Skip to content
Open
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
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
->setCacheFile(__DIR__ . '/var/' . basename(__FILE__) . '.cache');

(new PhpCsFixerCodingStandard())->applyTo($config, [
// 'rule' => ['overridden' => 'config'],
'new_expression_parentheses' => false,
]);

return $config;
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/formatClass.fn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]}";
}

Expand Down
3 changes: 2 additions & 1 deletion src/formatFunction.fn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
}
1 change: 1 addition & 0 deletions src/formatParameter.fn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/formatReflectedFunction.fn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
1 change: 0 additions & 1 deletion src/formatReflectedProperty.fn.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
*/
function formatReflectedProperty(\ReflectionProperty $property): string
{
/** @phpstan-ignore argument.type */
return formatProperty($property->class, $property->name);
}
4 changes: 4 additions & 0 deletions tests/FormatFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ 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);
}

/**
* @return \Generator<string, array{callable, non-empty-string}>
* @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),
Expand Down
4 changes: 3 additions & 1 deletion tests/FormatReflectedClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ final class FormatReflectedClassTest extends TestCase
{
public function testFormatReflectedClass(): void
{
$expectedFormattedClass = formatReflectedClass(new \ReflectionClass(\ReflectionClass::class));
/** @var \ReflectionClass<object> $reflectedClass */
$reflectedClass = new \ReflectionClass(\ReflectionClass::class);
$expectedFormattedClass = formatReflectedClass($reflectedClass);

$formatted = formatClass(\ReflectionClass::class);

Expand Down
4 changes: 2 additions & 2 deletions tests/FormatReflectedFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
8 changes: 4 additions & 4 deletions tests/FormatReflectedTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
Expand Down