Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert php arrays with the new syntax

I looking for a way (regex, snippet ,plugin etc) to convert the old arrays with the new php syntax with sublimeText.

// Old synthax
$var = array(
   'foo' => 'bar' 
);

// New synthax
$var = [
   'foo' => 'bar'
];

someone has an idea ?

like image 827
Kafin Avatar asked Jun 03 '14 14:06

Kafin


2 Answers

I found a script that does the job perfectly !

https://github.com/thomasbachem/php-short-array-syntax-converter

like image 189
Kafin Avatar answered Oct 22 '22 17:10

Kafin


I found out that it is also possible to do this with the php codesniffer: https://github.com/squizlabs/PHP_CodeSniffer

phpcbf src/ --standard=Generic --sniffs=Generic.Arrays.DisallowLongArraySyntax

In this example you have to replace src/ with the folder containing the scripts. Alternatively you can provide a file name.

like image 34
David Albrecht Avatar answered Oct 22 '22 16:10

David Albrecht