Open jrfnl opened 6 years ago
PHP 5.4 introduced the short array syntax.
ShortArray
Short array syntax has been added, e.g. $a = [1, 2, 3, 4]; or $a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];.
http://php.net/manual/en/migration54.new-features.php
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 ];
Generic.Arrays.DisallowLongArraySyntax
Short description
PHP 5.4 introduced the short array syntax.
Related PHPCompatibility sniff(s):
ShortArray
PHP manual references:
http://php.net/manual/en/migration54.new-features.php
Example code:
Detect the following code pattern(s):
And fix these to:
Notes for implementation of the sniff:
Generic.Arrays.DisallowLongArraySyntax
sniff can be used for this, but should only be invoked when the minimum PHP version for a project is PHP 5.4.