diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index e9c9810..e8d4a8e 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -20,7 +20,7 @@ ->setCacheFile(__DIR__ . '/var/' . basename(__FILE__) . '.cache'); (new PhpCsFixerCodingStandard())->applyTo($config, [ - // 'rule' => ['overridden' => 'config'], + 'new_expression_parentheses' => false, ]); return $config; diff --git a/composer.json b/composer.json index aee5825..371c5ed 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "php": "^8.1" }, "require-dev": { - "phpunit/phpunit": "^10.5.46", + "phpunit/phpunit": "^11.5.53", "symfony/var-dumper": "^6.4.21 || ^7.2.3" }, "autoload": { diff --git a/src/formatClass.fn.php b/src/formatClass.fn.php index ab9e33a..50c7695 100644 --- a/src/formatClass.fn.php +++ b/src/formatClass.fn.php @@ -15,7 +15,7 @@ function formatClass(string|object $class): string $class = $class::class; } - if (preg_match('/^(.+)anonymous\x00(.+?)[:(](\d+)/', $class, $matches)) { + if (preg_match('/^(.+)anonymous\x00(.+?)[:(](\d+)/', $class, $matches) === 1) { return "{$matches[1]}{$matches[2]}:{$matches[3]}"; } diff --git a/src/formatFunction.fn.php b/src/formatFunction.fn.php index e3b135e..78c7b20 100644 --- a/src/formatFunction.fn.php +++ b/src/formatFunction.fn.php @@ -8,6 +8,7 @@ * @api * @param callable $function native type is intentionally not used to avoid autoloading during callable type check * @return non-empty-string + * @phpstan-ignore missingType.callable */ function formatFunction(mixed $function): string { @@ -29,5 +30,5 @@ function formatFunction(mixed $function): string } /** @var object $function */ - return \sprintf('%s()', formatClass($function)); + return \sprintf('%s()', formatClass($function)); // @phpstan-ignore varTag.type } diff --git a/src/formatParameter.fn.php b/src/formatParameter.fn.php index 9399a2b..017a941 100644 --- a/src/formatParameter.fn.php +++ b/src/formatParameter.fn.php @@ -9,6 +9,7 @@ * @param callable $function native type is intentionally not used to avoid autoloading during callable type check * @param non-negative-int|non-empty-string $parameter * @return non-empty-string + * @phpstan-ignore missingType.callable */ function formatParameter(mixed $function, int|string $parameter): string { diff --git a/src/formatReflectedFunction.fn.php b/src/formatReflectedFunction.fn.php index a6e43fd..d4045af 100644 --- a/src/formatReflectedFunction.fn.php +++ b/src/formatReflectedFunction.fn.php @@ -17,7 +17,7 @@ function formatReflectedFunction(\ReflectionFunctionAbstract $function): string return 'function()'; } - if (preg_match('/^(.*)\((\d+)\)/', $file, $matches)) { + if (preg_match('/^(.*)\((\d+)\)/', $file, $matches) === 1) { return \sprintf('function@%s:%d()', $matches[1], $matches[2]); } diff --git a/src/formatReflectedProperty.fn.php b/src/formatReflectedProperty.fn.php index 7835f26..48ca83d 100644 --- a/src/formatReflectedProperty.fn.php +++ b/src/formatReflectedProperty.fn.php @@ -10,6 +10,5 @@ */ function formatReflectedProperty(\ReflectionProperty $property): string { - /** @phpstan-ignore argument.type */ return formatProperty($property->class, $property->name); } diff --git a/tests/FormatFunctionTest.php b/tests/FormatFunctionTest.php index bfa5af1..d4e20d4 100644 --- a/tests/FormatFunctionTest.php +++ b/tests/FormatFunctionTest.php @@ -13,10 +13,12 @@ final class FormatFunctionTest extends TestCase { /** * @param callable $closure + * @phpstan-param mixed $closure */ #[DataProvider('provideFormatFunctionCases')] public function testFormatFunction(mixed $closure, string $expectedFormattedFunction): void { + /** @phpstan-ignore argument.type */ $formatted = formatFunction($closure); self::assertSame($expectedFormattedFunction, $formatted); @@ -24,9 +26,11 @@ public function testFormatFunction(mixed $closure, string $expectedFormattedFunc /** * @return \Generator + * @phpstan-ignore missingType.callable */ public static function provideFormatFunctionCases(): iterable { + /** @phpstan-ignore-next-line generator.valueType */ yield 'brackets to string with ::' => [ \sprintf('%s::cases', self::class), \sprintf('%s::cases()', self::class), diff --git a/tests/FormatReflectedClassTest.php b/tests/FormatReflectedClassTest.php index 16d5748..732bcaf 100644 --- a/tests/FormatReflectedClassTest.php +++ b/tests/FormatReflectedClassTest.php @@ -12,7 +12,9 @@ final class FormatReflectedClassTest extends TestCase { public function testFormatReflectedClass(): void { - $expectedFormattedClass = formatReflectedClass(new \ReflectionClass(\ReflectionClass::class)); + /** @var \ReflectionClass $reflectedClass */ + $reflectedClass = new \ReflectionClass(\ReflectionClass::class); + $expectedFormattedClass = formatReflectedClass($reflectedClass); $formatted = formatClass(\ReflectionClass::class); diff --git a/tests/FormatReflectedFunctionTest.php b/tests/FormatReflectedFunctionTest.php index 2102cf9..8acd0e4 100644 --- a/tests/FormatReflectedFunctionTest.php +++ b/tests/FormatReflectedFunctionTest.php @@ -33,8 +33,8 @@ public static function provideFormatReflectedFunctionCases(): iterable self::class . '::testFormatReflectedFunction()', ]; yield 'from class method' => [ - new \ReflectionMethod(new self('name'), 'cases'), - self::class . '::cases()', + new \ReflectionMethod(self::class, 'testFormatReflectedFunction'), + self::class . '::testFormatReflectedFunction()', ]; yield 'from named method' => [new \ReflectionFunction('trim'), 'trim()']; yield 'from closure method' => [ diff --git a/tests/FormatReflectedTypeTest.php b/tests/FormatReflectedTypeTest.php index 45dcdfe..3ba8368 100644 --- a/tests/FormatReflectedTypeTest.php +++ b/tests/FormatReflectedTypeTest.php @@ -27,19 +27,19 @@ public static function provideFormatReflectedTypeCases(): iterable { yield 'from null' => [null, '']; yield 'from exact type' => [ - (new \ReflectionFunction(static fn(int $a) => null))->getParameters()[0]->getType(), + (new \ReflectionFunction(static fn(int $a) => null))->getParameters()[0]->getType(), // @phpstan-ignore offsetAccess.notFound 'int', ]; yield 'from nullable type' => [ - (new \ReflectionFunction(static fn(?int $a) => null))->getParameters()[0]->getType(), + (new \ReflectionFunction(static fn(?int $a) => null))->getParameters()[0]->getType(), // @phpstan-ignore offsetAccess.notFound '?int', ]; yield 'from union type' => [ - (new \ReflectionFunction(static fn(string|int $a) => null))->getParameters()[0]->getType(), + (new \ReflectionFunction(static fn(string|int $a) => null))->getParameters()[0]->getType(), // @phpstan-ignore offsetAccess.notFound 'string|int', ]; yield 'from intersection type' => [ - (new \ReflectionFunction(static fn(\IteratorAggregate&\Iterator $a) => null))->getParameters()[0]->getType(), + (new \ReflectionFunction(static fn(\IteratorAggregate&\Iterator $a) => null))->getParameters()[0]->getType(), // @phpstan-ignore offsetAccess.notFound 'IteratorAggregate&Iterator', ]; }