Question

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

Was it helpful?

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.

OTHER TIPS

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?

Great question.

Beware of ignoring errors, usually you'll also ignore something you do want to know about.

My recommendation is that before you ignore any error reporting you sift through the Code Sniffer documentation a bit more and see if you can find a setting for this.

Also, remember that just because an error message says one thing, it may not necessarily mean what it says. For example, when you get an error like "Unexpected string", that usually means that you forgot a ; or something. So, take a look at your code to confirm there aren't any syntax errors. (i.e. @DavidHoude made a good point: "$mysqli>connect_error === true" could require a -> rather than a >)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top