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

code quality report is genrated in the artifact section but not in the pipeline section in Gitlab

once pipeline completed the code quality report is generated in the artifact section but not in the pipeline section in Gitlab. anyone suggest what is the issue.& code its worked properly on server. enter image description here once pipeline…
KCA
  • 1
0
votes
0 answers

How to add spaces between the function name and the parenthesis in php-cs-fixer

php cs fixer is formatting the code as follows, by removing space between the function call and the parenthesis - public function __invoke (array $addedValues, array $args, Context $context, ResolveInfo $info) { + public function…
Shobi
  • 10,374
  • 6
  • 46
  • 82
0
votes
0 answers

PHPCS overrule PEAR rule with custom tags

I'm creating a custom rule config for our project and want to use the PEAR rule 'PEAR.Commenting.ClassComment'. But this rule checks more then we need. Like @package and @category. Is there a way to override the protected $tags from the…
0
votes
0 answers

PHPCS not found in command line (after composer install)

I installed PHPCS via composer, and checked the PATH to ensure it exists but it's not being recognized when I run the command. I've used both of the following commands to install and it's still not found after either installation: composer global…
0
votes
0 answers

Create own ruleset for codesniffer PHPCS

I am trying to create my own ruleset for PHPCS extending the WordPress standard. My goal is to define that a opening brace starts as the same line as the function name. public function __construct() { self::$instance = $this; } So…
Ted Logan
  • 404
  • 1
  • 4
  • 15
0
votes
0 answers

How to call php code sniffer in git hook if some developers work in docker in windows(wsl) and some don't?

I have a git hook that looks something like this: PHPCS_BIN=vendor/bin/phpcs ... OUTPUT=$($PHPCS_BIN $STAGED_FILES) RETVAL=$? exit $RETVAL Before many switched to docker, everything was fine, since everyone had php installed on their operating…
Mike
  • 51
  • 2
0
votes
1 answer

phpcs --standard=PHPCompatibility not detecting anything from PHP 8.0+

I am running phpcs with the following command: php -d memory_limit=-1 vendor/bin/phpcs -v -p . --standard=PHPCompatibility --extensions=php --colors --runtime-set testVersion 8.1 However, it is only finding deprecation and errors for PHP 7.4 and…
0
votes
0 answers

PHP-CS and custom rules for multi-line if statements Boolean operator at the beginning of the line

Is there a way to add a custom rule for PHP-CS such that the CI pipeline would fail if the boolean operators are not at the beginning of the line through multi-line if statements? Right: if (isset($someArray['question']) &&…
Mutatos
  • 1,675
  • 4
  • 25
  • 55
0
votes
0 answers

phpcs Standard for "Use of undefined constant"

Does anyone have a phpcs standard "ruleset" to detect stuff like Use of undefined constant foo - assumed 'foo' (this will throw an Error in a future version of PHP) in php? I tried https://github.com/sirbrillig/phpcs-variable-analysis but this did…
Schubi Duah
  • 309
  • 1
  • 7
0
votes
1 answer

PHP Code Sniffer shows warning in PhpStorm but not in CLI

I have a little function in a class: /** * @return float|int */ private function getPrice() { return rand(1000, 1000000) / 10; } In PhpStorm I am getting a warning by phpcs. Missing function's return type declaration But when I am running…
vaso123
  • 12,347
  • 4
  • 34
  • 64
0
votes
1 answer

How to make phpcs find PHP8 errors in whole project directory?

I am inside my project directory that has various files/folders and some have PHP8 fatal errors I have found when using the website (e.g. Fatal error: Uncaught Error: Non-static method), I am using the following command which I am expecting to show…
bigdaveygeorge
  • 947
  • 2
  • 12
  • 32
0
votes
0 answers

grumphp - how to force all files in specific directory to start with uppercase

I'm using grumphp + phpcs and phpstan to enforce a consistent project structure. Is there a way to use the current setup to ensure no developers create lowercase files? Have the rule for class name, but nothing for file name.
zozo
  • 8,230
  • 19
  • 79
  • 134
0
votes
1 answer

php.ini error_reporting option messes with phpcs plugin for vscode

I have a vscode plugin that uses phpcs for linting. I get this error: phpcs: Unknown error ocurred. Please verify that C:\Users\David\AppData\Roaming\Composer\vendor\bin\phpcs --report=json -q --encoding=UTF-8…
Daviid
  • 630
  • 4
  • 17
0
votes
0 answers

phpcs always shows Call stack

Simply running phpcs --version Give this output PHP_CodeSniffer\Exceptions\DeepExitException: PHP_CodeSniffer version 3.7.1 (stable) by Squiz (http://www.squiz.net) in…
Daviid
  • 630
  • 4
  • 17
0
votes
1 answer

phpcs - Why do I get a "useless variable" error on phpcs if the variable it's complaining about is the return value of a method?

I'm using phpcs When using code very similar to this(slightly altered for legal reasons): function methodNameHere($desiredParameter){ $client = new Client([ 'base_uri' => 'confidential uri', ]); $headers = [ …
JB3
  • 15
  • 7