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
3
votes
2 answers

What are "MySource" and "Squiz" Coding Standards?

After installing Composer in windows 10, the result of phpc -i command is: "The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz and Zend." After lots of searches I was unable to find any documentation about MySource coding…
IT_man2018
  • 53
  • 7
3
votes
1 answer

How to exclude everything except some directories from PHP Code Sniffer inspections in .phpcs.xml?

I would like to exclude everything except some directories from PHP Code Sniffer inspection in my project. Something similar like git repo exclusions with .gitignore I had the idea that regex with negative lookahead could be used with…
kanlukasz
  • 1,103
  • 19
  • 34
3
votes
0 answers

PSR12 Allow newline after closing parenthesis

How can I allow the writing of the bellow code? which rules should I add to my custom ruleset xml? foreach ($mIn as $key => $value) { $mOut -> $key = $mIn -> $key; } currently, PHPCS is issuing a warning stating that a space is expected…
exigez
  • 41
  • 4
3
votes
2 answers

vscode phpcs: referenced sniff Universal.WhiteSpace.DisallowInlineTabs does not exist

I have had a lot of issues setting up phpcs and vscode — they worked perfectly for a while, but then after reorganizing some folders, I moved my wpcs repo somewhere else. Now trying to reconfigure phpcs and cannot figure out what the problem is. I…
Jamie
  • 1,909
  • 3
  • 22
  • 47
3
votes
1 answer

How can I Partially disable PHPCS' PSR-12 declare(strict_types=1) checks?

I currently run php vendor/bin/phpcs --standard=PSR12 src in several of my projects' CI. They have been failing for 6+ months, because my code is organized like:
Theodore R. Smith
  • 21,848
  • 12
  • 65
  • 91
3
votes
1 answer

Can all PHP mess-detecter checks be replaced with PHP code-sniffer checks?

I have a project which uses both PHPMD (PHP Mess Detector) and PHPCS (PHP Code Sniffer) which got me wondering if all PHPMD checks can be replaced with PHPCS checks or is it best to use both in tandem? The list of PHPMD checks seems to be here:…
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
3
votes
1 answer

phpcs — Wordpress coding standard not working in Visual Studio

I get this error in visual studio: phpcs: The "WordPress" coding standard is not installed. Please review your configuration an try again. In settings.json: "php.suggest.basic": true, "php.validate.run": "onSave", …
Jamie
  • 1,909
  • 3
  • 22
  • 47
3
votes
1 answer

phpcs: Referenced sniff "WordPress" does not exist

I've installed phpcs by following this answer, and added the following to my Visual Code settings.json: { "phpcs.enable": true, "phpcs.composerJsonPath": "wp-content/themes/wprig/composer.json", "phpcs.standard": "WordPress", …
Insight
  • 202
  • 3
  • 28
3
votes
1 answer

PHP CodeSniffer Error: The phpcs report contains invalid json

I want to add PHP CodeSniffer to VScode. Within VScode I am getting the error 'phpcs: The phpcs report contains invalid json' However when I run the following command in the terminal: phpcs --standard="WordPress-Core" -q --report=json…
Michelle M.
  • 515
  • 1
  • 7
  • 20
3
votes
2 answers

phpcs - Prevent showing "Opening parenthesis of a multi-line function call must be the last content on the line"

The error occur for this code: $posts = App\Post::whereHas('comments', function (Builder $query) { $query->where('content', 'like', 'foo%'); }); I'm using phpcs vscode and need all of the default rules of phpcs except this one! Could you please…
Ali
  • 185
  • 11
3
votes
2 answers

Ignore or bypass errors phpcs

How to bypass or ignore specific errors/warnings in vscode?, I am using phpcs.
bashman
  • 138
  • 2
  • 11
3
votes
1 answer

WordPress Coding standards precision sniff issue

After updating to the latest wpcs version I'm getting precision alignment warnings in my file. And it's happening for comments for the properties in my class. For instance
dingo_d
  • 11,160
  • 11
  • 73
  • 132
3
votes
0 answers

Report type "json" not known

I'm a beginner to using visual studio code. After I installed phpcs, I got an error: "Report type "json" not known and phpcs: Cannot read property 'length' of null
Army
  • 33
  • 8
3
votes
1 answer

Unable to install PHP CodeSniffer in wamp or xampp in windows 10 system

I am trying to install code sniffer in my localhost but unable to install it. System: Windows 10 PHP: PHP 5.4+ I have tried below methods. Open command prompt with administrative permissions (select “run as administrator “) Go to your php install…
RJParikh
  • 4,096
  • 1
  • 19
  • 36
3
votes
1 answer

WordPress Coding Standards – phpcs Warnings

I'm using the WordPress-Core rules for a project I just started in PhpStorm (involves developing a custom plugin and theme), and I find it strange that most of the default php files in a clean WordPress install (for example, wp-config.php,…
sgr12
  • 1,047
  • 11
  • 13
1 2
3
13 14