FAQ – Foire aux questions

Est-ce que PHP_CodeSniffer effectue une évaluation de couverture de code ou de tests unitaires?

Non. PHP_CodeSniffer n'est pas un outil pour tester si votre application PHP fonctionne correctement. Tout ce que PHP_CodeSniffer est censé faire c'est s'assurer que le code PHP respecte les règles du standard de code que vous avez choisi.

Mon code fonctionne ! Pourquoi aurai-je besoin de PHP_CodeSniffer?

Maybe you don't, but if you want to ensure you adhere to a set of coding standards, PHP_CodeSniffer is a quick and easy way to do that. PHP_CodeSniffer is a replacement for the more manual task of checking coding standards in code reviews. With PHP_CodeSniffer, you can reserve code reviews for the checking of code correctness.

Coding standards are a good thing. They will make your code easier to read and maintain, especially when multiple developers are working on the same application. Consider using coding standards if you don't already.

Does PHP_CodeSniffer parse my code to ensure it will execute?

Non. PHP_CodeSniffer does not actually parse your code, and so cannot tell if your code contains parse errors. PHP_CodeSniffer may return an incorrect number of errors if checking code that does contain parse errors.

You can easily check for parse errors in a file using the PHP command line interface and the -l (lowercase L) option.

$ php -l /path/to/code/myfile.inc
No syntax errors detected in /path/to/code/myfile.inc

Je n'adhère pas avec votre standard de codage! Puis-je donner mes règles à PHP_CodeSniffer ?

Oui. At its core, PHP_CodeSniffer is just a framework for enforcing coding standards. Nous fournissons PHP_CodeSniffer avec une série d'exemple de standards de code pour aider les développeurs à démarrer sur des projets pour lesquels ils n'ont pas encore choisi de standard. Si vous voulez écrire votre propre standard, liser le tutorial pour créér un standard de codage.

How come PHP_CodeSniffer reported errors, I fixed them, now I get even more?

Sometimes, errors mask the existence of other errors, or new errors are created as you fix others. Par eFor example, PHP_CodeSniffer might tell you that an inline IF statement needs to be defined with braces. Once you make this change, PHP_CodeSniffer may report that the braces you added are not correctly aligned.

Always run PHP_CodeSniffer until you get a passing result. Once you've made the changes PHP_CodeSniffer recommends, run PHP_CodeSniffer again to ensure no new errors have been added.

Pourquoi ne pas faire en sorte que PHP_CodeSniffer effectue directement les changement plutot que de me les suggerer ?

As much as we trust PHP_CodeSniffer to check your code for coding standard errors, we don't trust any application to ever change code for us without reviewing it first. Considering we would have to check each change PHP_CodeSniffer made before releasing the source code, why not make the changes manually?

Faire les modification à la main garanti que é choses positives se passent:

  • Les développeurs apprenent les règles et font moins d'erreurs à l'avenir.

  • Les développeurs peuvent garantir que PHP_CodeSniffer fonctionne correctement.

  • Les développeurs peuvent décider si une règles se ne s'applique pas à une partie du code.

So if you find yourself wishing PHP_CodeSniffer would just go ahead and make those changes for you, maybe you just need to read the coding standards and adhere to them a bit better.

No matter how small of a change you make, always test your code before committing it to your code repository or releasing it. Even changes suggested by PHP_CodeSniffer need to be tested, as small and insignificant as they may seem.

What does PHP_CodeSniffer use to tokenize my PHP code?

PHP_CodeSniffer uses PHP's inbuilt tokenizer functions to parse your PHP code.

How to configure the Subversion pre-commit hook (Previous) PHP_Compat (Next)
Last updated: Sun, 29 Aug 2010 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.