Skip to content
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 crash on yield from on OptionalParametersAfterRequiredRector #6545

Merged
merged 6 commits into from
Dec 11, 2024

Conversation

samsonasik
Copy link
Member

@samsonasik
Copy link
Member Author

Fixed 🎉

@TomasVotruba
Copy link
Member

Thank, looks good to me 👍

@samsonasik samsonasik merged commit f5c95f5 into main Dec 11, 2024
41 checks passed
@samsonasik samsonasik deleted the yield-from-crash branch December 11, 2024 11:15
@@ -60,7 +62,7 @@ public function resolve(string $rule): string
throw new RectorRuleNameAmbigiousException($message);
}

if (strpos($rule, '\\') === false) {
if (in_array(str_contains($rule, '\\'), [0, false], true)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rectify seems should be only str_contains($rule, '\\') === false, as str_contains never return 0, only bool. I will check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems due 2 rules, with union type, that buggy due to usage of:

if ($exprType->isBoolean()->yes()) {
 0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
PHPStan\Type\UnionType #22767
   types: array (2)
   |  0 => PHPStan\Type\IntegerRangeType #20331
   |  |  min: 0
   |  |  max: null
   |  1 => PHPStan\Type\Constant\ConstantBooleanType #22757
   |  |  value: false
   normalized: true
   sortedTypes: true
   cachedDescriptions: array (1)
   |  4 => 'int<0, max>|false'
➜  rector-src git:(main) ✗ bin/rector process src/Configuration/OnlyRuleResolver.php --dry-run
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================

1) src/Configuration/OnlyRuleResolver.php:61

    ---------- begin diff ----------
@@ @@
             throw new RectorRuleNameAmbigiousException($message);
         }

-        if (strpos($rule, '\\') === false) {
+        if (in_array(str_contains($rule, '\\'), [0, false], true)) {
             $message = sprintf(
                 'Rule "%s" was not found.%sThe rule has no namespace. Make sure to escape the backslashes, and add quotes around the rule name: --only="My\\Rector\\Rule"',
                 $rule,
    ----------- end diff -----------

Applied rules:
 * StrContainsRector
 * BooleanInBooleanNotRuleFixerRector

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's seems issue in phpstan side for detecting it as union, I just directly patch it on the code for now:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants