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

ChangeSwitchToMatchRector fails to parse a switch() #8937

Closed
MichaelBelgium opened this issue Dec 16, 2024 · 0 comments · Fixed by rectorphp/rector-src#6597
Closed

ChangeSwitchToMatchRector fails to parse a switch() #8937

MichaelBelgium opened this issue Dec 16, 2024 · 0 comments · Fixed by rectorphp/rector-src#6597

Comments

@MichaelBelgium
Copy link

MichaelBelgium commented Dec 16, 2024

This is maybe similar to #8889 ?

[ERROR] Could not process "xxxxx" file, due to:
"System error: "PhpParser\PrettyPrinterAbstract::p(): Argument #1 ($node) must be of type PhpParser\Node, null
given, called in vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php612"
Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line: 571

It also says $node shouldn't be null.

I've found the line where it errors on and it has to do with a switch case and the change switch to match rector (ChangeSwitchToMatchRector)

switch($something) 
        {
        	case 'number':
            case 'percentage':
            case 'integer':
            case 'price':
            case 'decimal':
                $sort = SORT_NUMERIC;
                break;
            case 'string':
            case 'list':
            case 'text':
                $sort = SORT_NATURAL | SORT_FLAG_CASE;
                break;
            default:
                $sort = SORT_REGULAR;
        }

When removing the "default" clause, rector works again.

I recreated the switch case on the demo: https://getrector.com/demo/1d270752-64b2-42a8-aacc-f874eb294689

Using version 2.0.3

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 a pull request may close this issue.

1 participant