-
-
Notifications
You must be signed in to change notification settings - Fork 363
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
[Experiment] Rework child classes detection on DynamicSourceLocatorProvider #5735
Conversation
...eResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php
Outdated
Show resolved
Hide resolved
Ok, here investigation: 1 Tried back to Rector
got output: ➜ ci4-album git:(rector-0.x) ✗ vendor/bin/rector --dry-run
49/49 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
2 files with changes
====================
1) src/Domain/Exception/DuplicatedRecordException.php:12
---------- begin diff ----------
@@ @@
use DomainException;
-class DuplicatedRecordException extends DomainException
+final class DuplicatedRecordException extends DomainException which shouldnot as the class has child. I will check if there is possible way to "init" the classes to be resolved by phpstan Reflection. |
@TomasVotruba @staabm It somehow can be resolved by patch: - if (!$classReflection->isSubclassOf($desiredClassReflection->getName())) {
+ if ($desiredClassReflection->getName() !== $classReflection->getName() && !$classReflection->isSubclassOf($desiredClassReflection->getName())) {
continue;
} it seems
I will try apply the child detection back. |
I cannot follow, but you are right that you can use |
It seems the $classReflections = $this->privatesAccessor->getPrivateProperty($this->reflectionProvider, 'classes');
var_dump(count($classReflections)); Running on actual path only got 6 classes: ➜ ci4-album git:(rector-0.x) vendor/bin/rector process src/Domain/Exception/RecordNotFoundException.php --dry-run --clear-cache
0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0%int(6)
string(46) "Album\Domain\Exception\RecordNotFoundException"
string(15) "DomainException"
string(14) "LogicException"
string(9) "Exception"
string(9) "Throwable"
string(10) "Stringable" which should not, I will continue investigating if there is a way to init somewhere. |
ClassReflection only works on paths in the analyzed path or scan* configurations, thats expected and correct from PHPStan point of view (and composer autoloading I guess). |
@staabm thank you, I remember that on old phpstan, the code is working fine without the tweak, and on some point of phpstan release, it no longer working, I will continue investigating as it is interesting, I expect it should work with at least run on no path provided:
which means all classes loaded. |
fa34fa9
to
9a2fdbd
Compare
@TomasVotruba @staabm I finally got it working prototype 🎉 , tested on Rector 0.19.5 before the the Before ➜ ci4-album git:(rector-0.x) ✗ vendor/bin/rector process --dry-run --clear-cache
49/49 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
2 files with changes
====================
1) src/Domain/Exception/DuplicatedRecordException.php:12
---------- begin diff ----------
@@ @@
use DomainException;
-class DuplicatedRecordException extends DomainException
+final class DuplicatedRecordException extends DomainException After
I will check segmentation fault on package tests |
95167b9
to
527b2b4
Compare
527b2b4
to
34d2407
Compare
@nuryagdym @TomasVotruba @staabm it finally working again 🎉 🎉 🎉 , here the story: Long time ago, the children classes detection mostly always working, and mostly just require Turns out, the PHPStan has I tested in my own module: samsonasik/ci4-album#16 and it seems manually apply the code, and it finally working fine. This PR added back the feature, and the handle in and e2e test for the proof for Limitation:
➜ ci4-album git:(rector-0.x) ✗ vendor/bin/rector process src/Domain/Exception/DuplicatedRecordException.php --dry-run --clear-cache
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================
1) src/Domain/Exception/DuplicatedRecordException.php:12
---------- begin diff ----------
@@ @@
use DomainException;
-class DuplicatedRecordException extends DomainException
+final class DuplicatedRecordException extends DomainException so the run needs to apply on the parent and child classes contains, eg, both parent and child classes files: ➜ ci4-album git:(rector-0.x) ✗ vendor/bin/rector process src/Domain/Exception/DuplicatedRecordException.php src/Domain/Track/TrackDuplicatedRectorException.php --dry-run --clear-cache
2/2 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
[OK] Rector is done!
or the directory containst both: ➜ ci4-album git:(rector-0.x) ✗ vendor/bin/rector process src/ --dry-run --clear-cache
36/36 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
[OK] Rector is done! or just without arg: ➜ ci4-album git:(rector-0.x) ✗ vendor/bin/rector
36/36 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
[OK] Rector is done! If this PR merged, we can un-deprecate |
Thank you 👍 |
@nuryagdym @TomasVotruba this is experimental for rectorphp/rector#8557
Closes rectorphp/rector#8557