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

How to lint Namespace based on folder's name?

I know PHP CS Fixer and Psalm to lint PHP. I've been using both of them. But I can't find a way to lint / validate my namespace name based on the folder. For example, in folder Tests/Controllers/V1, I have MyControllerTest.php, and it has the…
rhzs
  • 516
  • 7
  • 24
2
votes
2 answers

Is there a rule for enforcing strict comparison (===) using PHP Code Sniffer?

As title says. I am looking for a rule similar to eslint's eqeqeq, but for PHP. I would want to enforce the use of ===/!== instead of ==/!=. I have tried googling and searched through their repo as well, but unfortunately to no avail. Just wanna ask…
carestad
  • 3,196
  • 2
  • 13
  • 10
2
votes
0 answers

VSCode Unable to locate phpcs on macOS

I know this has been asked many times but I can't find an answer that works for me. I'm on a Mac running macOS 10.15.6 and I'm getting the issue of Unable to locate phpcs in VSCode version 1.47.3. The actual error is: phpcs: Unable to locate phpcs.…
Mat Teague
  • 147
  • 2
  • 3
  • 11
2
votes
2 answers

Error: Class 'path' Is not compliant with PSR-4 configuration

I am trying PHP coding standard package: https://github.com/inpsyde/php-coding-standards, but when I start running phpcs, I get: nickan@nickan-VirtualBox:~/src/wordpress/wp-content/plugins/my-plugin$ vendor/bin/phpcs ./src/model/Users.php E 1 / 1…
Nickan
  • 313
  • 2
  • 11
2
votes
1 answer

New line on function argument list while using php-cs-fixer and PHPCodeSniffer

We are using both php-cs-fixer and PHPCodeSniffer tools for our coding standards. Both can be conflicted when having different rules. We were able to get a balanced result except for one rule. Warning thrown by PHP Code Sniffer : phpcs: Opening…
wlarcheveque
  • 894
  • 1
  • 10
  • 28
2
votes
1 answer

phpcs WordPress ruleset error Detected usage of a non-sanitized input variable: $_FILES

I have a function of a file uploading. While uploading a file when I run the PHP_CodeSniffer phpcs I am getting the error. I am running WordPress ruleset. Detected usage of a non-sanitized input variable: $_FILES $fext = $file =…
2
votes
1 answer

PhpStorm is throwing an error if running phpcs

First of all, let me list some versions so you know the setup. OS: Windows 10 php: 7.2.7 NTS with xDebug 2.6.1 active PhpStorm: 2016.2.2 PHP_CodeSniffer: version 3.4.0 (stable) by Squiz (http://www.squiz.net) PEAR: 1.10.7 Now let me describe the…
Xanatos
  • 395
  • 2
  • 11
2
votes
1 answer

PHPCS cannot be set to PSR2 by default

I'm trying to set up PHPCS to run with PSR2 by default instead of having to specify it on each run. I set the default with phpcs --config-set standard PSR2 When I check the configuration, it appears to be set: $ phpcs --config-show Using config…
user984869
  • 432
  • 2
  • 8
2
votes
1 answer

Inspect Subdirectories of an Excluded Folder with PHP CodeSniffer

I am attempting to configure my phpcs.xml (PHP CodeSniffer configuration file) so that I can exclude all directories from inspection within a folder except for those that I specify. For those familiar with .gitignore, an equivalent would be…
Phil Birnie
  • 1,104
  • 2
  • 12
  • 29
2
votes
0 answers

The grumphp precommit does not detect any errors

I cannot get grumphp to work in a subdirectory. My directory structure is below : /api/grumphp.yml /api/composer.json /api/src/ grumphp.yml contents: parameters: git_dir: ../. bin_dir: vendor/bin ascii: failed: ~ …
2
votes
2 answers

Custom phpcs ruleset is not respecting exclude-pattern declaration

I have a custom phpcs ruleset file, where I am including a couple of rulesets and also excluded files from certain directories like tests or vendor. The full phpcs.xml config file is at https://github.com/sudar/bulk-move/blob/master/phpcs.xml Below…
Sudar
  • 18,954
  • 30
  • 85
  • 131
2
votes
2 answers

PHP coding standards - Visual Studio code

I'm trying to implement other coding standards for phpcs. Currently, I have setup phpcs for visual studio code and I have the following coding standards current/path> phpcs -i The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz and…
AashikP
  • 43
  • 1
  • 6
2
votes
1 answer

Static analysis - SonarQube to test same standards as on Git pre-commit hook

We are running static analysis tests on two points: On Git pre-commit hook, and in that case we are using phpcs, phpmd, stylelint and eslint engines (vanilla installations + Drupal Coder for Drupal standards addition) Once in a week we are updating…
Rotem
  • 442
  • 1
  • 8
  • 23
2
votes
1 answer

PHPCS - Sniffs to enforce new lines after closures and before returns?

We're running various sniffs to help consistency, along with using eslint - so we're trying to unify some rules. we can do this in eslint but cant figure out how to do it in phpcs. New line after closures e.g tap(function () { return…
owenmelbz
  • 6,180
  • 16
  • 63
  • 113
2
votes
1 answer

Finding PHP CodeSniffer rules

How do I find the PHP CodeSniffer rules that I need? For example I would like function arguments and arrays to not be spaced like this function asd( $var, $var2 = '' ) { $array = [ $arg, $arg2 ]; } Instead it should be like this: function…
user1340531
  • 720
  • 1
  • 10
  • 21