Search code examples
phpphpcodesniffer

PHP Code Sniffer and camel caps


I have just started to use Code Sniffer to clean up my code.

I found out that Code Sniffer catches php's built-in function names as errors. For example:

on line if($mysqli->connect_error === true) { I get a message that:

Variable "connect_error" is not in valid camel caps format.

I have chosen to use the Zend standard as it shows a lot of points for cleaning up and would like to use it in the future.

So the question is - how do you go about this? - ignore these errors - fix php code sniffer to ignore php built-in function names - use another standard? - anything else?

Thanks for your suggestions!

Andrius


Solution

  • This is due to the Zend standard being incomplete and infrequently updated. The Zend standard inside PHP_CodeSniffer is not actually a complete standard at all. It is just a collection of sniffs written (long ago) by some people working at Zend.

    If you'd like to start cleaning up your code, I'd suggest starting with the PEAR or PSR2 standards. PEAR is quite mature while PSR2 is very new, but both will help you get nice clean code. The PEAR standard will help to keep doc comments consistent while PSR2 will not, so keep that in mind. Neither of these will complain about mysqli functions.

    PHP_CodeSniffer also comes with the Squiz standard, but this is very strict. Probably too strict to begin with.

    You can also create your own standard by mixing up parts of all of them, but it's probably best to start with a complete one first so you understand where all the checks are being done.