3

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';
Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • See the answer here: http://www.sematopia.com/2007/08/php-double-quotes-vs-single-quotes/ Having a very big site it turned out it will reduce generation time and reduce server load. That little bit it helps on this project. And it was request by an Audit company. – Pentium10 Oct 14 '10 at 11:50
  • @salathe: I think it's a good thing if your code consistent. Several years in programming i tried a lot of practices, now when i need to open my old codes, i'm doing the same - manually. – fabrik Oct 14 '10 at 11:51
  • 1
    Don't you have better things to do? Like actually profiling your application to see where it can be improved? – Mchl Oct 14 '10 at 11:55
  • The linked PHP official page from that article, says "If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters." I think what's on PHP page is official http://ca.php.net/types.string – Pentium10 Oct 14 '10 at 11:55
  • AND SO WHAT? yes, it will interpret. it does mean NOTHING – Your Common Sense Oct 14 '10 at 11:57
  • 3
    The company I work for, doesn't accept this coding style. Either give solution or ignore the question. – Pentium10 Oct 14 '10 at 11:57
  • BTW, what about these characters? like "\n" for example? want it being converted too? – Your Common Sense Oct 14 '10 at 11:58
  • @Col. Shrapnel "article been written by a fool" is not an argument – fabrik Oct 14 '10 at 11:59
  • Seriously, I gotta ask why you ask "Seriously, why"? It's obvious and NOT a lie. But as I know the Col. he's no person for discussions. By the way you can accomplish your goal, with most PHP-IDEs. – Fidi Oct 14 '10 at 11:59
  • coding style is one thing but these stupid tales about server load is another – Your Common Sense Oct 14 '10 at 12:00
  • @fabrik coding standards are for people, not people for coding standards. We are programmers, not soldiers. Don't try to standardize every trifle thing. Try to think of algorithm, not of quotes style. – Your Common Sense Oct 14 '10 at 12:05
  • 1
    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... – Etienne Marais Oct 14 '10 at 12:11
  • @etbal that's a good answer, post it – Pentium10 Oct 14 '10 at 12:45

1 Answers1

0

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.

Etienne Marais
  • 1,660
  • 1
  • 22
  • 40