Search code examples
phpcode-standards

Fixing code style: change double quote strings to single quote in PHP when there are no variables in them


I am wondering if there is a tool, that will parse a PHP project and fix a bad code style.

That is a double quoted string that has no variables should be changed to single quote.

$var1="change enclosing to single quote"."here too";
$var2="change enclosing in this string but keep $i"."change it here";

I would like to rewrite automatically in entire project to:

$var1='change enclosing to single quote'.'here too';
$var2='do not change enclosing in this string '.$i.'change it here';

Solution

  • PHP codesniffer will show these for you so you can change them before you commit code to the repository but this method is preventative not fixing something afterwards...

    http://pear.php.net/package/PHP_CodeSniffer/redirected

    This is a methodology you should follow when developing.