Skip to content

Incorrect behavior of RemoveDuplicatedCaseInSwitchRector #9329

@mspirkov

Description

@mspirkov

Bug Report

Subject Details
Rector version dev-main

I found two bugs, which I have given examples of below. I don't know if it is necessary to split this into 2 issue

Minimal PHP Code Causing Issue

  1. https://getrector.com/demo/8cd8f6df-da4f-4ba3-8b3c-b8f9c787dada
<?php

final class DemoFile
{
	public function run($name): string 
    {
        switch ($name) {
            case 'a':
                return 'A';
            case 'b':
                return 'C';
            case 'd':
            case 'c':
            case 'f':
            default:
                return 'C';
        }
	}
}
  1. https://getrector.com/demo/fea7ead6-bdc0-4912-9c59-a03a32b2d400
<?php

final class DemoFile
{
	public function run($name): string 
    {
        switch ($item) {
            case 'a':
            case 'b':
                return 'val1';
            case 'c':
                return 'val2';
            case 'd':
            case 'e':
                return 'val5';
            case 'f':
            case 'g':
            case 'h':
                return 'val2';
            case 'i':
                return 'val3';
        }
	}
}

Expected Behaviour

First example:

<?php

final class DemoFile
{
	public function run($name): string 
    {
        switch ($name) {
            case 'a':
                return 'A';
            case 'b':
            case 'd':
            case 'c':
            case 'f':
            default:
                return 'C';
        }
	}
}

Second example:

<?php

final class DemoFile
{
	public function run($name): string 
    {
        switch ($item) {
            case 'a':
            case 'b':
                return 'val1';
            case 'c':
            case 'f':
            case 'g':
            case 'h':
                return 'val2';
            case 'd':
            case 'e':
                return 'val5';
            case 'i':
                return 'val3';
        }
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions