Is there a neat search and replace model for reformatting php's old array
style to the newer/cleaner json style - without reformatting the entire document with a formatter extension*
$flibble = array('foo' => 'bar');
$wibble = array(
'linefeeds' => true,
);
$flibble = ['foo' => 'bar'];
$wibble = [
'linefeeds' => true,
];
*
Aside; I can't actually find a PHP Formatter for VSC which does this either...
No idea how to do it with visual studio code itself but here are some solutions:
Using PHP Codesniffer:
https://github.com/squizlabs/PHP_CodeSniffer
phpcbf src/ --standard=Generic --sniffs=Generic.Arrays.DisallowLongArraySyntax
or
https://github.com/thomasbachem/php-short-array-syntax-converter
There is now a vscode plugin:
https://marketplace.visualstudio.com/items?itemName=Yannick.php-convert-array
I haven't tried it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With