Roave / BetterReflection

:crystal_ball: Better Reflection is a reflection API that aims to improve and provide more features than PHP's built-in reflection API.
MIT License
1.18k stars 131 forks source link

Add fix for SplObjectStorage with next PHPStorm stubs #1448

Closed VincentLanglet closed 4 days ago

VincentLanglet commented 1 week ago

While working on https://github.com/Roave/BetterReflection/pull/1445

I discovered that in the next PHPStorm/stub tag you'll get an issue with SplObjectStorage because Iterator is changed to SeekableIterator for PHP >= 8.4. https://github.com/JetBrains/phpstorm-stubs/blob/56f6b9e55f5885e651553843a1aaf9ec9c586c04/SPL/SPL_c1.php#L2061

So I extracted the fix in a separate PR.

ondrejmirtes commented 6 days ago

I feel like there should definitely be a test added. You can ask about the interfaces this class implements.

Otherwise you can run into a mutant: if $modifiedNames[] = new Node\Name\FullyQualified(Iterator::class); would get removed, no tests would fail.

VincentLanglet commented 6 days ago

I feel like there should definitely be a test added. You can ask about the interfaces this class implements.

Otherwise you can run into a mutant: if $modifiedNames[] = new Node\Name\FullyQualified(Iterator::class); would get removed, no tests would fail.

Current tests will fail without this fix as soon as the PHPStorm stubs will be updated here The error will be https://github.com/Roave/BetterReflection/actions/runs/10706859215/job/29685555800?pr=1445

1) Roave\BetterReflectionTest\SourceLocator\SourceStubber\PhpStormStubsSourceStubberTest::testInternalClasses with data set #73 ('SplObjectStorage')
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
     0 => 'ArrayAccess',
     1 => 'Countable',
     2 => 'Iterator',
-    3 => 'Serializable',
-    4 => 'Traversable',
+    3 => 'SeekableIterator',
+    4 => 'Serializable',
+    5 => 'Traversable',
 ]

D:\a\BetterReflection\BetterReflection\test\unit\SourceLocator\SourceStubber\PhpStormStubsSourceStubberTest.php:[178](https://github.com/Roave/BetterReflection/actions/runs/10706859215/job/29685555800?pr=1445#step:6:179)
D:\a\BetterReflection\BetterReflection\test\unit\SourceLocator\SourceStubber\PhpStormStubsSourceStubberTest.php:186
D:\a\BetterReflection\BetterReflection\test\unit\SourceLocator\SourceStubber\PhpStormStubsSourceStubberTest.php:156
Ocramius commented 4 days ago

Thanks @VincentLanglet!