Skip to content

Commit

Permalink
Modernize codebase for PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Aug 18, 2023
1 parent 832ef28 commit fb00e23
Show file tree
Hide file tree
Showing 90 changed files with 276 additions and 662 deletions.
9 changes: 3 additions & 6 deletions lib/Doctrine/Migrations/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ abstract class AbstractMigration
/** @var AbstractPlatform */
protected $platform;

private LoggerInterface $logger;

/** @var Query[] */
private array $plannedSql = [];

public function __construct(Connection $connection, LoggerInterface $logger)
public function __construct(Connection $connection, private readonly LoggerInterface $logger)
{
$this->connection = $connection;
$this->sm = $this->connection->createSchemaManager();
$this->platform = $this->connection->getDatabasePlatform();
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -126,7 +123,7 @@ public function down(Schema $schema): void
protected function addSql(
string $sql,
array $params = [],
array $types = []
array $types = [],
): void {
$this->plannedSql[] = new Query($sql, $params, $types);
}
Expand All @@ -143,7 +140,7 @@ protected function write(string $message): void
}

/** @throws IrreversibleMigration */
protected function throwIrreversibleMigrationException(?string $message = null): void
protected function throwIrreversibleMigrationException(string|null $message = null): void
{
if ($message === null) {
$message = 'This migration is irreversible and cannot be reverted.';
Expand Down
45 changes: 19 additions & 26 deletions lib/Doctrine/Migrations/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ final class Configuration

private bool $migrationsAreOrganizedByYearAndMonth = false;

private ?string $customTemplate = null;
private string|null $customTemplate = null;

private bool $isDryRun = false;

private bool $allOrNothing = false;

private bool $transactional = true;

private ?string $connectionName = null;
private string|null $connectionName = null;

private ?string $entityManagerName = null;
private string|null $entityManagerName = null;

private bool $checkDbPlatform = true;

private ?MetadataStorageConfiguration $metadataStorageConfiguration = null;
private MetadataStorageConfiguration|null $metadataStorageConfiguration = null;

private bool $frozen = false;

Expand Down Expand Up @@ -78,7 +78,7 @@ public function addMigrationClass(string $className): void
$this->migrationClasses[] = $className;
}

public function getMetadataStorageConfiguration(): ?MetadataStorageConfiguration
public function getMetadataStorageConfiguration(): MetadataStorageConfiguration|null
{
return $this->metadataStorageConfiguration;
}
Expand All @@ -95,35 +95,35 @@ public function getMigrationDirectories(): array
return $this->migrationsDirectories;
}

public function getConnectionName(): ?string
public function getConnectionName(): string|null
{
return $this->connectionName;
}

public function setConnectionName(?string $connectionName): void
public function setConnectionName(string|null $connectionName): void
{
$this->assertNotFrozen();
$this->connectionName = $connectionName;
}

public function getEntityManagerName(): ?string
public function getEntityManagerName(): string|null
{
return $this->entityManagerName;
}

public function setEntityManagerName(?string $entityManagerName): void
public function setEntityManagerName(string|null $entityManagerName): void
{
$this->assertNotFrozen();
$this->entityManagerName = $entityManagerName;
}

public function setCustomTemplate(?string $customTemplate): void
public function setCustomTemplate(string|null $customTemplate): void
{
$this->assertNotFrozen();
$this->customTemplate = $customTemplate;
}

public function getCustomTemplate(): ?string
public function getCustomTemplate(): string|null
{
return $this->customTemplate;
}
Expand All @@ -135,15 +135,15 @@ public function areMigrationsOrganizedByYear(): bool

/** @throws MigrationException */
public function setMigrationsAreOrganizedByYear(
bool $migrationsAreOrganizedByYear = true
bool $migrationsAreOrganizedByYear = true,
): void {
$this->assertNotFrozen();
$this->migrationsAreOrganizedByYear = $migrationsAreOrganizedByYear;
}

/** @throws MigrationException */
public function setMigrationsAreOrganizedByYearAndMonth(
bool $migrationsAreOrganizedByYearAndMonth = true
bool $migrationsAreOrganizedByYearAndMonth = true,
): void {
$this->assertNotFrozen();
$this->migrationsAreOrganizedByYear = $migrationsAreOrganizedByYearAndMonth;
Expand Down Expand Up @@ -202,18 +202,11 @@ public function setMigrationOrganization(string $migrationOrganization): void
{
$this->assertNotFrozen();

switch (strtolower($migrationOrganization)) {
case self::VERSIONS_ORGANIZATION_NONE:
$this->setMigrationsAreOrganizedByYearAndMonth(false);
break;
case self::VERSIONS_ORGANIZATION_BY_YEAR:
$this->setMigrationsAreOrganizedByYear();
break;
case self::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH:
$this->setMigrationsAreOrganizedByYearAndMonth();
break;
default:
throw UnknownConfigurationValue::new('organize_migrations', $migrationOrganization);
}
match (strtolower($migrationOrganization)) {
self::VERSIONS_ORGANIZATION_NONE => $this->setMigrationsAreOrganizedByYearAndMonth(false),
self::VERSIONS_ORGANIZATION_BY_YEAR => $this->setMigrationsAreOrganizedByYear(),
self::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH => $this->setMigrationsAreOrganizedByYearAndMonth(),
default => throw UnknownConfigurationValue::new('organize_migrations', $migrationOrganization),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
*/
final class ConfigurationFile implements ConnectionLoader
{
private string $filename;

public function __construct(string $filename)
public function __construct(private readonly string $filename)
{
$this->filename = $filename;
}

public function getConnection(?string $name = null): Connection
public function getConnection(string|null $name = null): Connection
{
if ($name !== null) {
throw new InvalidArgumentException('Only one connection is supported');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ interface ConnectionLoader
*
* @throws ConnectionNotSpecified
*/
public function getConnection(?string $name = null): Connection;
public function getConnection(string|null $name = null): Connection;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ final class ConnectionRegistryConnection implements ConnectionLoader
{
private ConnectionRegistry $registry;

private ?string $defaultConnectionName = null;
private string|null $defaultConnectionName = null;

public static function withSimpleDefault(ConnectionRegistry $registry, ?string $connectionName = null): self
public static function withSimpleDefault(ConnectionRegistry $registry, string|null $connectionName = null): self
{
$that = new self();
$that->registry = $registry;
Expand All @@ -27,7 +27,7 @@ private function __construct()
{
}

public function getConnection(?string $name = null): Connection
public function getConnection(string|null $name = null): Connection
{
$connection = $this->registry->getConnection($name ?? $this->defaultConnectionName);
if (! $connection instanceof Connection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\DBAL\Connection;
use InvalidArgumentException;

use function get_class;
use function sprintf;

final class InvalidConfiguration extends InvalidArgumentException implements LoaderException
Expand All @@ -19,6 +18,6 @@ public static function invalidArrayConfiguration(): self

public static function invalidConnectionType(object $connection): self
{
return new self(sprintf('The returned connection must be a %s instance, %s returned.', Connection::class, get_class($connection)));
return new self(sprintf('The returned connection must be a %s instance, %s returned.', Connection::class, $connection::class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@

final class ExistingConnection implements ConnectionLoader
{
private Connection $connection;

public function __construct(Connection $connection)
public function __construct(private readonly Connection $connection)
{
$this->connection = $connection;
}

public function getConnection(?string $name = null): Connection
public function getConnection(string|null $name = null): Connection
{
if ($name !== null) {
throw InvalidLoader::noMultipleConnections($this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
*/
final class ConfigurationFile implements EntityManagerLoader
{
private string $filename;

public function __construct(string $filename)
public function __construct(private readonly string $filename)
{
$this->filename = $filename;
}

/**
Expand All @@ -29,7 +26,7 @@ public function __construct(string $filename)
*
* @throws InvalidConfiguration
*/
public function getEntityManager(?string $name = null): EntityManagerInterface
public function getEntityManager(string|null $name = null): EntityManagerInterface
{
if ($name !== null) {
throw new InvalidArgumentException('Only one connection is supported');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
*/
interface EntityManagerLoader
{
public function getEntityManager(?string $name = null): EntityManagerInterface;
public function getEntityManager(string|null $name = null): EntityManagerInterface;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;

use function get_class;
use function sprintf;

final class InvalidConfiguration extends InvalidArgumentException implements LoaderException
Expand All @@ -19,6 +18,6 @@ public static function invalidArrayConfiguration(): self

public static function invalidManagerType(object $em): self
{
return new self(sprintf('The returned manager must implement %s, %s returned.', EntityManagerInterface::class, get_class($em)));
return new self(sprintf('The returned manager must implement %s, %s returned.', EntityManagerInterface::class, $em::class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@

final class ExistingEntityManager implements EntityManagerLoader
{
private EntityManagerInterface $entityManager;

public function __construct(EntityManagerInterface $entityManager)
public function __construct(private readonly EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}

public function getEntityManager(?string $name = null): EntityManagerInterface
public function getEntityManager(string|null $name = null): EntityManagerInterface
{
if ($name !== null) {
throw InvalidLoader::noMultipleEntityManagers($this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ final class ManagerRegistryEntityManager implements EntityManagerLoader
{
private ManagerRegistry $registry;

private ?string $defaultManagerName = null;
private string|null $defaultManagerName = null;

public static function withSimpleDefault(ManagerRegistry $registry, ?string $managerName = null): self
public static function withSimpleDefault(ManagerRegistry $registry, string|null $managerName = null): self
{
$that = new self();
$that->registry = $registry;
Expand All @@ -27,7 +27,7 @@ private function __construct()
{
}

public function getEntityManager(?string $name = null): EntityManagerInterface
public function getEntityManager(string|null $name = null): EntityManagerInterface
{
$managerName = $name ?? $this->defaultManagerName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
use Doctrine\Migrations\Configuration\EntityManager\EntityManagerLoader;
use InvalidArgumentException;

use function get_class;
use function sprintf;

final class InvalidLoader extends InvalidArgumentException implements ConfigurationException
{
public static function noMultipleConnections(ConnectionLoader $loader): self
{
return new self(sprintf('Only one connection is supported by %s', get_class($loader)));
return new self(sprintf('Only one connection is supported by %s', $loader::class));
}

public static function noMultipleEntityManagers(EntityManagerLoader $loader): self
{
return new self(sprintf('Only one entity manager is supported by %s', get_class($loader)));
return new self(sprintf('Only one entity manager is supported by %s', $loader::class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

final class UnknownConfigurationValue extends LogicException implements ConfigurationException
{
/** @param mixed $value */
public static function new(string $key, $value): self
public static function new(string $key, mixed $value): self
{
return new self(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@

final class ConfigurationArray implements ConfigurationLoader
{
/** @var array<string,mixed> */
private array $configurations;

/** @param array<string,mixed> $configurations */
public function __construct(array $configurations)
public function __construct(private readonly array $configurations)
{
$this->configurations = $configurations;
}

public function getConfiguration(): Configuration
Expand Down Expand Up @@ -78,11 +74,10 @@ public function getConfiguration(): Configuration
}

/**
* @param mixed[] $configMap
* @param Configuration|TableMetadataStorageConfiguration $object
* @param array<string|int,mixed> $data
* @param mixed[] $configMap
* @param array<string|int,mixed> $data
*/
private static function applyConfigs(array $configMap, $object, array $data): void
private static function applyConfigs(array $configMap, Configuration|TableMetadataStorageConfiguration $object, array $data): void
{
foreach ($data as $configurationKey => $configurationValue) {
if (! isset($configMap[$configurationKey])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
*/
final class ConfigurationFileWithFallback implements ConfigurationLoader
{
private ?string $file = null;

public function __construct(?string $file = null)
public function __construct(private readonly string|null $file = null)
{
$this->file = $file;
}

public function getConfiguration(): Configuration
Expand Down
Loading

0 comments on commit fb00e23

Please sign in to comment.