Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate database driver to PHP 8 syntax #10496

Merged
merged 1 commit into from
Feb 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 17 additions & 47 deletions lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use function assert;
use function count;
use function current;
use function get_class;
use function in_array;
use function preg_replace;
use function sort;
Expand All @@ -52,64 +51,50 @@ class DatabaseDriver implements MappingDriver
*/
private const OBJECT = 'object';

/** @var AbstractSchemaManager */
private $sm;

/** @var array<string,Table>|null */
private $tables = null;
private array|null $tables = null;

/** @var array<class-string, string> */
private $classToTableNames = [];
private array $classToTableNames = [];

/** @psalm-var array<string, Table> */
private $manyToManyTables = [];
private array $manyToManyTables = [];

/** @var mixed[] */
private $classNamesForTables = [];
private array $classNamesForTables = [];

/** @var mixed[] */
private $fieldNamesForColumns = [];
private array $fieldNamesForColumns = [];

/**
* The namespace for the generated entities.
*
* @var string|null
*/
private $namespace;
private string|null $namespace = null;

/** @var Inflector */
private $inflector;
private Inflector $inflector;

public function __construct(AbstractSchemaManager $schemaManager)
public function __construct(private readonly AbstractSchemaManager $sm)
{
$this->sm = $schemaManager;
$this->inflector = InflectorFactory::create()->build();
}

/**
* Set the namespace for the generated entities.
*
* @param string $namespace
*
* @return void
*/
public function setNamespace($namespace)
public function setNamespace(string $namespace): void
{
$this->namespace = $namespace;
}

/**
* {@inheritDoc}
*/
public function isTransient($className)
public function isTransient(string $className): bool
{
return true;
}

/**
* {@inheritDoc}
*/
public function getAllClassNames()
public function getAllClassNames(): array
{
$this->reverseEngineerMappingFromDatabase();

Expand All @@ -118,27 +103,16 @@ public function getAllClassNames()

/**
* Sets class name for a table.
*
* @param string $tableName
* @param string $className
*
* @return void
*/
public function setClassNameForTable($tableName, $className)
public function setClassNameForTable(string $tableName, string $className): void
{
$this->classNamesForTables[$tableName] = $className;
}

/**
* Sets field name for a column on a specific table.
*
* @param string $tableName
* @param string $columnName
* @param string $fieldName
*
* @return void
*/
public function setFieldNameForColumn($tableName, $columnName, $fieldName)
public function setFieldNameForColumn(string $tableName, string $columnName, string $fieldName): void
{
$this->fieldNamesForColumns[$tableName][$columnName] = $fieldName;
}
Expand All @@ -150,10 +124,8 @@ public function setFieldNameForColumn($tableName, $columnName, $fieldName)
* @param Table[] $manyToManyTables
* @psalm-param list<Table> $entityTables
* @psalm-param list<Table> $manyToManyTables
*
* @return void
*/
public function setTables($entityTables, $manyToManyTables)
public function setTables(array $entityTables, array $manyToManyTables): void
{
$this->tables = $this->manyToManyTables = $this->classToTableNames = [];

Expand Down Expand Up @@ -182,14 +154,14 @@ public function setInflector(Inflector $inflector): void
*
* @template T of object
*/
public function loadMetadataForClass($className, PersistenceClassMetadata $metadata)
public function loadMetadataForClass(string $className, PersistenceClassMetadata $metadata): void
{
if (! $metadata instanceof ClassMetadata) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/249',
'Passing an instance of %s to %s is deprecated, please pass a ClassMetadata instance instead.',
get_class($metadata),
$metadata::class,
__METHOD__,
ClassMetadata::class,
);
Expand Down Expand Up @@ -457,10 +429,8 @@ private function buildFieldMapping(string $tableName, Column $column): array

/**
* Build to one (one to one, many to one) association mapping from class metadata.
*
* @return void
*/
private function buildToOneAssociationMappings(ClassMetadata $metadata)
private function buildToOneAssociationMappings(ClassMetadata $metadata): void
{
assert($this->tables !== null);

Expand Down