PHPCompatibility / PHPModernizer

External PHPCS standard with auto-fixers to modernize legacy codebases
GNU Lesser General Public License v3.0
10 stars 0 forks source link

New sniff: change long array syntax to short array syntax #4

Open jrfnl opened 6 years ago

jrfnl commented 6 years ago
Sniff basics -
Fixable for PHP: 5.4+
Sniff type: Modernize
Fixer type: Safe

Short description

PHP 5.4 introduced the short array syntax.

Related PHPCompatibility sniff(s):

PHP manual references:

Example code:

Detect the following code pattern(s):

$a = array(1, 2, 3, 4);
$a = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4);
$a = array(
    'one' => 1,
    'two' => 2,
    'three' => 3,
    'four' => 4
);

And fix these to:

$a = [1, 2, 3, 4];
$a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];
$a = [
    'one' => 1,
    'two' => 2,
    'three' => 3,
    'four' => 4
];

Notes for implementation of the sniff: