From 4dead9cbb15d98bc026cedfcad4dd1db2612cbc6 Mon Sep 17 00:00:00 2001 From: Dennis Riehle Date: Sun, 29 Dec 2024 18:27:19 +0100 Subject: [PATCH] upgraded from PHPStan 1.12 to 2.0 --- composer.json | 4 ++-- phpstan.neon | 5 +++-- src/Options/Configuration.php | 22 +++++++++---------- tests/Assets/CustomRepositoryFactory.php | 14 +++++++----- tests/Doctrine/ConfigurationFactoryTest.php | 4 ---- .../Doctrine/CustomDefaultRepositoryTest.php | 3 --- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index b892a47..96839b7 100644 --- a/composer.json +++ b/composer.json @@ -63,12 +63,12 @@ "require-dev": { "doctrine/coding-standard": "^12.0.0", "doctrine/persistence": "^2.5.7 || ^3.4.0", - "jangregor/phpstan-prophecy": "^1.0.2", + "jangregor/phpstan-prophecy": "^2.0.0", "laminas/laminas-developer-tools": "^2.9.0", "laminas/laminas-hydrator": "^4.16.0", "laminas/laminas-session": "^2.22.1", "phpspec/prophecy-phpunit": "^2.3.0", - "phpstan/phpstan": "^1.12.13", + "phpstan/phpstan": "^2.0.4", "phpunit/phpunit": "^10.5.40" }, "suggest": { diff --git a/phpstan.neon b/phpstan.neon index 3436e08..1b54adf 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,11 +1,12 @@ parameters: level: 6 - checkGenericClassInNonGenericObjectType: false paths: - src - tests ignoreErrors: - - '#Method class@anonymous/tests/Assets/CustomRepositoryFactory.*has parameter.*with no type specified#' + - + identifier: missingType.generics - '#defaultDocumentRepositoryClassName with type .* is not subtype of native type string#' + - '#Method .*Configuration::getDefaultDocumentRepositoryClassName\(\) never returns null#' includes: - vendor/jangregor/phpstan-prophecy/extension.neon diff --git a/src/Options/Configuration.php b/src/Options/Configuration.php index 1740a23..e5db079 100644 --- a/src/Options/Configuration.php +++ b/src/Options/Configuration.php @@ -27,7 +27,7 @@ final class Configuration extends AbstractOptions /** * Automatic generation of proxies (disable for production!) * - * @psalm-var MongoDbConfiguration::AUTOGENERATE_* + * @phpstan-var MongoDbConfiguration::AUTOGENERATE_* */ protected int $generateProxies = MongoDbConfiguration::AUTOGENERATE_EVAL; @@ -44,7 +44,7 @@ final class Configuration extends AbstractOptions /** * Automatic generation of hydrators (disable for production!) * - * @psalm-var MongoDbConfiguration::AUTOGENERATE_* + * @phpstan-var MongoDbConfiguration::AUTOGENERATE_* */ protected int $generateHydrators = MongoDbConfiguration::AUTOGENERATE_ALWAYS; @@ -61,7 +61,7 @@ final class Configuration extends AbstractOptions /** * Persistent collection generation strategy. * - * @psalm-var MongoDbConfiguration::AUTOGENERATE_* + * @phpstan-var MongoDbConfiguration::AUTOGENERATE_* */ protected int $generatePersistentCollections = MongoDbConfiguration::AUTOGENERATE_ALWAYS; @@ -135,7 +135,7 @@ public function getDriver(): string return 'doctrine.driver.' . $this->driver; } - /** @psalm-param MongoDbConfiguration::AUTOGENERATE_* $generateProxies */ + /** @phpstan-param MongoDbConfiguration::AUTOGENERATE_* $generateProxies */ public function setGenerateProxies(int $generateProxies): self { $this->generateProxies = $generateProxies; @@ -143,7 +143,7 @@ public function setGenerateProxies(int $generateProxies): self return $this; } - /** @psalm-return MongoDbConfiguration::AUTOGENERATE_* */ + /** @phpstan-return MongoDbConfiguration::AUTOGENERATE_* */ public function getGenerateProxies(): int { return $this->generateProxies; @@ -185,13 +185,13 @@ public function getProxyNamespace(): string return $this->proxyNamespace; } - /** @psalm-return MongoDbConfiguration::AUTOGENERATE_* */ + /** @phpstan-return MongoDbConfiguration::AUTOGENERATE_* */ public function getGenerateHydrators(): int { return $this->generateHydrators; } - /** @psalm-param MongoDbConfiguration::AUTOGENERATE_* $generateHydrators */ + /** @phpstan-param MongoDbConfiguration::AUTOGENERATE_* $generateHydrators */ public function setGenerateHydrators(int $generateHydrators): self { $this->generateHydrators = $generateHydrators; @@ -223,13 +223,13 @@ public function setHydratorNamespace(string $hydratorNamespace): self return $this; } - /** @psalm-return MongoDbConfiguration::AUTOGENERATE_* */ + /** @phpstan-return MongoDbConfiguration::AUTOGENERATE_* */ public function getGeneratePersistentCollections(): int { return $this->generatePersistentCollections; } - /** @psalm-param MongoDbConfiguration::AUTOGENERATE_* $generatePersistentCollections */ + /** @phpstan-param MongoDbConfiguration::AUTOGENERATE_* $generatePersistentCollections */ public function setGeneratePersistentCollections(int $generatePersistentCollections): self { $this->generatePersistentCollections = (int) $generatePersistentCollections; @@ -325,7 +325,7 @@ public function getLogger(): string|null return $this->logger; } - /** @psalm-return class-string|null */ + /** @phpstan-return class-string|null */ public function getClassMetadataFactoryName(): string|null { return $this->classMetadataFactoryName; @@ -362,7 +362,7 @@ public function setRepositoryFactory(string|null $repositoryFactory): Configurat return $this; } - /** @psalm-return class-string> */ + /** @phpstan-return class-string> */ public function getDefaultDocumentRepositoryClassName(): string|null { return $this->defaultDocumentRepositoryClassName; diff --git a/tests/Assets/CustomRepositoryFactory.php b/tests/Assets/CustomRepositoryFactory.php index cc1114e..05735c9 100644 --- a/tests/Assets/CustomRepositoryFactory.php +++ b/tests/Assets/CustomRepositoryFactory.php @@ -31,7 +31,7 @@ public function find($id): object|null /** * {@inheritDoc} * - * @psalm-return mixed[] + * @phpstan-return mixed[] */ public function findAll(): array { @@ -41,10 +41,14 @@ public function findAll(): array /** * {@inheritDoc} * - * @psalm-return mixed[] + * @phpstan-return mixed[] */ - public function findBy(array $criteria, array|null $orderBy = null, $limit = null, $offset = null): array - { + public function findBy( + array $criteria, + array|null $orderBy = null, + int|null $limit = null, + int|null $offset = null, + ): array { return []; } @@ -56,7 +60,7 @@ public function findOneBy(array $criteria): object|null return null; } - /** @psalm-return string */ + /** @phpstan-return string */ public function getClassName(): string { return stdClass::class; diff --git a/tests/Doctrine/ConfigurationFactoryTest.php b/tests/Doctrine/ConfigurationFactoryTest.php index 295f777..3636699 100644 --- a/tests/Doctrine/ConfigurationFactoryTest.php +++ b/tests/Doctrine/ConfigurationFactoryTest.php @@ -20,8 +20,6 @@ use DoctrineMongoODMModuleTest\Assets\CustomType; use Laminas\ServiceManager\ServiceManager; -use function assert; - final class ConfigurationFactoryTest extends AbstractTestCase { public function testCreation(): void @@ -97,8 +95,6 @@ public function testCreation(): void $factory = new ConfigurationFactory('odm_test'); $config = $factory($serviceLocator, Config::class); - assert($config instanceof Config); - $this->assertInstanceOf(Config::class, $config); $this->assertEquals(CacheAdapter::wrap($metadataCache), $config->getMetadataCache()); diff --git a/tests/Doctrine/CustomDefaultRepositoryTest.php b/tests/Doctrine/CustomDefaultRepositoryTest.php index 994f1fb..4d9bbf6 100644 --- a/tests/Doctrine/CustomDefaultRepositoryTest.php +++ b/tests/Doctrine/CustomDefaultRepositoryTest.php @@ -8,8 +8,6 @@ use DoctrineMongoODMModuleTest\Assets\CustomDocumentRepository; use DoctrineMongoODMModuleTest\Assets\Document\Simple; -use function assert; - final class CustomDefaultRepositoryTest extends AbstractTestCase { public function testCustomDefaultRepository(): void @@ -19,7 +17,6 @@ public function testCustomDefaultRepository(): void $repository = $documentManager->getRepository(Simple::class); $this->assertInstanceOf(CustomDocumentRepository::class, $repository); - assert($repository instanceof CustomDocumentRepository); $this->assertTrue($repository->isCustomDefaultDocumentRepository()); } }