Skip to content

RemoveAlwaysElseRector bug #2842

@escopecz

Description

@escopecz
Subject Details
Rector version v0.6.13)
PHP version PHP 7.2
Full Command e.g. vendor/bin/rector process /src --set dead-code --debug
Demo link https://getrector.org/demo/dacac137-cae9-4d24-a153-06e5016615c1#result
rector.yaml in the demo

Current Behaviour

Rector moves the elseif part out of the foreach loop and breaks the code. It should stay in the loop.

Minimal PHP Code Causing Issue

Applied rules:

  • Rector\SOLID\Rector\If_\RemoveAlwaysElseRector
<?php declare(strict_types=1);

final class DemoFile
{
    public function run(array $list, bool $removeEmpty)
    {
        foreach ($list as $val => $label) {
			if ($removeEmpty && empty($val) && empty($label)) {
				continue;
			} elseif (empty($label)) {
				$label = $val;
			}
		}
    }
}

Expected Behaviour

The elseif part should stay in the foreach loop scope.

Metadata

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