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

How to config phpcs.xml to accept acronym with the CamelCaps rule?

I have the following error when I "phpcs" my code : 223 | ERROR | Method name "Query::MySQLQueryBuilder" is not in camel | | caps format | | (PSR1.Methods.CamelCapsMethodName.NotCamelCaps) I would not to exclude the rule but…
Amina
  • 46
  • 4
1
vote
1 answer

How to ignore PHP_CodeSniffer warnings

I was wondering if there is some way to ignore warning generated by PHP_CodeSniffer which refer to Eloquent mappings. For example: /** * @param User $user * @param string $message * @param string $type * @return Comment * @throws Exception …
ka_lin
  • 9,329
  • 6
  • 35
  • 56
1
vote
1 answer

PHPCS ignoring too many indentations

I have updated my phpcs rules in my phpcs.xml to include: which works perfectly, however if I were to…
Jamie
  • 1,909
  • 3
  • 22
  • 47
1
vote
1 answer

How to remove silencing errors is descouraged error from magento 2?

I have written code for SSO in magento 2.3 and for handling response from differnt IDPs like okta, keycloak I have done following code: if(!(@$xpath->query('/saml2p:Response',$xml))) { $status = SAML2Utilities::xpQuery($xml,…
Mansi
  • 25
  • 9
1
vote
0 answers

Php cs fixer new line after array brace

We have simple array like this return ['env' => 'release', 'mode' => 'normal', 'theme' => 'basic', 'redis' => require __DIR__.'/redis.php', ]; How to add new line after(blank line) after array brace example return [ // new line after brace …
Alma Z
  • 244
  • 2
  • 10
1
vote
0 answers

With phpcs for VSCode, how can I change the font color of an error based on the ruleset it violated?

I am using PHP Code Sniffer (phpcs) for VSCode. It contains a set of PHP coding rules, and when it detects a violation of one of these rules, it displays those errors in VSCode. These errors are separate to the PHP coding errors detected and…
cag8f
  • 817
  • 1
  • 10
  • 33
1
vote
0 answers

Visual Studio WordPress coding standards

I have got phpcs installed in Visual Studio Code, and I have got the following lines in file settings.json: { // PHPCS "phpcs.enable": true, "phpcs.standard": "WordPress", } This seems to have installed correctly and if I have the…
ascsoftw
  • 3,466
  • 2
  • 15
  • 23
1
vote
1 answer

PHPCS - Enforce class name case when instantiating

I'm using PHPCS to check my class name are valid with the rule PEAR.NamingConventions.ValidClassName It works fine on class declaration: class My_Class {} // Valid class My_class {} // Invalid - expected behaviour Is there any rule to check class…
Tdy
  • 863
  • 12
  • 28
1
vote
1 answer

Closing parenthesis of a multi-line function call must be on a line by itself

I am getting this message from phpcs. my code is: $userdata["expirydate"] = date("Y-m-d H:i:s", mktime(date("H"), date( "i"), date("s"), date("m"), date("d") - 1, date("y")));
Hemant
  • 133
  • 1
  • 3
  • 9
1
vote
1 answer

How to exclude specific rule in a custom phpcs.xml ruleset?

I am looking for a way to automate coding standards and I've decided to use SlevomatCodingStandard.TypeHints.TypeHintDeclaration in our phpcs.xml file. Unfortunately we have faced with an issue with the error reporting: 38 | ERROR | [ ] @var…
mirza
  • 5,685
  • 10
  • 43
  • 73
1
vote
2 answers

Phpcs svg escape function wordpress

i'll try to be quick in my question ! My problem is that i use the svg icons system as the tweentyseventeen default theme ! but when i use echo get_svg() function. phpcs give me a warning that all output need to be escaped with escaping function…
1
vote
0 answers

Disable squiz.commenting.functioncomment.missing phpcs sniff only for inherited methods

The project that I am currently working on has the following coding standard. Don't add phpdoc to inherited methods if it is just a copy of the parent class method's phpdoc. Add phpdoc to inherited methods only if it is different. I am trying…
Sudar
  • 18,954
  • 30
  • 85
  • 131
1
vote
0 answers

phpcs only on git blame value

I work in a project with lots of other developers and the norm is that we only lint and format our own code, not legacy. I'm trying to find a way to run phpcs on only my code or code that I am the git blame value, is this possible? I've been…
grmdgs
  • 585
  • 6
  • 17
1
vote
1 answer

PHP CodeSniffer custom ruleset for multiline function declaration

I was trying to configure phpcs to use two spaces indentation everywhere instead of 4 but i am stuck at one place, i cannot override rule for multiline function declartion my code is if (!function_exists('errorlog')) { function errorlog( …
Amit Bisht
  • 329
  • 3
  • 15
1
vote
1 answer

PHP Code Sniffer - rule updates and tweaking for spaces and underscores

Before I start, I really don't want this to turn into a "change your coding style" post, but rather how I can use PHP Code Sniffer to "lint" our current coding standards. Thanks :) There are two rules which, due to legacy and personal coding styles,…
mikestreety
  • 833
  • 6
  • 28