Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded from PHPStan 1.12 to 2.0 #292

Merged
merged 1 commit into from
Dec 29, 2024
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 3 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
22 changes: 11 additions & 11 deletions src/Options/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -135,15 +135,15 @@ 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;

return $this;
}

/** @psalm-return MongoDbConfiguration::AUTOGENERATE_* */
/** @phpstan-return MongoDbConfiguration::AUTOGENERATE_* */
public function getGenerateProxies(): int
{
return $this->generateProxies;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -325,7 +325,7 @@ public function getLogger(): string|null
return $this->logger;
}

/** @psalm-return class-string<ClassMetadataFactory>|null */
/** @phpstan-return class-string<ClassMetadataFactory>|null */
public function getClassMetadataFactoryName(): string|null
{
return $this->classMetadataFactoryName;
Expand Down Expand Up @@ -362,7 +362,7 @@ public function setRepositoryFactory(string|null $repositoryFactory): Configurat
return $this;
}

/** @psalm-return class-string<ObjectRepository<object>> */
/** @phpstan-return class-string<ObjectRepository<object>> */
public function getDefaultDocumentRepositoryClassName(): string|null
{
return $this->defaultDocumentRepositoryClassName;
Expand Down
14 changes: 9 additions & 5 deletions tests/Assets/CustomRepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function find($id): object|null
/**
* {@inheritDoc}
*
* @psalm-return mixed[]
* @phpstan-return mixed[]
*/
public function findAll(): array
{
Expand All @@ -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 [];
}

Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions tests/Doctrine/ConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
use DoctrineMongoODMModuleTest\Assets\CustomType;
use Laminas\ServiceManager\ServiceManager;

use function assert;

final class ConfigurationFactoryTest extends AbstractTestCase
{
public function testCreation(): void
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 0 additions & 3 deletions tests/Doctrine/CustomDefaultRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}