Skip to content

PhpCsFixer\Fixer\ControlStructure\SwitchContinueToBreakFixer: breaks control flow #78

Description

@CharlemagneLasse

The expected output is:

asd
blub

from following example:

<?php

declare(strict_types=1);

function foo(array $bar): void
{
    switch ($bar['type']) {
        case 1:
        case 2:
            $positions = match ($bar['subtype']) {
                0 => 1,
                1 => 3,
                default => 1,
            };

            for ($i = 1; ($positions + 1) > $i; ++$i) {
                if (!isset($bar['val'][$i])) {
                    continue;
                }

                print $bar['val'][$i] . "\n";
            }

            break;
    }
}

foo([
    'type' => 1,
    'subtype' => 1,
    'val' => [
        1 => 'asd',
        3 => 'blub',
    ],
]);

But the SwitchContinueToBreakFixer changes the continue to a break and thus the output is only

asd

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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