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

Generic.WhiteSpace.ScopeIndent false positive when using ternary operator with short arrays #2702

Closed
SpazzMarticus opened this issue Nov 18, 2019 · 1 comment
Milestone

Comments

@SpazzMarticus
Copy link

SpazzMarticus commented Nov 18, 2019

Generic.WhiteSpace.ScopeIndent expects 4 more whitespace characters when using a ternary operator:

function failure($a)
{
    $a = $a === true ? [
        'a' => 1,
        'b' => 2,
        ] : [
        'a' => 100,
        'b' => 99,
    ]; //Line indented incorrectly; expected at least 8 spaces, found 4
}

Alternatives using ?: or ?? work fine with only 4 whitespace characters:

function success1($a)
{
    $a = $a === true ?: [
        'a' => 1,
        'b' => 2,
    ];
}

function success2($a)
{
    $a = $a === true ?? [
        'a' => 1,
        'b' => 2,
    ];
}

Is this expected behaviour?

@gsherwood gsherwood added this to the 3.5.3 milestone Nov 18, 2019
@gsherwood gsherwood changed the title ScopeIndent incorrect when using ternary operator Generic.WhiteSpace.ScopeIndent false positive when using ternary operator with short arrays Nov 18, 2019
gsherwood added a commit that referenced this issue Nov 18, 2019
…using ternary operator with short arrays

The first token was being recalculated but the indent was not being modified along with that new first token.
@gsherwood
Copy link
Member

Thanks for reporting this. There was a problem specifically checking short arrays in this case. The sniff was trying to align the closing bracket with the line that the opening bracket is on (hence the 8 spaces required) instead of with the start of the statement ($a = ...), which only required 4 spaces.

Fix will be in 3.5.3

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

No branches or pull requests

2 participants