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
[CodeQuality] Handle negative and positive int/float on InlineConstructorDefaultToPropertyRector #5159
Conversation
…faultToPropertyRector
Fixed 🎉 /cc @JulianCBC |
All checks have passed 🎉 @TomasVotruba let's merge it ;) |
Is this actually enough to fully handle class Test {
public $thing;
public function __construct() {
$this->thing = -CONSTANT;
}
} should also get moved? |
Accessing constant on property default value can be dangerous that cause compile time error, see https://3v4l.org/W8Epd I think exact int and float value is the safest :) |
I'm not disagreeing that it's the safest. I think that something like this would cover almost all possible scenarios: if ($expr instanceof UnaryPlus || $expr instanceof UnaryMinus) {
return $this->isDynamicExpr($expr->expr);
} |
I see, yes, it seems can be covered with: if ($expr instanceof UnaryPlus || $expr instanceof UnaryMinus) {
- return ! $expr->expr instanceof LNumber && ! $expr->expr instanceof DNumber;
+ return $this->isDynamicExpr($expr->expr);
+ } @JulianCBC could you create a PR improvement for it with add fixture for possible constants ? Thank you. |
Can do! PR incoming... |
Done: #5177 |
Fixes rectorphp/rector#8261