Skip to content

ChangeSwitchToMatchRector fails to parse a switch() #8937

Closed
rectorphp/rector-src
#6597
@MichaelBelgium

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions