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 produces invalid indices when using ternary operator #2694

Closed
michalbundyra opened this issue Nov 14, 2019 · 0 comments · Fixed by #2695
Closed

AbstractArraySniff produces invalid indices when using ternary operator #2694

michalbundyra opened this issue Nov 14, 2019 · 0 comments · Fixed by #2695

Comments

@michalbundyra
Copy link
Contributor

Example:

<?php

$array = [
    'foo' => 'foo',
    'bar' => $baz ? ['abc'] : ['def'],
    'baz' => 'baz',
];

Indices:

Array
(
    [0] => Array
        (
            [index_start] => 9
            [index_end] => 9
            [arrow] => 11
            [value_start] => 13
        )

    [1] => Array
        (
            [index_start] => 17
            [index_end] => 17
            [arrow] => 19
            [value_start] => 21
        )

    [2] => Array
        (
            [value_start] => 31
        )

    [3] => Array
        (
            [index_start] => 37
            [index_end] => 37
            [arrow] => 39
            [value_start] => 41
        )
)

Above is dump of variable $indices in method AbstractArraySniff::processMultiLineArray.

It is wrong, because array contains 3 elements, all 3 with keys.
The problem is because of ternary operator.

@gsherwood gsherwood changed the title AbstractArraySniff - invalid indices when using ternary operator AbstractArraySniff produces invalid indices when using ternary operator Nov 14, 2019
@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Nov 14, 2019
@gsherwood gsherwood added this to the 3.5.3 milestone Nov 14, 2019
@gsherwood gsherwood moved this from Idea Bank to Ready for Release in PHPCS v3 Development Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
2 participants