-
-
Notifications
You must be signed in to change notification settings - Fork 340
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
[DX] Make PhpDocInfoFactory explicitly required in Rector rule constructor, if needed #5051
Conversation
46ec435
to
b66b567
Compare
…tor injection, to avoid global dependencies
b66b567
to
3afbff8
Compare
* Handle deprecated dependencies compatbility | ||
*/ | ||
public function __get(string $name): mixed | ||
{ |
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.
I think this should has soft warning:
if (! property_exists($this, $name) && isset($this->deprecatedDependencies[$name])) {
$this->symfonyStyle->warning(
sprintf('pull %s property from AbstractRector is deprecated, inject via __construct() instead', $name)
);
}
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.
Good idea 👍 Could you add it?
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.
I wil try 👍
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.
adding warning on __get()
seems make too many verbose in console:
➜ rector-src git:(main) ✗ bin/rector process src
0/146 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0%
pull phpDocInfoFactory property from AbstractRector on class Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector is deprecated, inject via __construct() instead
pull phpDocInfoFactory property from AbstractRector on class Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector is deprecated, inject via __construct() instead
pull phpDocInfoFactory property from AbstractRector on class Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector is deprecated, inject via __construct() instead
pull phpDocInfoFactory property from AbstractRector on class Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\TicketAnnotationToAttributeRector is deprecated, inject via __construct() instead
pull phpDocInfoFactory property from AbstractRector on class Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\AnnotationWithValueToAttributeRector is deprecated, inject via __construct() instead
if next release is 0.19, then I think the __get()
itself is unnecessary, then add release note instead.
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.
Ok, message seems can be cached, see #5069
AbstractRector is quite heavy class with "handy" dependencies. At least that was the original idea :)
Now it contains ~15 services just in case they're used in child service:
rector-src/src/Rector/AbstractRector.php
Lines 86 to 114 in 5ee831f
This design doesn't seem smart anymore and only forces each rule to decide if they use global dependency or local one. It's like having Doctrine serivce in every Controller.
Instead, there should be zero global dependencies (unless used in the AbstractRector itself) and each rule should ask only what they need. Goal is to make design from ambiguous to single dependency injection, and lighten all the rules.