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

AbstractArraySniff wrong indices when mixed coalesce and ternary values #2745

Closed
michalbundyra opened this issue Dec 5, 2019 · 0 comments · Fixed by #2746
Closed

AbstractArraySniff wrong indices when mixed coalesce and ternary values #2745

michalbundyra opened this issue Dec 5, 2019 · 0 comments · Fixed by #2746
Milestone

Comments

@michalbundyra
Copy link
Contributor

Code:

<?php

return [

    $a => static function () {
        return [1, 2, 3];
    },

    $b ?? $c,
    $d ? [$e] : [$f],

];

Indicies:

Array
(
    [0] => Array
        (
            [index_start] => 8
            [index_end] => 8
            [arrow] => 10
            [value_start] => 12
        )

)

The problem is here:

if ($tokens[$checkToken]['code'] === T_INLINE_THEN
|| $tokens[$checkToken]['code'] === T_COALESCE
) {
$checkToken = $phpcsFile->findEndOfStatement($checkToken);
continue;
}

as we do not have arrows for two last elements in array, above finds end of the statement - comma - and then skip to next element.

@gsherwood gsherwood added this to the 3.5.4 milestone Dec 8, 2019
@gsherwood gsherwood changed the title AbstractArray wrong indices AbstractArraySniff wrong indices when mixed coalesce and ternary values Jan 14, 2020
gsherwood added a commit that referenced this issue Jan 14, 2020
Includes fix for unit test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants