From a08bc3b4d8567cdff05e89b272ba1e06e9d71c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Mon, 5 Apr 2021 16:21:02 +0200 Subject: [PATCH] SA: Bump Psalm to level 4 --- ConnectionFactory.php | 4 ++-- DataCollector/DoctrineDataCollector.php | 2 +- DependencyInjection/Configuration.php | 2 +- DependencyInjection/DoctrineExtension.php | 10 +--------- Mapping/ClassMetadataFactory.php | 11 ++++++++++- Mapping/MappingDriver.php | 4 ++-- Tests/ConnectionFactoryTest.php | 7 ++++--- .../AbstractDoctrineExtensionTest.php | 5 ----- Tests/DependencyInjection/DoctrineExtensionTest.php | 2 -- Tests/DependencyInjection/Fixtures/DbalTestKernel.php | 2 +- Tests/DependencyInjection/Fixtures/TestKernel.php | 2 +- Tests/ProfilerTest.php | 1 + psalm.xml.dist | 2 +- 13 files changed, 25 insertions(+), 29 deletions(-) diff --git a/ConnectionFactory.php b/ConnectionFactory.php index b210b9424..715fc8fe0 100644 --- a/ConnectionFactory.php +++ b/ConnectionFactory.php @@ -41,8 +41,8 @@ public function __construct(array $typesConfig) /** * Create a connection by name. * - * @param mixed[] $params - * @param string[]|Type[] $mappingTypes + * @param mixed[] $params + * @param array $mappingTypes * * @return Connection * diff --git a/DataCollector/DoctrineDataCollector.php b/DataCollector/DoctrineDataCollector.php index 3f6e0ae9e..122096580 100644 --- a/DataCollector/DoctrineDataCollector.php +++ b/DataCollector/DoctrineDataCollector.php @@ -309,7 +309,7 @@ public function getGroupedQueries() private function executionTimePercentage(int $executionTimeMS, int $totalExecutionTimeMS): float { - if ($totalExecutionTimeMS === 0.0 || $totalExecutionTimeMS === 0) { + if (! $totalExecutionTimeMS) { return 0; } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 67eed7a5d..1ecc807b3 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -47,7 +47,7 @@ class Configuration implements ConfigurationInterface */ public function __construct(bool $debug) { - $this->debug = (bool) $debug; + $this->debug = $debug; } public function getConfigTreeBuilder(): TreeBuilder diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index 361873058..3716e488c 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -268,13 +268,9 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder } /** - * @param mixed[] $connection + * @param array $connection * * @return mixed[] - * - * @psalm-return T - * @psalm-param T - * @template T of array */ protected function getConnectionOptions(array $connection): array { @@ -656,10 +652,6 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $ return; } - if (! isset($listenerDef)) { - throw new InvalidArgumentException('Entity listeners configuration requires doctrine-orm 2.5.0 or newer'); - } - $entities = $entityManager['entity_listeners']['entities']; foreach ($entities as $entityListenerClass => $entity) { diff --git a/Mapping/ClassMetadataFactory.php b/Mapping/ClassMetadataFactory.php index 3890b5231..c84cfd2d7 100644 --- a/Mapping/ClassMetadataFactory.php +++ b/Mapping/ClassMetadataFactory.php @@ -2,10 +2,13 @@ namespace Doctrine\Bundle\DoctrineBundle\Mapping; +use Doctrine\ORM\Id\AbstractIdGenerator; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory as BaseClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use function assert; + class ClassMetadataFactory extends BaseClassMetadataFactory { /** @@ -15,12 +18,18 @@ protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonS { parent::doLoadMetadata($class, $parent, $rootEntityFound, $nonSuperclassParents); + if (! $class instanceof ClassMetadataInfo) { + return; + } + $customGeneratorDefinition = $class->customGeneratorDefinition; - if (! isset($customGeneratorDefinition['instance']) || ! $class instanceof ClassMetadataInfo) { + if (! isset($customGeneratorDefinition['instance'])) { return; } + assert($customGeneratorDefinition['instance'] instanceof AbstractIdGenerator); + $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); $class->setIdGenerator($customGeneratorDefinition['instance']); unset($customGeneratorDefinition['instance']); diff --git a/Mapping/MappingDriver.php b/Mapping/MappingDriver.php index a51eacf73..136a672fa 100644 --- a/Mapping/MappingDriver.php +++ b/Mapping/MappingDriver.php @@ -45,10 +45,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata): void $this->driver->loadMetadataForClass($className, $metadata); if ( - $metadata->generatorType !== ClassMetadataInfo::GENERATOR_TYPE_CUSTOM + ! $metadata instanceof ClassMetadataInfo + || $metadata->generatorType !== ClassMetadataInfo::GENERATOR_TYPE_CUSTOM || ! isset($metadata->customGeneratorDefinition['class']) || ! $this->idGeneratorLocator->has($metadata->customGeneratorDefinition['class']) - || ! $metadata instanceof ClassMetadataInfo ) { return; } diff --git a/Tests/ConnectionFactoryTest.php b/Tests/ConnectionFactoryTest.php index 4beb3ac21..6445a2abd 100644 --- a/Tests/ConnectionFactoryTest.php +++ b/Tests/ConnectionFactoryTest.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Exception; use Throwable; @@ -27,7 +28,7 @@ public function testContainer(): void $params = ['driverClass' => FakeDriver::class]; $config = null; $eventManager = null; - $mappingTypes = [0]; + $mappingTypes = ['' => '']; $exception = class_exists(Driver\AbstractDriverException::class) ? new DriverException('', $this->createMock(Driver\AbstractDriverException::class)) : new DriverException('', $this->createMock(Driver\AbstractException::class)); @@ -140,12 +141,12 @@ public function getDatabasePlatform(): AbstractPlatform * @param string|null $password * @param mixed[] $driverOptions */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []): void + public function connect(array $params, $username = null, $password = null, array $driverOptions = []): Connection { throw new Exception('not implemented'); } - public function getSchemaManager(Connection $conn, ?AbstractPlatform $platform = null): void + public function getSchemaManager(Connection $conn, ?AbstractPlatform $platform = null): AbstractSchemaManager { throw new Exception('not implemented'); } diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 906ab2f7f..e211aa4a4 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -10,7 +10,6 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connections\MasterSlaveConnection; use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection; -use Doctrine\DBAL\Schema\AbstractAsset; use Doctrine\ORM\EntityManagerInterface; use Generator; use InvalidArgumentException; @@ -1447,10 +1446,6 @@ public function __construct(string $tableToIgnore) public function __invoke(string $assetName): bool { - if ($assetName instanceof AbstractAsset) { - $assetName = $assetName->getName(); - } - return $assetName !== $this->tableToIgnore; } } diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index 42e18da40..ab6b527c1 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -1038,8 +1038,6 @@ public function testShardManager(): void */ private function getContainer(array $bundles = ['YamlBundle'], string $vendor = ''): ContainerBuilder { - $bundles = (array) $bundles; - $map = []; foreach ($bundles as $bundle) { require_once __DIR__ . '/Fixtures/Bundles/' . ($vendor ? $vendor . '/' : '') . $bundle . '/' . $bundle . '.php'; diff --git a/Tests/DependencyInjection/Fixtures/DbalTestKernel.php b/Tests/DependencyInjection/Fixtures/DbalTestKernel.php index d03194ef7..cdbc027cf 100644 --- a/Tests/DependencyInjection/Fixtures/DbalTestKernel.php +++ b/Tests/DependencyInjection/Fixtures/DbalTestKernel.php @@ -64,7 +64,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void public function getProjectDir(): string { if ($this->projectDir === null) { - $this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5(mt_rand()); + $this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5((string) mt_rand()); } return $this->projectDir; diff --git a/Tests/DependencyInjection/Fixtures/TestKernel.php b/Tests/DependencyInjection/Fixtures/TestKernel.php index b181f9ce9..581212188 100644 --- a/Tests/DependencyInjection/Fixtures/TestKernel.php +++ b/Tests/DependencyInjection/Fixtures/TestKernel.php @@ -62,7 +62,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void public function getProjectDir(): string { if ($this->projectDir === null) { - $this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5(mt_rand()); + $this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5((string) mt_rand()); } return $this->projectDir; diff --git a/Tests/ProfilerTest.php b/Tests/ProfilerTest.php index e3670d883..67410584a 100644 --- a/Tests/ProfilerTest.php +++ b/Tests/ProfilerTest.php @@ -62,6 +62,7 @@ public function setUp(): void $this->twig->addExtension(new CodeExtension('', '', '')); $this->twig->addExtension(new RoutingExtension($urlGenerator)); $this->twig->addExtension(new HttpKernelExtension()); + /** @psalm-suppress InternalClass */ $this->twig->addExtension(new WebProfilerExtension()); $this->twig->addExtension(new DoctrineExtension()); diff --git a/psalm.xml.dist b/psalm.xml.dist index f182ddfc2..8d686af10 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -1,6 +1,6 @@