-
Notifications
You must be signed in to change notification settings - Fork 575
Add @implements to SPL iterator stubs
#5672
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
base: 2.2.x
Are you sure you want to change the base?
Changes from all commits
28cf00c
6a76e67
85ee9b3
dab3e58
a5d98fd
93455b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,22 +159,19 @@ class ArrayIterator implements SeekableIterator, ArrayAccess, Countable | |
| } | ||
|
|
||
| /** | ||
| * @template T of \RecursiveIterator|\IteratorAggregate | ||
| * @mixin T | ||
| * @template TValue = mixed | ||
| * @implements SeekableIterator<string, TValue> | ||
| */ | ||
| class RecursiveIteratorIterator | ||
| class DirectoryIterator extends SplFileInfo implements SeekableIterator | ||
| { | ||
| /** | ||
| * @param T $iterator | ||
| */ | ||
| public function __construct( | ||
| $iterator, | ||
| int $mode = RecursiveIteratorIterator::LEAVES_ONLY, | ||
| int $flags = 0 | ||
| ) | ||
| { | ||
|
|
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @extends DirectoryIterator<SplFileInfo|string> | ||
| */ | ||
| class FilesystemIterator extends DirectoryIterator | ||
| { | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -207,6 +204,29 @@ class IteratorIterator implements OuterIterator { | |
| public function __construct(Traversable $iterator) {} | ||
| } | ||
|
|
||
| /** | ||
| * @template T of \RecursiveIterator|\IteratorAggregate | ||
| * | ||
| * @implements OuterIterator<key-of<T>, value-of<T>> | ||
| * | ||
| * @mixin T | ||
| */ | ||
| class RecursiveIteratorIterator implements OuterIterator | ||
| { | ||
| /** | ||
| * @param T $iterator | ||
| */ | ||
| public function __construct( | ||
| $iterator, | ||
| int $mode = RecursiveIteratorIterator::LEAVES_ONLY, | ||
| int $flags = 0 | ||
| ) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * @template-covariant TKey | ||
| * @template-covariant TValue | ||
|
|
@@ -289,6 +309,14 @@ class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator | |
| public function uksort($cmp_function) { } | ||
| } | ||
|
|
||
| /** | ||
| * @implements RecursiveIterator<string, SplFileInfo|string> | ||
| */ | ||
| class RecursiveDirectoryIterator extends FilesystemIterator implements RecursiveIterator | ||
|
Comment on lines
+312
to
+315
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looking at the above baseline.neon comment, I realized it might be a nice improvement to infer the if we could do this, we would not have the baseline entry (this might also be stuff for a future PR) might be doable for more iterators which work with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to do something like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need a extension and I agree, it should be a followup |
||
| { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * @template TKey | ||
| * @template TValue | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug8435; | ||
|
|
||
| use RecursiveDirectoryIterator; | ||
| use RecursiveIteratorIterator; | ||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| class HelloWorld | ||
| { | ||
| public function sayHello1(string $path): void | ||
| { | ||
| $iterator = new RecursiveDirectoryIterator($path); | ||
| foreach ($iterator as $fileinfo) { | ||
| assertType('SplFileInfo|string', $fileinfo); | ||
| } | ||
| } | ||
|
|
||
| public function sayHello2(string $path): void | ||
| { | ||
| $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); | ||
| foreach ($iterator as $fileinfo) { | ||
| assertType('SplFileInfo|string', $fileinfo); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param RecursiveIteratorIterator<RecursiveDirectoryIterator> $iterator | ||
| */ | ||
| public function test(RecursiveIteratorIterator $iterator): void | ||
| { | ||
| foreach ($iterator as $fileinfo) { | ||
| assertType('SplFileInfo|string', $fileinfo); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of computer today
@staabm do we have assert in the codebase or should it be a shouldNotHappen exception ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, we have some of them already