diff --git a/composer.json b/composer.json index 6a8dfef4b..da85fa3a4 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "require": { "php": "^8.1", "composer-runtime-api": "^2", - "doctrine/dbal": "^3.5.1 || ^4", + "doctrine/dbal": "^3.6 || ^4", "doctrine/deprecations": "^0.5.3 || ^1", "doctrine/event-manager": "^1.2 || ^2.0", "psr/log": "^1.1.3 || ^2 || ^3", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9da956f32..957f21f1c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 7 + level: 8 paths: - src - tests diff --git a/src/DependencyFactory.php b/src/DependencyFactory.php index f415b5729..e30ebb891 100644 --- a/src/DependencyFactory.php +++ b/src/DependencyFactory.php @@ -145,7 +145,7 @@ public function getConfiguration(): Configuration { if ($this->configuration === null) { $this->configuration = $this->configurationLoader->getConfiguration(); - $this->freeze(); + $this->frozen = true; } return $this->configuration; @@ -157,7 +157,7 @@ public function getConnection(): Connection $this->connection = $this->hasEntityManager() ? $this->getEntityManager()->getConnection() : $this->connectionLoader->getConnection($this->getConfiguration()->getConnectionName()); - $this->freeze(); + $this->frozen = true; } return $this->connection; @@ -171,7 +171,7 @@ public function getEntityManager(): EntityManagerInterface } $this->em = $this->emLoader->getEntityManager($this->getConfiguration()->getEntityManagerName()); - $this->freeze(); + $this->frozen = true; } return $this->em; @@ -222,7 +222,7 @@ public function getSchemaDumper(): SchemaDumper private function getEmptySchemaProvider(): SchemaProvider { - return $this->getDependency(EmptySchemaProvider::class, fn (): SchemaProvider => new EmptySchemaProvider($this->connection->createSchemaManager())); + return $this->getDependency(EmptySchemaProvider::class, fn (): SchemaProvider => new EmptySchemaProvider($this->getConnection()->createSchemaManager())); } public function hasSchemaProvider(): bool diff --git a/src/InlineParameterFormatter.php b/src/InlineParameterFormatter.php index 9aa6fc782..741a5ca3d 100644 --- a/src/InlineParameterFormatter.php +++ b/src/InlineParameterFormatter.php @@ -53,7 +53,7 @@ public function formatParameters(array $params, array $types): string return sprintf('with parameters (%s)', implode(', ', $formattedParameters)); } - private function formatParameter(mixed $value, string|int $type): string|int|bool|float|null + private function formatParameter(mixed $value, mixed $type): string|int|bool|float|null { if (is_string($type) && Type::hasType($type)) { return Type::getType($type)->convertToDatabaseValue( diff --git a/src/Tools/Console/Command/DiffCommand.php b/src/Tools/Console/Command/DiffCommand.php index b65b13269..4159fec13 100644 --- a/src/Tools/Console/Command/DiffCommand.php +++ b/src/Tools/Console/Command/DiffCommand.php @@ -135,7 +135,7 @@ protected function execute( $executedUnavailableMigrations = $statusCalculator->getExecutedUnavailableMigrations(); $newMigrations = $statusCalculator->getNewMigrations(); - if (! $this->checkNewMigrationsOrExecutedUnavailable($newMigrations, $executedUnavailableMigrations, $input, $output)) { + if (! $this->checkNewMigrationsOrExecutedUnavailable($newMigrations, $executedUnavailableMigrations, $input)) { $this->io->error('Migration cancelled!'); return 3; @@ -186,7 +186,6 @@ private function checkNewMigrationsOrExecutedUnavailable( AvailableMigrationsList $newMigrations, ExecutedMigrationsList $executedUnavailableMigrations, InputInterface $input, - OutputInterface $output, ): bool { if (count($newMigrations) === 0 && count($executedUnavailableMigrations) === 0) { return true; diff --git a/src/Tools/Console/Command/DoctrineCommand.php b/src/Tools/Console/Command/DoctrineCommand.php index d7b54a5b4..01f90b140 100644 --- a/src/Tools/Console/Command/DoctrineCommand.php +++ b/src/Tools/Console/Command/DoctrineCommand.php @@ -88,16 +88,17 @@ protected function initialize(InputInterface $input, OutputInterface $output): v $configurationLoader = new ConfigurationFileWithFallback($configurationParameter); $this->dependencyFactory->setConfigurationLoader($configurationLoader); } + $dependencyFactory = $this->dependencyFactory; $this->setNamedEmOrConnection($input); - if ($this->dependencyFactory->isFrozen()) { + if ($dependencyFactory->isFrozen()) { return; } $logger = new ConsoleLogger($output); - $this->dependencyFactory->setService(LoggerInterface::class, $logger); - $this->dependencyFactory->freeze(); + $dependencyFactory->setService(LoggerInterface::class, $logger); + $dependencyFactory->freeze(); } protected function getDependencyFactory(): DependencyFactory @@ -116,6 +117,7 @@ protected function canExecute(string $question, InputInterface $input): bool private function setNamedEmOrConnection(InputInterface $input): void { + assert($this->dependencyFactory !== null); $emName = $input->getOption('em'); $connName = $input->getOption('conn'); if ($emName !== null && $connName !== null) { diff --git a/src/Tools/Console/Command/VersionCommand.php b/src/Tools/Console/Command/VersionCommand.php index e5bc67268..edf946588 100644 --- a/src/Tools/Console/Command/VersionCommand.php +++ b/src/Tools/Console/Command/VersionCommand.php @@ -113,19 +113,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int $confirmation = $this->io->confirm($question); if ($confirmation) { - $this->markVersions($input, $output); + $this->markVersions($input); } else { $this->io->error('Migration cancelled!'); } } else { - $this->markVersions($input, $output); + $this->markVersions($input); } return 0; } /** @throws InvalidOptionUsage */ - private function markVersions(InputInterface $input, OutputInterface $output): void + private function markVersions(InputInterface $input): void { $affectedVersion = $input->getArgument('version'); $allOption = $input->getOption('all'); @@ -149,15 +149,15 @@ private function markVersions(InputInterface $input, OutputInterface $output): v if ($allOption === true) { if ($input->getOption('delete') === true) { foreach ($executedMigrations->getItems() as $availableMigration) { - $this->mark($input, $output, $availableMigration->getVersion(), false, $executedMigrations); + $this->mark($input, $availableMigration->getVersion(), false, $executedMigrations); } } foreach ($availableVersions->getItems() as $availableMigration) { - $this->mark($input, $output, $availableMigration->getVersion(), true, $executedMigrations); + $this->mark($input, $availableMigration->getVersion(), true, $executedMigrations); } } elseif ($affectedVersion !== null) { - $this->mark($input, $output, new Version($affectedVersion), false, $executedMigrations); + $this->mark($input, new Version($affectedVersion), false, $executedMigrations); } elseif ($rangeFromOption !== null && $rangeToOption !== null) { $migrate = false; foreach ($availableVersions->getItems() as $availableMigration) { @@ -166,7 +166,7 @@ private function markVersions(InputInterface $input, OutputInterface $output): v } if ($migrate) { - $this->mark($input, $output, $availableMigration->getVersion(), true, $executedMigrations); + $this->mark($input, $availableMigration->getVersion(), true, $executedMigrations); } if ((string) $availableMigration->getVersion() === $rangeToOption) { @@ -183,7 +183,7 @@ private function markVersions(InputInterface $input, OutputInterface $output): v * @throws VersionDoesNotExist * @throws UnknownMigrationVersion */ - private function mark(InputInterface $input, OutputInterface $output, Version $version, bool $all, ExecutedMigrationsList $executedMigrations): void + private function mark(InputInterface $input, Version $version, bool $all, ExecutedMigrationsList $executedMigrations): void { try { $availableMigration = $this->getDependencyFactory()->getMigrationRepository()->getMigration($version); diff --git a/tests/InlineParameterFormatterTest.php b/tests/InlineParameterFormatterTest.php index 07a45d565..02a4ccc64 100644 --- a/tests/InlineParameterFormatterTest.php +++ b/tests/InlineParameterFormatterTest.php @@ -4,7 +4,9 @@ namespace Doctrine\Migrations\Tests; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Types; use Doctrine\Migrations\InlineParameterFormatter; @@ -12,10 +14,6 @@ class InlineParameterFormatterTest extends TestCase { - private Connection $connection; - - private AbstractPlatform $platform; - private InlineParameterFormatter $parameterFormatter; public function testFormatParameters(): void @@ -35,6 +33,8 @@ public function testFormatParameters(): void 11 => true, 12 => false, 13 => [1, true, false, 'string value'], + 14 => 'string value', + 15 => [1, 2, 3], 'named' => 'string value', ]; @@ -54,25 +54,25 @@ public function testFormatParameters(): void 'unknown', 'unknown', 'unknown', + ParameterType::STRING, + ArrayParameterType::INTEGER, ]; $result = $this->parameterFormatter->formatParameters($params, $types); - $expected = 'with parameters ([string value], [1], [], [1], [1.5], [1,1,,string value], [], [], [string value], [1], [1.5], [true], [false], [1, true, false, string value], :named => [string value])'; + $expected = 'with parameters ([string value], [1], [], [1], [1.5], [1,1,,string value], [], [], [string value], [1], [1.5], [true], [false], [1, true, false, string value], [string value], [1, 2, 3], :named => [string value])'; self::assertSame($expected, $result); } protected function setUp(): void { - $this->connection = $this->createMock(Connection::class); - - $this->platform = $this->createMock(AbstractPlatform::class); + $connection = $this->createMock(Connection::class); - $this->connection->expects(self::any()) + $connection->expects(self::any()) ->method('getDatabasePlatform') - ->willReturn($this->platform); + ->willReturn(self::createStub(AbstractPlatform::class)); - $this->parameterFormatter = new InlineParameterFormatter($this->connection); + $this->parameterFormatter = new InlineParameterFormatter($connection); } }