diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f6cd6fd5935..1b412271b50 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -120,6 +120,12 @@ parameters: count: 5 path: src/Analyser/TypeSpecifier.php + - + rawMessage: 'Cannot call method getPathname() on SplFileInfo|string.' + identifier: method.nonObject + count: 1 + path: src/Cache/FileCacheStorage.php + - rawMessage: 'Template type TNodeType is declared as covariant, but occurs in contravariant position in parameter node of method PHPStan\Collectors\Collector::processNode().' identifier: generics.variance diff --git a/stubs/iterable.stub b/stubs/iterable.stub index baf5ca90837..4d180a38cab 100644 --- a/stubs/iterable.stub +++ b/stubs/iterable.stub @@ -159,22 +159,10 @@ class ArrayIterator implements SeekableIterator, ArrayAccess, Countable } /** - * @template T of \RecursiveIterator|\IteratorAggregate - * @mixin T + * @implements SeekableIterator */ -class RecursiveIteratorIterator +class DirectoryIterator extends SplFileInfo implements SeekableIterator { - /** - * @param T $iterator - */ - public function __construct( - $iterator, - int $mode = RecursiveIteratorIterator::LEAVES_ONLY, - int $flags = 0 - ) - { - - } } @@ -207,6 +195,31 @@ class IteratorIterator implements OuterIterator { public function __construct(Traversable $iterator) {} } +/** + * @template-covariant TKey + * @template-covariant TValue + * @template TIterator of \RecursiveIterator|\IteratorAggregate + * + * @implements OuterIterator + * + * @mixin TIterator + */ +class RecursiveIteratorIterator implements OuterIterator +{ + /** + * @param TIterator $iterator + */ + public function __construct( + $iterator, + int $mode = RecursiveIteratorIterator::LEAVES_ONLY, + int $flags = 0 + ) + { + + } + +} + /** * @template-covariant TKey * @template-covariant TValue @@ -289,6 +302,14 @@ class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator public function uksort($cmp_function) { } } +/** + * @implements RecursiveIterator + */ +class RecursiveDirectoryIterator extends FilesystemIterator implements RecursiveIterator +{ + +} + /** * @template TKey * @template TValue diff --git a/tests/PHPStan/Analyser/nsrt/bug-8435.php b/tests/PHPStan/Analyser/nsrt/bug-8435.php new file mode 100644 index 00000000000..af4c03cfe56 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-8435.php @@ -0,0 +1,26 @@ +analyse([__DIR__ . '/data/bug-3425.php'], [ [ - 'Parameter #1 $iterator of class RecursiveIteratorIterator constructor expects T of IteratorAggregate|RecursiveIterator, Generator given.', + 'Parameter #1 $iterator of class RecursiveIteratorIterator constructor expects TIterator of IteratorAggregate|RecursiveIterator, Generator given.', 5, ], ]);