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
1
vote
0 answers

PHP Mess Detector did not allow private methods with underscore prefix

I tested my code and encountered an error on mess detector. It seems like PHP Mess Detector did not allow private methods to be prefixed with underscore as it did not fulfil mess detector requirements, and stated that the methods shall be named in…
1
vote
1 answer

How to enforce snake_case for properties with PHPCS?

I am trying to find rule which will enforce ONLY properties to be in $snake_case I have this for CamelCase: Is there any full list of these rules and what they do? Cannot find…
michnovka
  • 2,880
  • 3
  • 26
  • 58
1
vote
0 answers

how to disallow arrays with extra whitespaces with php codesniffer ruleset?

I tried couple of sniffs in my phpcs.xml file but couldn't come up with a solution for such cases: $arrays = array("1", 2, 2 , 3 ); // not allowed due to extra whitespaces $arrays = [1 , 2 , 3, 4]; // not allowed $arrays = [1, 2, 3, 4]; //…
mirza
  • 5,685
  • 10
  • 43
  • 73
1
vote
0 answers

vs code phpcs only works sometimes

Sometimes I open a php file in VS Code and no linting occurs until I open the linting console from the bottom, switch over to the terminal pane where a dialog shows up that asks me if I trust the authors of this workspace. If I say yes then linting…
ubsd
  • 35
  • 6
1
vote
1 answer

PHPCS requires a license but my code is closed source

After doing some digging online there doesn't seem to be an immediate answer to this. I am writing code for a closed source application and when running PHPCS its informing me that an @license tag is required in order to conform to PSR standards. I…
Xenology
  • 2,357
  • 2
  • 21
  • 39
1
vote
3 answers

ERROR: the "PHPCompatibility" coding standard is not installed

When I execute git commit, I get this error: ERROR: the "PHPCompatibility" coding standard is not installed. The installed coding standards are MySource, PEAR, Zend, PSR2, PSR1, Squiz, PSR12, Drupal and DrupalPractice Fix the PHPCompatibility error…
River Zhao
  • 73
  • 2
  • 8
1
vote
1 answer

Phpcs is not reported on PhpStorm interface

I'm trying to configure PHP Code Sniffer on my project, and I would like to see the error/warnings directly on the editor - like any other error, warnings. I installed the package in composer squizlabs/php_codesniffer and configured the remote…
Mistre83
  • 2,677
  • 6
  • 40
  • 77
1
vote
0 answers

phpcs --standard=PHPCompatibility not detecting error

I am trying to check for errors via phpcs and PHPCompatibility standard on a laravel project, here is the command: phpcs -psvw app --extensions=php --standard=PHPCompatibility --runtime-set testVersion 8.0 The command works fine. However, I am…
dev0010
  • 95
  • 1
  • 5
1
vote
2 answers

How do I prevent PHP CS Fixer from fixing specific function names?

When using PHP CS Fixer to resolve syntax errors on file save and using the Symfony rule set, any function names that are not camelCase will be corrected (as expected). However when writing PHP Unit based tests, it's often common practice to make…
Joe
  • 13
  • 4
1
vote
1 answer

phpcs can not find php in Visual Studio Code

I have a question about Visual Studio Code and phpcs extension. I'm working in Ubuntu and I run in to problem, that VSCode could not start phpcs. It throws error: "/usr/bin/env: 'php': No such file or directory". I tried to run "vendor/bin/phpcs…
DMG
  • 131
  • 1
  • 5
1
vote
0 answers

phpcs: Request workspace/configuration failed with message:unable to locate phpcs

phpcs: Request workspace/configuration failed with message:unable to locate phpcs. please add phpcs to your global path or use composer dependency manager to install it in your project locally.
1
vote
1 answer

Fixing function multiline arguments to a certain structure using phpcs or php-cs-fixer

I'm working on a project which developed many developers for many years, and as it often happens there is no coding standard. There are many code blocks which in general is similar but written in a different way. For example: return…
Serhii Popov
  • 3,326
  • 2
  • 25
  • 36
1
vote
1 answer

WP Rig: Error running npm run build: Cannot find "/vendor/bin/phpcs"

I've installed WP Rig on a Windows development machine running WAMPserver. I get to Step 5 at the URL above where I need to run npm run build, and then I receive an error: Finished 'images' after 1.91 s [16:34:30] 'php' errored after 5.92…
Insight
  • 202
  • 3
  • 28
1
vote
1 answer

How to install PHP_CodeSniffer in macOSx?

I tried to install phpcs in the macOS Catalina but I was getting multiple errors. So in my answer, I shared the steps to install phpcs easily.
Arti Singh
  • 906
  • 1
  • 6
  • 21
1
vote
1 answer

PHP Easy Coding Standard (ECS) - suppress phpcs warnings

ECS = symplify/easy-coding-standard I am getting an message when running ECS: Unused variable $validator. (SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff.UnusedVariable) For this code: // phpcs:ignore //…
simpleman
  • 205
  • 1
  • 2
  • 7