-
-
Notifications
You must be signed in to change notification settings - Fork 417
Directly check type of substr() on RecastingRemovalRector #7446
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
Conversation
| && $this->isName($node->expr, 'substr') | ||
| && ! $node->expr->isFirstClassCallable()) { | ||
| $nodeType = new UnionType([new StringType(), new ConstantBooleanType(false)]); | ||
| } |
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.
This should be checked by version in Rector. If on PHP 8.0+, this should be skipped.
And new downgrade rule added to make it safe
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.
The downgrade rule need to exists first then, as without this, the cast string will be removed at
and add back the regression bug.
After downgrade rule created, then we can safely remove this check.
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.
Please revert this first and add PHP version check, so we don't create regressions in existing rule.
Then make a downgrade rule 🙏
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.
There is no need php version check, as phpstan already check it when run on php 7.x, just need add skip config in rector.php for now:
// on php 7.x, substr() result can return false, so force (string) is needed
RecastingRemovalRector::class => [
__DIR__ . '/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/ClassLikeNameClassNameImportSkipVoter.php',
],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.
| } | ||
|
|
||
| return strtoupper('warning'); | ||
| return substr('warning', 1); |
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.
Instead of changing existing fixture, always make a new one. To make clear former one works.
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.
it is the old fixture behaviour, see previous PR revert:
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.
This is original fixture before the changes train, see PR order changes:
- [DeadCode] Skip remove cast (string) on substr as may return false on php 7.x on RecastingRemovalRector #7442 (change to strtoupper due to cause issue on type declaration set)
- Directly check type of substr() on RecastingRemovalRector #7446 (This PR back to original, only change the RecastingRemovalRector only)
- [DeadCode] Skip ClassLikeNameClassNameImportSkipVoter for RecastingRemovalRector #7448 (Next, I only back to skip via
rector.php, and add test for cast removal for(string) substr()for RecastingRemovalRector)
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.
Same as before, do not change fixture, but rather add new one. Renaming a fuction that we talk about is confusing to read.
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.
@samsonasik Exactly my point. Instead of renaming fixture content back and forth and having to read 3 PRs to understand, they should be always related only to current PR. These PRs should be independent on each other, standalone units.
Avoid on
NodeTypeResolverto avoid on purposestringon php 8.x on type declaration set.Let's do per use case fix.