diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7fd99cc..f3948b4 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -20,11 +20,6 @@ parameters: count: 1 path: src/EventListener/ORM/SortableListener.php - - - message: "#^Method Nucleos\\\\Doctrine\\\\EventListener\\\\ORM\\\\TablePrefixEventListener\\:\\:addSequenceGenerator\\(\\) has parameter \\$definition with no value type specified in iterable type array\\.$#" - count: 1 - path: src/EventListener/ORM/TablePrefixEventListener.php - - message: "#^Method Nucleos\\\\Doctrine\\\\EventListener\\\\ORM\\\\TablePrefixEventListener\\:\\:evaluteMapping\\(\\) has parameter \\$mapping with no value type specified in iterable type array\\.$#" count: 1 @@ -36,12 +31,12 @@ parameters: path: src/EventListener/ORM/TablePrefixEventListener.php - - message: "#^Parameter \\#1 \\$definition of method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\\\:\\:setSequenceGeneratorDefinition\\(\\) expects array\\{sequenceName\\?\\: string, allocationSize\\?\\: int\\|string, initialValue\\?\\: int\\|string, quoted\\?\\: mixed\\}, array\\{sequenceName\\: string, allocationSize\\: string, initialValue\\: string, quoted\\?\\: mixed\\}\\|array\\{sequenceName\\: string\\}\\|null given\\.$#" + message: "#^Parameter \\#1 \\$definition of method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata\\\\:\\:setSequenceGeneratorDefinition\\(\\) expects array\\{sequenceName\\?\\: string, allocationSize\\?\\: int\\|string, initialValue\\?\\: int\\|string, quoted\\?\\: mixed\\}, array\\{sequenceName\\: string, allocationSize\\: string, initialValue\\: string, quoted\\?\\: mixed\\}\\|array\\{sequenceName\\: string\\}\\|null given\\.$#" count: 1 path: src/EventListener/ORM/TablePrefixEventListener.php - - message: "#^Parameter \\#3 \\$definition of method Nucleos\\\\Doctrine\\\\EventListener\\\\ORM\\\\TablePrefixEventListener\\:\\:addSequenceGenerator\\(\\) expects array, array\\\\|null given\\.$#" + message: "#^Parameter \\#3 \\$definition of method Nucleos\\\\Doctrine\\\\EventListener\\\\ORM\\\\TablePrefixEventListener\\:\\:addSequenceGenerator\\(\\) expects array\\{allocationSize\\: int\\}, array\\{sequenceName\\: string, allocationSize\\: string, initialValue\\: string, quoted\\?\\: mixed\\}\\|array\\{sequenceName\\: string\\}\\|null given\\.$#" count: 1 path: src/EventListener/ORM/TablePrefixEventListener.php @@ -50,50 +45,45 @@ parameters: count: 1 path: src/EventListener/ORM/UniqueActiveListener.php - - - message: "#^Call to function method_exists\\(\\) with Doctrine\\\\DBAL\\\\Connection and 'createSchemaManager' will always evaluate to true\\.$#" - count: 1 - path: src/Migration/IdToUuidMigration.php - - message: "#^Property Nucleos\\\\Doctrine\\\\Migration\\\\IdToUuidMigration\\:\\:\\$schemaManager with generic class Doctrine\\\\DBAL\\\\Schema\\\\AbstractSchemaManager does not specify its types\\: T$#" count: 1 path: src/Migration/IdToUuidMigration.php - - message: "#^Method Nucleos\\\\Doctrine\\\\Tests\\\\Bridge\\\\Symfony\\\\App\\\\AppKernel\\:\\:configureContainer\\(\\) has parameter \\$container with no type specified\\.$#" - count: 1 - path: tests/Bridge/Symfony/App/AppKernel.php + message: "#^Call to method method\\(\\) on an unknown class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\.$#" + count: 4 + path: src/Test/ORM/EntityManagerMockFactory.php - - message: "#^Method Nucleos\\\\Doctrine\\\\Tests\\\\Bridge\\\\Symfony\\\\App\\\\AppKernel\\:\\:configureContainer\\(\\) has parameter \\$loader with no type specified\\.$#" + message: "#^Call to protected method createMock\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\.$#" count: 1 - path: tests/Bridge/Symfony/App/AppKernel.php + path: src/Test/ORM/EntityManagerMockFactory.php - - message: "#^Method Nucleos\\\\Doctrine\\\\Tests\\\\Bridge\\\\Symfony\\\\App\\\\AppKernel\\:\\:configureRoutes\\(\\) has parameter \\$routes with no type specified\\.$#" + message: "#^Class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo not found\\.$#" count: 1 - path: tests/Bridge/Symfony/App/AppKernel.php + path: src/Test/ORM/EntityManagerMockFactory.php - - message: "#^Call to method getResponse\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Client\\.$#" + message: "#^Trying to mock an undefined method getFieldNames\\(\\) on class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\.$#" count: 1 - path: tests/Bridge/Symfony/Bundle/BundleIntegrationTest.php + path: src/Test/ORM/EntityManagerMockFactory.php - - message: "#^Call to method request\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Client\\.$#" + message: "#^Trying to mock an undefined method getIdentifier\\(\\) on class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\.$#" count: 1 - path: tests/Bridge/Symfony/Bundle/BundleIntegrationTest.php + path: src/Test/ORM/EntityManagerMockFactory.php - - message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Client not found\\.$#" + message: "#^Trying to mock an undefined method getName\\(\\) on class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\.$#" count: 1 - path: tests/Bridge/Symfony/Bundle/BundleIntegrationTest.php + path: src/Test/ORM/EntityManagerMockFactory.php - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\TestCase\\:\\:createStub\\(\\)\\.$#" - count: 2 - path: tests/EventListener/ORM/LifecycleDateListenerTest.php + message: "#^Trying to mock an undefined method getTableName\\(\\) on class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\.$#" + count: 1 + path: src/Test/ORM/EntityManagerMockFactory.php - message: "#^Call to function assert\\(\\) with true will always evaluate to true\\.$#" @@ -125,8 +115,3 @@ parameters: count: 1 path: tests/Fixtures/DemoEntityManager.php - - - message: "#^Call to function method_exists\\(\\) with Doctrine\\\\DBAL\\\\Connection and 'createSchemaManager' will always evaluate to true\\.$#" - count: 1 - path: tests/Migration/IdToUuidMigrationTest.php - diff --git a/src/EventListener/ORM/TablePrefixEventListener.php b/src/EventListener/ORM/TablePrefixEventListener.php index b922575..56a9ed2 100644 --- a/src/EventListener/ORM/TablePrefixEventListener.php +++ b/src/EventListener/ORM/TablePrefixEventListener.php @@ -16,8 +16,8 @@ use Doctrine\ORM\Event\LoadClassMetadataEventArgs; use Doctrine\ORM\Events; use Doctrine\ORM\Id\SequenceGenerator; +use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Mapping\ClassMetadataInfo; final class TablePrefixEventListener implements EventSubscriber { @@ -102,12 +102,12 @@ private function isValidTable(ClassMetadata $classMetadata): bool private function prefixExists(string $name): bool { - return 0 === strpos($name, (string) $this->prefix); + return str_starts_with($name, (string) $this->prefix); } - private function evaluteMapping(ClassMetadata $classMetadata, array $mapping, string $fieldName): void + private function evaluteMapping(ClassMetadata $classMetadata, array|AssociationMapping $mapping, string $fieldName): void { - if (ClassMetadataInfo::MANY_TO_MANY !== $mapping['type']) { + if (ClassMetadata::MANY_TO_MANY !== $mapping['type']) { return; } @@ -120,6 +120,9 @@ private function evaluteMapping(ClassMetadata $classMetadata, array $mapping, st } } + /** + * @param array{allocationSize: int} $definition + */ private function addSequenceGenerator(ClassMetadata $classMetadata, EntityManagerInterface $em, array $definition): void { $sequenceGenerator = new SequenceGenerator( diff --git a/src/Migration/IdToUuidMigration.php b/src/Migration/IdToUuidMigration.php index aa71f5c..3c76658 100644 --- a/src/Migration/IdToUuidMigration.php +++ b/src/Migration/IdToUuidMigration.php @@ -13,7 +13,6 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Schema\AbstractSchemaManager; -use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Types; @@ -475,7 +474,6 @@ private function restoreConstraintsAndIndexes(): void */ private function hasCombinedPrimaryKey(array $foreignKey): bool { - /** @var Column $key */ foreach ($foreignKey['primaryKey'] as $key) { if ($key === $foreignKey['key']) { return true; diff --git a/src/Test/ORM/EntityManagerMockFactory.php b/src/Test/ORM/EntityManagerMockFactory.php index d843efc..31378cc 100644 --- a/src/Test/ORM/EntityManagerMockFactory.php +++ b/src/Test/ORM/EntityManagerMockFactory.php @@ -16,6 +16,7 @@ use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\QueryBuilder; use PHPUnit\Framework\MockObject\MockObject; @@ -74,6 +75,10 @@ private static function prepareQueryBuilder(TestCase $test, MockObject $qb): voi */ private static function prepareMetadata(TestCase $test, array $fields): MockObject { + if (class_exists(EntityManager::class)) { + return $test->createMock(ClassMetadata::class); + } + $metadata = $test->getMockBuilder(ClassMetadataInfo::class)->disableOriginalConstructor()->getMock(); $metadata->method('getFieldNames')->willReturn($fields); $metadata->method('getName')->willReturn('className');