203 questions
2
votes
0
answers
47
views
CodeSniffer rules override each other
I have those rules:
<rule ref="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces">
<include-pattern>/src\/Module\/Quotes\/Adapter\/Incoming/</include-pattern&...
1
vote
1
answer
70
views
PHPCS Warning: Incorrect number of replacements in $wpdb->prepare() with dynamic IN clause
I'm working on a WordPress plugin and keep getting a PHPCS warning that I can't seem to resolve. The warning is:
WARNING WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
Incorrect number ...
2
votes
1
answer
50
views
How to disable PSR12 statement bracket in same line?
I am currently working on a standard formatting configuration for my PHP project. I want to use the PSR-12 rules, but I prefer to disable the rule that forces the opening curly brace to be on the same ...
0
votes
1
answer
45
views
phpcbf snif fails with this error "$stackPtr is not a class member var"
squizlabs/php_codesniffer/bin/phpcbf fails with this error:
php vendor/squizlabs/php_codesniffer/bin/phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml ...
0
votes
1
answer
53
views
Can't run phpcbf, tries to open in vscode
If I try to run phpcbf --version vscode opens and shows
The editor could not be opened due to an unexpected error: Unable to resolve resource phar://c:/PHP_Tools/phpcbf/src/Config.php
(Sometimes it's ...
2
votes
3
answers
162
views
phpcbf: Automatically fix Generic.PHP.RequireStrictTypes.MissingDeclaration rule?
I've managed to enforce strict types, but now I need to declare them in every file.
phpcbf says it has 0 fixable issues upon running.
Is there a way to automatically add declare(strict_types = 1); to ...
0
votes
0
answers
98
views
How to Enforce Correct Method Chaining Style in PHP?
I'm looking to enforce a specific method chaining style in PHP, particularly to differentiate between what I consider the 'wrong' and 'good' styles. Is there a tool or method that can help check and ...
0
votes
3
answers
328
views
Very simple simple custom phpcs (phpcbf) fixing sniff fails
I am attempting to write a little simple phpcs (phpcbf) sniff to remove whitespace within empty curly braces. I've written quite a few small fixers, and this seemed like it should be very easy.
...
-1
votes
1
answer
54
views
PHPCS Update doesn't show up
I'm at a loss, I hope someone can explain what I'm doing wrong:
I'm working on macOS (10.15.7). I tried to update PHPCS via Composer:
composer global require "squizlabs/php_codesniffer=*"
...
0
votes
0
answers
84
views
sanitize_post_field() not accepting by PHPCS why?
$template_html = sanitize_post_field('template_content_html',$_POST['template_content_html'], $post_id, 'db' );
I'm saving some HTML in post meta but i don't want lose any html while sanitizing but ...
0
votes
1
answer
98
views
How can I prevent phpcs from scanning docblock / comments?
I am using (among others) the following PHPCS sniff:
Squiz.WhiteSpace.SuperfluousWhitespace.EndLine
But I find it frustrating that end-of-line white space within docblocks is getting flagged. Is there ...
4
votes
0
answers
150
views
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 ...
0
votes
1
answer
790
views
Cannot install friendsofphp/php-cs-fixer on Symfony 5.4 and PHP 8.2
I'm on a symfony 5.4 installation with PHP 8.2 and I'm trying to require friendsofphp/php-cs-fixer with
composer require friendsofphp/php-cs-fixer -W --dev
Unfortunately I'm getting the following ...
0
votes
0
answers
181
views
Liniting deprecated wp function over version 4.9.0 phpcs vscode
in my current project i'm using the following configuration
composer.json:
"require-dev": {
"php": "^7.4 || ^8.0",
"dealerdirect/phpcodesniffer-composer-...
1
vote
1
answer
1k
views
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 ...
0
votes
1
answer
1k
views
Laravel Pint formatting issue with line breaks in comments
I'm using Laravel Pint for code styling in my Laravel project. I have a function with a multi-line comment block that includes various tags such as @description, @author, and @email. When I run ...
0
votes
0
answers
586
views
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, ...
0
votes
0
answers
42
views
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 ...
0
votes
1
answer
226
views
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(...
3
votes
1
answer
2k
views
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 ...
2
votes
1
answer
138
views
How do I ensure PHPCS takes annotations into account?
PHPCS is reporting
<error line="5" column="1" severity="warning" message="Unused use statement" source="Drupal.Classes.UnusedUseStatement.UnusedUse&...
0
votes
1
answer
337
views
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 ...
0
votes
1
answer
259
views
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 ...
0
votes
1
answer
302
views
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 --...
0
votes
1
answer
266
views
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' => '...
0
votes
0
answers
359
views
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 ...
1
vote
1
answer
647
views
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([
...
1
vote
0
answers
573
views
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 ...
1
vote
0
answers
214
views
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:
...
0
votes
2
answers
798
views
Find phpcs rule name by its error message
Maintaining some legacy code, phpcs (in Vim, using ALE) 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 ...
0
votes
1
answer
295
views
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 ...
0
votes
1
answer
700
views
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....
1
vote
0
answers
754
views
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: /home/user/PhpstormProjects/php-vadzim-...
1
vote
0
answers
295
views
PHP Mess Detector did not allow private methods with underscore prefix
I tested my code and encountered an error on mess detector. It seems like PHP Mess Detector did not allow private methods to be prefixed with underscore as it did not fulfil mess detector requirements,...
0
votes
1
answer
170
views
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 ...
2
votes
1
answer
993
views
How to enforce snake_case for properties with PHPCS?
I am trying to find rule which will enforce ONLY properties to be in $snake_case
I have this for CamelCase:
<rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"/>
Is ...
1
vote
0
answers
240
views
how to disallow arrays with extra whitespaces with php codesniffer ruleset?
I tried couple of sniffs in my phpcs.xml file but couldn't come up with a solution for such cases:
$arrays = array("1", 2, 2 , 3 ); // not allowed due to extra whitespaces
$arrays = [1 , 2 ...
0
votes
0
answers
908
views
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 ...
1
vote
0
answers
171
views
vs code phpcs only works sometimes
Sometimes I open a php file in VS Code and no linting occurs until I open the linting console from the bottom, switch over to the terminal pane where a dialog shows up that asks me if I trust the ...
4
votes
3
answers
6k
views
Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist
Just installed php_codesniffer and coder:
composer global require "squizlabs/php_codesniffer=*"
composer global require drupal/coder
After installation, run phpcs -i and the result is as ...
1
vote
1
answer
392
views
PHPCS requires a license but my code is closed source
After doing some digging online there doesn't seem to be an immediate answer to this.
I am writing code for a closed source application and when running PHPCS its informing me that an @license tag is ...
-2
votes
1
answer
339
views
why vscode phpcs extension fails after removing PEAR coding standard folder
I was going to remove (uninstall) PEAR and Zend standards from my phpcs (provided by composer installation in my windows 11)
according to this answer i manually deleted these two folders (PEAR and ...
3
votes
2
answers
2k
views
What are "MySource" and "Squiz" Coding Standards?
After installing Composer in windows 10, the result of phpc -i command is:
"The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz and Zend."
After lots of searches I ...
2
votes
3
answers
7k
views
ERROR: the "PHPCompatibility" coding standard is not installed
When I execute git commit, I get this error:
ERROR: the "PHPCompatibility" coding standard is not installed. The installed coding standards are MySource, PEAR, Zend, PSR2, PSR1, Squiz, ...
2
votes
0
answers
178
views
Is there a CLI tool organizing my PHP imports? [closed]
I am already using phpcs/phpcbf for sniffing my code. Unfortunately, I cannot find a tool or a rule for PHPCS which can automatically organize my imports. I know something like this exists for IDE's ...
4
votes
1
answer
2k
views
How to exclude everything except some directories from PHP Code Sniffer inspections in .phpcs.xml?
I would like to exclude everything except some directories from PHP Code Sniffer inspection in my project. Something similar like git repo exclusions with .gitignore
I had the idea that regex with ...
2
votes
0
answers
166
views
How to deal with PHPDoc blocks and print width PHPCS/PHPMD rules?
I'm developing a Laravel application, and I use PHPCS, PHPMD and Prettier.
I have a Facade to deal with the invitation system of the app, and the PHPDoc (at the time of writing) looks like this:
/**
*...
1
vote
1
answer
611
views
Phpcs is not reported on PhpStorm interface
I'm trying to configure PHP Code Sniffer on my project, and I would like to see the error/warnings directly on the editor - like any other error, warnings.
I installed the package in composer ...
1
vote
1
answer
551
views
phpcs --standard=PHPCompatibility not detecting error
I am trying to check for errors via phpcs and PHPCompatibility standard on a laravel project, here is the command:
phpcs -psvw app --extensions=php --standard=PHPCompatibility --runtime-set ...
2
votes
1
answer
319
views
Is there any Customizable Sniff Properties for classes/traits/interfaces?
is there any Customizable Sniff Properties for classes/traits/interfaces to do the followings;
not allow a blank line before the first content
One blank line after the last content
I am expecting a ...