Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ on:
jobs:
coding-standards:
name: "Coding Standards"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@2.1.0"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@3.0.0"
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,7 @@
use Doctrine\DBAL\Connection;
use InvalidArgumentException;

use function get_class;
use function get_debug_type;
use function sprintf;

final class InvalidConfiguration extends InvalidArgumentException implements LoaderException
Expand All @@ -19,6 +19,10 @@ 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,
get_debug_type($connection),
));
}
}
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,7 @@
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;

use function get_class;
use function get_debug_type;
use function sprintf;

final class InvalidConfiguration extends InvalidArgumentException implements LoaderException
Expand All @@ -19,6 +19,10 @@ 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,
get_debug_type($em),
));
}
}
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,24 @@
use Doctrine\Migrations\Configuration\EntityManager\EntityManagerLoader;
use InvalidArgumentException;

use function get_class;
use function get_debug_type;
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',
get_debug_type($loader),
));
}

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',
get_debug_type($loader),
));
}
}
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
Loading