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

Error with ternary operator in PHP code sniffer

I have problem with PHP code sniffer and ternary operator. I added rule for checking spaces after and before operators and now I have errors in short if statements: 37 | ERROR | [x] Expected 1 space…
jager91
  • 272
  • 6
  • 15
2
votes
1 answer

How to get all php member variables with phpcs

I am trying to get a list of class variables using phpcs but can only get a list of all variables in the file. Has anyone got any ideas on achieving this? Sniff Code for ($i = $stackPtr; $i < count ($tokens); $i++) { $variable =…
GrahamL
  • 243
  • 2
  • 15
2
votes
1 answer

phpcs Is there a rule to disallow empty lines?

Is there a rule that I can use with phpcs that limits the number of consecutive empty lines to e.g. 3? I currently use PSR2, which does not take this into consideration at all.
Chris
  • 13,100
  • 23
  • 79
  • 162
2
votes
2 answers

phpcs: detecting old style constructors

I have to work with a very large codebase that has been in continuous development for the last 11 years, with varying maintenance levels. Older code is slightly messy, as one would expect. And there are tons of PHP4 constructors lying around: class…
yivi
  • 42,438
  • 18
  • 116
  • 138
2
votes
1 answer

SublimeLinter: WARNING: phpcs deactivated, cannot locate 'phpcs'

I've got a path problem. I am trying to setup SublimeText3 and WordPress Coding Standards. I'm working width XAMPP on a Mac. My phpcs file is located in /Applications/XAMPP/xamppfiles/PHP_CodeSniffer/scripts/ In the SublimeLinter user settings I put…
user3684098
  • 349
  • 1
  • 3
  • 18
2
votes
1 answer

Sublimetext php-cs-fixer changes namespace to lowercase

While using sublimetext3 in a Laravel project, php-cs-fixer (PHP CS Fixer version 1.12.0) 'fixes' the namespace (App) from Uppercase to lowercase (app). Eg. namespace App\Http\Controllers; to namespace app\Http\Controllers; This causes a Class not…
user573
  • 33
  • 2
2
votes
2 answers

PHP Code Sniffer explanation of rule PEAR.Files.IncludingFile.UseRequireOnce

i'm trying to improve my coding style, so i'm starting to use PHP Code Sniffer to follow standards. Im confused by this rule "PEAR.Files.IncludingFile.UseRequireOnce" what's wrong on include_once? Is it serious violation of standard to suppres this…
ETNyx
  • 180
  • 5
2
votes
2 answers

Disabling notifications in PHP Storm 9

I am using PHPStorm 9. I have installed PHPCS to sniff my code. It is properly configured, up and running. I am working on a very old project, which was implemented in plain PHP, and not using any code standard. As a result, every time I open any…
Nicolas
  • 1,320
  • 2
  • 16
  • 28
1
vote
0 answers

PHPCS disallow dynamic property

I have created a project based on php 7.4. I plan to move to php 8.2. In php 8.2, in a class, it is forbidden to declare properties dynamically. I would like to add a rule to PHPCS that would highlight the places where this happens so I can…
AtyKlaxas
  • 21
  • 3
1
vote
0 answers

How can I configure phpcbf or phpcsfixer in Neovim using null-ls to indent code using 2 spaces?

I have read the documentation from both formatters and have tried different configurations using various coding styles with different arguments with no success. Here's a code snippet of how my configuration currently stands. local present, null_ls =…
1
vote
0 answers

How do I ensure PHPCS takes annotations into account?

PHPCS is reporting for my use statement use Drupal\Core\Entity\EntityStorageException; however later in the same…
Monkeybrain
  • 766
  • 5
  • 23
1
vote
1 answer

Exception when directory does not exist

The issue is that if watching multiple directories via the Finder class. If one does not exist, the Finder will throw an exception and the fixer will die. $finder = Finder::create() ->in([ __DIR__ . '/web/app/mu-plugins/ys-*', …
ruckie
  • 149
  • 14
1
vote
0 answers

PHP Static analysis to detect breaking changes in advance of upgrade

We have a large codebase and it's currently running in production on PHP 7.4. Now we're getting ready to upgrade to PHP 8.1 and so we've been asked to make sure the code is going to work when we upgrade. We have phpcs of course, and this will detect…
Emmet O'Grady
  • 269
  • 2
  • 8
1
vote
0 answers

How to disable "disallowtab" in phpcs inside vscode?

I am using vscode editing legacy php code. The phpcs extensions is great in finding potential problems. However, the old code is using tab instead of 4 spaces for indentation. phpcs would report with: Spaces must be used to indent lines; tabs are…
Nick
  • 8,451
  • 13
  • 57
  • 106
1
vote
0 answers

phpcs works, but output many error with it

In my project i use composer phpcs to test my code style phpcs --standard=PSR12 src/ tests/ and it's work well, all error are outputs. For example: FILE:…
Vadim
  • 11
  • 2