Questions tagged [phpcs]

A component of Php Code Sniffer Package, phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard.

Useful links:

203 questions
92
votes
4 answers

How can I suppress PHPCS warnings using comments?

My TestMyClass.php has two class definitions in the same file (unit testing class), and PHP Code Sniffer complains about each class must be in a file by itself. How can I suppress this warning? class MyClassImpl implements MyInterface { //…
gremo
  • 47,186
  • 75
  • 257
  • 421
35
votes
2 answers

PhpStorm: How to disable PHPCS for Javascript

PHPCS is checking my JS files on PhpStorm, I need to disable this feature I added this line in the file phpcs.xml.dist but no luck *\.(inc|css|js)
unloco
  • 6,928
  • 2
  • 47
  • 58
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
12
votes
3 answers

How to add multiple paths for phpcs?

I want to configure multiple installed paths for phpcs. I can add one via: phpcs --config-set installed_paths the/dir/to/standard I tried adding multiple by using : yet it did not work and the man page is non-existent and the help not that helpful.
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
11
votes
1 answer

phpcs version not specified

I spent hours on Google searching for an answer too this before asking, in phpcs I had this error "PHP version not specified", but I couldn't find an answer on Google, eventually I've just came across this "PHP Version 5" which cleared the error up,…
Have a Laugh
  • 177
  • 1
  • 9
9
votes
1 answer

Resolve this error for Laravel migration file: Each class must be in a namespace of at least one level

How to resolve this phpcs error? It shows up for the class Keyword in all Laravel migrations files. The error message is: Each class must be in a namespace of at least one level (a top-level vendor name) phpcs
Sharath
  • 2,348
  • 8
  • 45
  • 81
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
1 answer

When running phpcs, ERROR: Referenced sniff "PHPCompatibility" does not exist is coming

I want to run phpcs tool, but this error is coming, ERROR: Referenced sniff "PHPCompatibility" does not exist I ran phpcs -i. That gave me , The installed coding standards are PEAR, PSR1, Zend, Squiz, PSR12, PSR2, MySource and PHPCompatibility. But…
Viraj Amarasinghe
  • 911
  • 10
  • 20
8
votes
1 answer

Configure PHP-cs-fixer indentation for 2 spaces rather than 4?

Not sure if this a better question for here or SuperUser. If it belongs there feel free to move it. I'm using php-cs-fixer, and I have a unique requirement on indentations - I need two spaces rather than four. Is there a way to change this…
dluxcru
  • 397
  • 1
  • 5
  • 16
7
votes
2 answers

Can we set up Intelephense in VS Code as per WordPress coding Standard?

I am using PHPCS and PHPCBF for WordPress development in VS Code.( as per instructions mentioned in https://github.com/tommcfarlin/phpcs-wpcs-vscode ) While PHPCBF is formatting the codes as per WPCS, I still feel that the code looks really ugly,…
Dibakash
  • 186
  • 1
  • 1
  • 9
7
votes
3 answers

VScode PHPCS Extension Error: Referenced Sniff "WordPress-Core" does not exist

I want to add PHP CodeSniffer to VScode. Within VScode I am getting the error 'phpcs: Referenced sniff "WordPress-Core" does not exist' However when I run the following command in the terminal: phpcs --standard="WordPress-Core" dropdowns.php PHP…
Michelle M.
  • 515
  • 1
  • 7
  • 20
7
votes
1 answer

How do I fix the following phpcs error in Visual Studio Code?

I am new to VS code. I am trying to work with PHP, but I keep getting this notification. phpcs: Request workspace/configuration failed with message:unable to locate phpcs. please add phpcs to your global path or use composer dependency manager…
Prince Atti
  • 71
  • 1
  • 1
  • 4
6
votes
2 answers

phpcs: Missing parameter comment

I have the following code: /** * @param TranscodingJob $transcodingJob * * @return TranscodingJob * @throws \Lexik\Bundle\WorkflowBundle\Exception\WorkflowException */ public function onTranscodingJobError(TranscodingJob $transcodingJob) {…
6
votes
2 answers

PHPCS different ruleset for different directories

I am currently working on cleaning up an existing codebase and one of the aspects involve using PHPCS. This is my phpcs.xml file at the moment:
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
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
1
2 3
13 14