Questions tagged [phpcodesniffer]

PHP_CodeSniffer is a PHP PEAR package that can be used to tokenise PHP, JavaScript and CSS files and to detect violations of a defined set of coding standards.

PHP_CodeSniffer is a PHP PEAR package that can be used to tokenise PHP, JavaScript and CSS files and to detect violations of a defined set of coding standards. More information can be found here: http://pear.php.net/package/PHP_CodeSniffer/redirected , including documentation and download links.

327 questions
57
votes
3 answers

Ignore code snippets in PHP_CodeSniffer

It is possible to ignore some parts of code from a php file when it's analyzed by PHP_CodeSniffer?
Madalina
  • 1,297
  • 6
  • 15
  • 25
54
votes
8 answers

How useful is PHP CodeSniffer? Code Standards Enforcement in General?

I'm dabbling with the idea of setting up PHP CodeSniffer on our continuous integration server in an effort to improve the quality of our code-base. After reading the documentation I'm very excited about the idea of normalizing and enforcing our…
Mike B
  • 31,886
  • 13
  • 87
  • 111
47
votes
4 answers

How to Ignore Line Length PHP_CodeSniffer

I have been using PHP_CodeSniffer with jenkins, my build.xml was configured for phpcs as below
dextervip
  • 4,999
  • 16
  • 65
  • 93
35
votes
4 answers

Add an empty line at end of file according to PSR-2 on PhpStorm

I use PSR-2 for code styling my code. When I inspect a file using Codesniffer most of the times I get the following error. 332 | ERROR | [x] Expected 1 newline at end of file; 0 found It's obvious how to fix this. What I need to know is if…
gmponos
  • 2,157
  • 4
  • 22
  • 33
21
votes
3 answers

Is there a PHPCS standard targeting PHP docblocks?

Is there a PHPCS coding standard that would check that proper annotations (@param, @return, @throws, etc.) are present in a docblock, including the proper spacing between them?
BenMorel
  • 34,448
  • 50
  • 182
  • 322
18
votes
11 answers

PHP CodeSniffer include_once error

I'm trying to install PHP CodeSniffer on OS X Mountain Lion - and I appear to be getting a strange problem When running 'phpcs' I get the following error: PHP Warning: include_once(PHP/CodeSniffer/CLI.php): failed to open stream: No such file or…
thatdamnqa
  • 494
  • 1
  • 4
  • 12
17
votes
2 answers

phpcs: How can I modify PSR2 to check that the brace is on the same line as the method?

I've spent now over 2h on trying to figure out how to require the { in the same line as the method declaration instead of the default requirement being the next line. How can I get this done? I've copied the PSR2 standard to a new folder named PSR2…
floriank
  • 25,546
  • 9
  • 42
  • 66
16
votes
1 answer

PHP_CodeSniffer - Show Sniff that failed

Is there a setting in the PHP_CodeSniffer to show the sniff that failed? I am comparing the output to our coding standards, and using one by one is tough to decipher which test is failing, to see which we may want to ignore. If there was a simple…
Steven Scott
  • 10,234
  • 9
  • 69
  • 117
15
votes
1 answer

How to call a custom ruleset.xml for php code sniffer

I'm trying to write an custom ruleset.xml for php code sniffer but calling it from the commandline without putting it in the default folder doesn't seem to work. Since the documentations seems to state otherwise i'd like to ask if i'm doing…
edorian
  • 38,542
  • 15
  • 125
  • 143
15
votes
2 answers

What's a good standard to use with PHP_CodeSniffer?

My codebase adheres (or should) to the Zend Coding Standard. I've been using the Zend standard with PHP_CodeSniffer, but I see discussion saying the Zend standard for phpcs is inconsistent and unmaintained and doesn't necessarily stick to the Zend…
Brian Kendig
  • 2,452
  • 2
  • 26
  • 36
15
votes
2 answers

Dependencies graph for large PHP application

I've recently inherited a large PHP application with NO objects/modules/namespaces...only a lot of files containing functions. Of course, there is a LOT of dependencies (and all files and almost always included). I'm looking for a tool that could…
Loïc Février
  • 7,540
  • 8
  • 39
  • 51
14
votes
10 answers

Git: pre-receive hook with PHP_CodeSniffer

Since switching from SVN to Git, we lost the ability to enforce our coding standards through a pre-commit hook on the subversion server. With Git, you only have pre-commit hooks on the client which cannot be enforced in any way. What makes it worse…
cweiske
  • 30,033
  • 14
  • 133
  • 194
14
votes
1 answer

How to override a rule/sniff in a PHP CodeSniffer ruleset correctly and to avoid doublechecking of code?

I've extended a class of the PSR-2 sniff set. Now the checks are executed two times -- even if my chid class is empty. Why? And how to do it correctly? EDIT: I have an idea now why: Probably the Sniffer processes the rulesets bottom-up -- from the…
automatix
  • 14,018
  • 26
  • 105
  • 230
13
votes
1 answer

Missing file doc comment?

I used drupal coder module to check my code and always get missing file doc as an error. I used the following file doc comment but still showing error. Can you please guide me what am i doing wrong. Edit:
Versha Gupta
  • 265
  • 2
  • 3
  • 10
13
votes
2 answers

What are the main differences between the PSR-2 coding standard and the Symfony2 code standard for phpcs?

I am trying to figure out which code style to enforce with the phpcs code sniffer. Since the popularity of Symfony2, it seems to be a good practice to use its code standard. On the other hand, its code style is based upon PSR2, so this seems to be…
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
1
2 3
21 22