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
8
votes
1 answer

PHP CodeSniffer: ERROR: The specified sniff code "Generic.Files.LineEndings.InvalidEOLChar" is invalid

My attempt to exclude the check for the EOL char on my Windows machine always results in this error message: >vendor\bin\phpcs.bat --standard=PSR2 --exclude=Generic.Files.LineEndings.InvalidEOLChar src\version.php ERROR: The specified sniff code…
Tobias Uhmann
  • 2,757
  • 2
  • 25
  • 35
8
votes
3 answers

How to detect dynamic declarated fields on objects with codesniffer in PHP

After a refactoring, we had something like this in one of our classes: class FooBar { // $foo was $bla before private $foo; public function setBlubbOnArrayOnlyOnce($value) { // $this->bla was forgotten during refactoring.…
Kasihasi
  • 1,062
  • 1
  • 8
  • 20
8
votes
4 answers

Git pre-receive hook to launch PHP CodeSniffer

I'd like to check code committed to my remote git repository with PHP CodeSniffer and reject it if there are any problems code standards. Does anyone have an example how to use it on git remote repository or maybe example how to use it with…
rzajac
  • 1,591
  • 2
  • 18
  • 37
8
votes
2 answers

Xdebug triggered by Code Sniffer in PHPStorm

I have both xdebug and Code Sniffer working great on my installation of PHPStorm, but the one really annoying part is that the debugger now seems to be treating Code Sniffer errors as breakpoints and interrupts the code to let me know of style…
osdiab
  • 1,972
  • 3
  • 26
  • 37
7
votes
1 answer

How to configure PHP CodeSniffer to allow my case statements to be indented the way I like?

I have code that looks like this: function processRequest() { // get the verb $method = strtolower($_SERVER['REQUEST_METHOD']); switch ($method) { case 'get': handleGet(); break; case 'post': handlePost(); //…
Cheeso
  • 189,189
  • 101
  • 473
  • 713
6
votes
2 answers

codesniffer using pear standard ignore line indent

using codesniffer with pear standard. I got over 20tsd errors cause of line indents. I use tab-stops for indenting. I try to disable that check but I failed. I removed the last rule from the generic standards in the ruleset.xml for the pear…
steros
  • 1,794
  • 2
  • 26
  • 60
6
votes
3 answers

How to create PHP-UnitTest case for PHP_Codesniffer standards?`

I have created my own codesniffer rules standards.They are working fine. Now I want to test codesniffer rules using PHP UnitTest. PhpCodesniffer has already have their framework for PHPUnit test case. So using that I have extended their…
Gaurav
  • 83
  • 1
  • 8
6
votes
1 answer

How to I display results of phpcs in VIM?

I am presently trying to use PHP Codesniffer (PEAR) in vim for PHP Files. I have found 2 sites that give code to add into the $HOME/.vim/plugin/phpcs.vim file. I have added the code and I "think" it is working, but I cannot see the results, I only…
Matt
  • 586
  • 1
  • 5
  • 10
6
votes
1 answer

PHP CodeSniffer ignore/exclude underscore rule in methods

When running phpcs, I am getting an error of Protected member variable "myMethod" must contain a leading underscore. How do I exclude/ignore this error on the ruleset.xml? The PSR-2 coding…
basagabi
  • 4,900
  • 6
  • 38
  • 84
6
votes
2 answers

Use PSR-2 with exceptions in PHP CodeSniffer

I'm attempting to set up a ruleset for PHP CodeSniffer to enforce code style among a group of developers but I've run into some trouble. We'd like to adhere to PSR-2 except for regarding two things. We want class declarations to have the open brace…
FighterHayabusa
  • 321
  • 1
  • 3
  • 12
6
votes
1 answer

PHPCS Limit to Filetype

I'm trying to create a custom ruleset for a particular frameworks "guidelines". However, I want to be able to limit sniffs to only be relevant to a .php or .phtml filetype. Is this possible within to have Sniffs to only use or ignore a defined…
Adam Paterson
  • 412
  • 2
  • 11
6
votes
1 answer

Sniffer Snippet to allow brackets on new line

Is there a codesniffer snippet which allows/forces { } to be put on newlines for every function/method? Basically, forcing something like this: if (TRUE) { // Code logic } else { // Code Logic } And public function test() { // Code…
ThomasVdBerge
  • 7,483
  • 4
  • 44
  • 62
6
votes
1 answer

Can I override the used phpcs ruleset per file if so, how?

Recently we migrated to git and implemented (for now post) receive hooks on our central server to send reports to developers, as well as making several tools enabling us to have our codestandard checked automagically with phpcs on our development…
sg3s
  • 9,411
  • 3
  • 36
  • 52
6
votes
4 answers

Why aren't CodeSniffer excluding the --ignore specified folders?

I'm using Jenkins(Hudson) CI, and every night analysing the code using a number of tools for repporting, including Codesniffer for Checkstyle reports. I wan't it to ignore the ./framework/* directory, but it insists on including it, regardless of my…
Julian
  • 1,050
  • 1
  • 12
  • 23
6
votes
2 answers

PHPCS not running on the command line?

When I type in phpcs --version, instead of getting the version number, I get something like this: /Applications/drupal/php/bin/phpcs: line 2: ?php: No such file or directory /Applications/drupal/php/bin/phpcs: line 3: /Applications: is a…
Pattie Reaves
  • 175
  • 1
  • 3
  • 11
1 2
3
21 22