From bba2b8dd4c1b8841d5d270250ae71921fb171b7e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 12 Nov 2024 09:29:23 +0100 Subject: [PATCH] Update to PHPStan 2.0 --- CHANGELOG.md | 1 + composer.json | 3 ++- functions/functions.php | 1 + phpstan.neon | 6 +++++- src/Factory/ValinorConfigFactory.php | 2 ++ .../DottedAccessConfigAbstractFactoryTest.php | 18 +++++++++--------- test/Factory/ValinorConfigFactoryTest.php | 1 + 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98ebdcf..cf1b94d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this ### Changed * Update shlinkio coding standard to v2.4 +* Update to PHPStan 2.0 ### Deprecated * *Nothing* diff --git a/composer.json b/composer.json index ea30265..b0cf544 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "require-dev": { "cuyz/valinor": "^1.12", "devster/ubench": "^2.1", - "phpstan/phpstan": "^1.12", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", "phpunit/phpunit": "^11.4", "psr/simple-cache": "^2.0", "roave/security-advisories": "dev-master", diff --git a/functions/functions.php b/functions/functions.php index e698367..2876ba6 100644 --- a/functions/functions.php +++ b/functions/functions.php @@ -91,6 +91,7 @@ function putNotYetDefinedEnv(string $key, mixed $value): void return; } + // @phpstan-ignore argument.type $formattedValue = formatEnvVarValueOrNull($value); if ($formattedValue === null) { return; diff --git a/phpstan.neon b/phpstan.neon index 3ee65eb..d1eafbb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,11 @@ +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon parameters: - level: 8 + level: 9 paths: - functions - src + - test ignoreErrors: - identifier: missingType.iterableValue diff --git a/src/Factory/ValinorConfigFactory.php b/src/Factory/ValinorConfigFactory.php index a796682..478310e 100644 --- a/src/Factory/ValinorConfigFactory.php +++ b/src/Factory/ValinorConfigFactory.php @@ -21,6 +21,7 @@ public static function __callStatic(string $name, array $arguments): mixed $mapper = self::getMapper($container); $options = $container->get($name); + // @phpstan-ignore argument.type return $mapper->map($serviceName, Source::array($options)->camelCaseKeys()); } @@ -33,6 +34,7 @@ private static function getMapper(ContainerInterface $container): TreeMapper $mapper = (new MapperBuilder())->allowSuperfluousKeys(); if ($container->has(CacheInterface::class)) { + // @phpstan-ignore argument.type return $mapper = $mapper->withCache($container->get(CacheInterface::class))->mapper(); } diff --git a/test/Factory/DottedAccessConfigAbstractFactoryTest.php b/test/Factory/DottedAccessConfigAbstractFactoryTest.php index e9e9d3f..a641218 100644 --- a/test/Factory/DottedAccessConfigAbstractFactoryTest.php +++ b/test/Factory/DottedAccessConfigAbstractFactoryTest.php @@ -23,10 +23,10 @@ public function setUp(): void } #[Test] - #[TestWith(data: ['foo.bar', true], name: 'valid service')] - #[TestWith(data: ['config.something', true], name: 'another valid service')] - #[TestWith(data: ['config_something', false], name: 'invalid service')] - #[TestWith(data: ['foo', false], name: 'another invalid service')] + #[TestWith(['foo.bar', true], 'valid service')] + #[TestWith(['config.something', true], 'another valid service')] + #[TestWith(['config_something', false], 'invalid service')] + #[TestWith(['foo', false], 'another invalid service')] public function canCreateOnlyServicesWithDot(string $serviceName, bool $canCreate): void { self::assertEquals($canCreate, $this->factory->canCreate(new ServiceManager(), $serviceName)); @@ -44,11 +44,11 @@ public function throwsExceptionWhenFirstPartOfTheServiceIsNotRegistered(): void } #[Test] - #[TestWith(data: ['string'], name: 'string')] - #[TestWith(data: [new stdClass()], name: 'object')] - #[TestWith(data: [true], name: 'true')] - #[TestWith(data: [false], name: 'false')] - #[TestWith(data: [100], name: 'number')] + #[TestWith(['string'], 'string')] + #[TestWith([new stdClass()], 'object')] + #[TestWith([true], 'true')] + #[TestWith([false], 'false')] + #[TestWith([100], 'number')] public function throwsExceptionWhenFirstPartOfTheServiceDoesNotResultInAnArray(mixed $value): void { $this->expectException(ServiceNotCreatedException::class); diff --git a/test/Factory/ValinorConfigFactoryTest.php b/test/Factory/ValinorConfigFactoryTest.php index d9e1167..926741d 100644 --- a/test/Factory/ValinorConfigFactoryTest.php +++ b/test/Factory/ValinorConfigFactoryTest.php @@ -68,6 +68,7 @@ public function throwsExceptionWhenTryingToMapInvalidData(array $config): void ]]); $this->expectException(MappingError::class); + // @phpstan-ignore staticMethod.notFound ValinorConfigFactory::config($serviceManager, FooModel::class); }