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

Setting up Visual Studio Code for WordPress PHP 8.1.4 on Windows 10

I need help... I have looked all over and maybe it's just a rookie mistake somewhere, however I feel I have looked and re-looked at every aspect of install on configuration. Error in Visual Studio Code (1.74.0) phpcs: The "WordPress" coding standard…
Robert T
  • 1
  • 2
0
votes
0 answers

PhpStorm, set a custom coding standard

I have a dockerized WSL with PHP code sniffer installed. Now I stuck to set up "wordpress" coding standard. When I run phpcs -i from WSL it then shows The installed coding standards are PSR2, PEAR, PSR12, MySource, Squiz, Zend, PSR1,…
0
votes
1 answer

Find phpcs rule name by its error message

Maintaining some legacy code, phpcs (in Vim, using Syntastic) shows a lot of errors. I'd like to suppress them (for now). I get errors like: participant.php|1 col 1 error| Header blocks must be separated by a single blank line …
klokop
  • 2,414
  • 2
  • 18
  • 22
0
votes
1 answer

Sanitize a $_REQUEST[object] to satisfy the phpcs standards for WordPress?

Is there a way to sanitize a $_REQUEST[object] to satisfy the phpcs standards for WordPress? Below is what I have so far but phpcs still errors on the earliest assignment of the request and I cannot figure out how to sanitize without first…
oooorgle
  • 1
  • 1
0
votes
1 answer

How do I fix code not being ignored by phpcs in VSCode

I'm trying to (temporarily) ignore some errors about not using Nonces. I've tried using // @codingStandardsIgnoreLine. before the line, and I've tried using // phpcs:ignore WordPress.Security.NonceVerification.Missing., I'm still being notified of a…
gillespieza
  • 137
  • 8
0
votes
1 answer

phpcs: How to enforce class inheritance?

I want to make sure all classes in some dir (src/Controller/CP) extend some other class AbstractCPController. So that class SupportTicketTagController extends AbstractController would show PHPCS error, and class SupportTicketTagController extends…
michnovka
  • 2,880
  • 3
  • 26
  • 58
0
votes
0 answers

CodeSniffer not working on PhpStorm/MacOS but it work in Docker

I use PhpStorm 2021.3 on MacOS (Apple Sillicon M1). I'm not sure the problem is with PhpStorm but PHP Code Sniffer doesn't work. When I type this command it doesn't show any errors in the code and I'm sure I got some. vendor/bin/phpcs The only…
pirmax
  • 2,054
  • 8
  • 36
  • 69
0
votes
1 answer

How to change an error to a warning with PHPCS?

I recently started to use PHP_CodeSniffer for WordPress development. I'm now trying to make some of my plugins/themes compliant with the WP Coding Standard. For that, I'd like to change some of the rules temporarily from errors to warnings, so I can…
jost21
  • 1,084
  • 3
  • 15
  • 29
0
votes
1 answer

How to configure GitLab's phpcs-security-audit analyzer?

I am trying to use phpcs-security-audit by including GitLab's SAST template. It generates a report as expected, but the report is filled with warnings from libraries and specific warnings that I would like to ignore for the report to be useful. If I…
August Janse
  • 290
  • 1
  • 6
  • 18
0
votes
0 answers

PHP CodeSniffer start indentation

I am looking into setting up the PHPCS to run at build time and report any issues. Something that I find more readable is a start indentation based on an open PHP tag: But PHPCS seems determined that I need to have something like this: I…
Jovan Perovic
  • 19,846
  • 5
  • 44
  • 85
0
votes
1 answer

Is there a way to break down a namespace in PHP?

I found myself looking on the internet for someone who has already answered it, but I can't find any. I was cleaning up some code with a strict PSR12 standard, and I found this issue with namespace getting longer than the configured 80 characters…
0
votes
0 answers

Gitlab CI exit 1 even if it is successful

I have a step on my gitlabci that runs php code sniff. I used custom base image for this step. This step exit with code 1 and failed the step. I checked this with starting a container with my docker image. phpcs command is working like charm inside…
rmznbyk 1
  • 1,104
  • 2
  • 13
  • 27
0
votes
2 answers

Discouraged Class Usage PHPCS

Let's say I have these classes: Old_Class New_Class If this exists ->something(new Old_Class()) or Old_Class::staticMethod() or $oldClass->methodCall() I want a code sniff to warn "Old_Class usage found, recommend using New_Class instead". I…
Jrow
  • 1,026
  • 2
  • 12
  • 31
0
votes
0 answers

PHP_CodeSniffer returns exit status 1 or 2 in PhpStorm instead of showing warnings about violations

Problem PHP_CodeSniffer runs fine in my console, but gives me problems when I try to use it in PhpStorm. In should give me warnings about violations when I'm working in the editor. Currently it just returns phpcs: exit status 1 and phpcs: exit…
0
votes
1 answer

WordPress: How to autoformat file on save using WordPress Code Standards?

I have installed phpcs vscode extension and configured vscode settings as follows: settings.json: ... "php.suggest.basic": true, "php.validate.executablePath": "/usr/bin/php", "php.validate.run": "onSave", "phpcs.enable":…
xiarnousx
  • 575
  • 6
  • 18