Questions tagged [phpcodesniffer]

PHP_CodeSniffer is a PHP PEAR package that can be used to tokenise PHP, JavaScript and CSS files and to detect violations of a defined set of coding standards.

PHP_CodeSniffer is a PHP PEAR package that can be used to tokenise PHP, JavaScript and CSS files and to detect violations of a defined set of coding standards. More information can be found here: http://pear.php.net/package/PHP_CodeSniffer/redirected , including documentation and download links.

327 questions
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
0 answers

magento phpcodeniffer exception

When I run codesniffer for magento2 extension by following the doc - https://developer.adobe.com/commerce/php/coding-standards/ From magento root directory I run vendor/bin/phpcbf --standard=Magento2 ./app/code/Test/Module I get the following…
footy
  • 5,803
  • 13
  • 48
  • 96
0
votes
0 answers

Referenced sniff "PHPCSUtils" does not exist

I have PhpStorm and installed "squizlabs/php_codesniffer". When I try to use (e.g. modify the source code), PhpStorm sends me a little error every time, as Referenced sniff "PHPCSUtils" does not exist I tried to get that PHPCSUtils like…
John Smith
  • 6,129
  • 12
  • 68
  • 123
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
0 answers

How to make PHP_Codesniffer complain about array value indentation?

I find it incredibly hard to find the name of PHP_Codesniffer rules I'd like to use. What I want to do right now is to make PHP_Codesniffer complain about array value alignment: $array = [ 'lorem' => 1, 'sit' => 2, // there should only be…
quick-brown-fox
  • 61
  • 1
  • 13
0
votes
1 answer

Why squizlabs/php_codesniffer marked as error code with(new Vote)?

I laravel 9 project with squizlabs/php_codesniffer my phpstorm 2021 shows error : Expected parameter of type '\TValue', 'Vote' provided in model when I use table name in scope condition : class QuizQualityResult extends Model { protected…
mstdmstd
  • 2,195
  • 17
  • 63
  • 140
0
votes
1 answer

Setup PhpStorm's to reformat code based on phpcs (codesniffer-rules from Squizlabs)

I've taken over a code base, where most of the code is following the codesniffer settings from squizlabs/PHP_CodeSniffer. How do I setup PhpStorm to automatically reformat the code upon saving files; so I always follow those standards. Ideally I…
Zeth
  • 2,273
  • 4
  • 43
  • 91
0
votes
0 answers

Find User location without IP

Can I find the user locaion without the help of IP? for example, user will access my website but they have masked/hidden their IP, So is there any other way to find the user location and redirect him to as per there locaion in php? Any help will…
Rajeev
  • 11
  • 2
0
votes
1 answer

Where can I edit the background color of php_codesniffer errors?

Working with PhpStorm 2021, I use squizlabs/php_codesniffer 3.7 and want to change back phpcs warning background color. phpcs has level ="warning"—I suppose that is some common option for all warnings, but where can I edit background color?
mstdmstd
  • 2,195
  • 17
  • 63
  • 140
0
votes
0 answers

Lint rule to prevent html code in php files

I would like to prevent developer to put Html code in php logic to force them to handle presentation layer on template engine. I found the following code in the project and would like to set up a linter that would prevent such code commitment to…
112Legion
  • 1,129
  • 12
  • 25
0
votes
0 answers

Setting up PHP_CodeSniffer in PhpStorm, Custom standard option is not available

I'm having trouble setting up PhpStorm to use PHP_CodeSniffer properly. At first I was running PhpStorm on Windows through WSL2g, where I got to the point of selecting the coding standard in Editor > Inspections > PHP > Quality Tools > PHP…
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

PHP_Codesniffer says "Undefined offset: 2 in /PHP_Codesniffer/src/Files/File.php on line 863"

I am working on an analytics plugin for Shopware to expand the statistics section. Everything works as expected, but when I wanted to commit the code for the controller I got the above mentioned error. I can't seem to find the problem and would be…
mel_p
  • 1
  • 2
0
votes
1 answer

ignoring coding standards with php-cs-fixer?

In php_codesniffer you can ignore coding standards for a block of code thusly: // @codingStandardsIgnoreStart $a = ($b[$c >> 5 ] & 0x0080) & ($b[$c ] & 0x0100) & // here is a multi-line // quote from some…
neubert
  • 15,947
  • 24
  • 120
  • 212