Questions tagged [codesniffer]

This tag is for questions having to do with the PHP_CodeSniffer PEAR package from Squiz Labs, which is used for static analysis of PHP code.

The PHP_CodeSniffer tool is a PHP PEAR package for static analysis of PHP code, developed and maintained by Squiz Labs.

Useful Links

231 questions
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
  • 30,567
  • 12
  • 81
  • 109
53
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,227
  • 4
  • 14
  • 25
41
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,729
  • 14
  • 60
  • 91
28
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,009
  • 4
  • 19
  • 31
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
  • 30,280
  • 40
  • 163
  • 285
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
  • 484
  • 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…
burzum
  • 25,122
  • 8
  • 38
  • 65
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
  • 6,794
  • 7
  • 37
  • 50
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
  • 27,869
  • 13
  • 115
  • 180
14
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,250
  • 2
  • 25
  • 33
13
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
  • 36,948
  • 13
  • 119
  • 141
12
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
  • 41,137
  • 49
  • 170
  • 286
12
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
  • 10,950
  • 17
  • 85
  • 198
12
votes
5 answers

Use PHP_CodeSniffer for modified lines only

I am trying to build a pre-commit script in SVN, and I want to run PHP_CodeSniffer on the modified lines only (as opposed to the whole file). So far I have this script: #!/bin/sh REPOS="$1" TXN="$2" # Make sure that the log message contains some…
Antonio
  • 271
  • 4
  • 12
11
votes
1 answer

What is the right way to install codesniffer to Aptana Studio standalone version?

I followed this guide for eclipse integration on drupal: https://drupal.org/node/1420004 I tried to install PTI plugin to Aptana (Aptana Studio 3, build: 3.4.1.201306062137, with Eclipse Platform Version:…
Phoenix
  • 736
  • 1
  • 6
  • 22
1
2 3
15 16