Skip to content

New sniff: change long list syntax to short list syntax #5

@jrfnl

Description

@jrfnl
Sniff basics -
Fixable for PHP: 7.1+
Sniff type: Modernize
Fixer type: Safe

Short description

PHP 7.1 introduced a short list syntax.

Related PHPCompatibility sniff(s):

PHP manual references:

Example code:

Detect the following code pattern(s):

list($id1, $name1) = $data[0];

foreach ($data as list($id, $name)) {
    // logic here with $id and $name
}

And fix these to:

[$id1, $name1] = $data[0];

foreach ($data as [$id, $name]) {
    // logic here with $id and $name
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions