Questions tagged [phpcs]

0

votes
0

answer
3

Views

How can I modify PSR2 to check that all opening braces are on the new line everywhere

I've spent a lot of time to figure out how to require the { always on the new line (including inside functions). We have several projects with altered coding standards and I would like to write phpcs-ruleset.xml, so phpcs could check this standard. I know how to write phpcs-ruleset.xml based on PSR2...
Howard
1

votes
0

answer
109

Views

WordPress Coding standards precision sniff issue

After updating to the latest wpcs version I'm getting precision alignment warnings in my file. And it's happening for comments for the properties in my class. For instance
dingo_d
1

votes
0

answer
62

Views

Issue with Code Sniffer on Ubuntu 16 - Install pfff

I am trying to setup PHPCS, PHPMD on my Ubuntu 16.04 I was following these instruction but I am getting stuck at Installing pfff which phpcs -/usr/bin/phpcs which phpcbf -/usr/bin/phpcbf which php-cs-fixer -/usr/local/bin/php-cs-fixer which phpmd -/usr/bin/phpmd which git #installed version is 2.16....
Amit Borate
1

votes
2

answer
913

Views

PHPcs xml config disable some rules

I understand how phpcs is configurated with xml, but can not find how I disable some sniffs. This ist my current conf (don‘t even know if this is correct): and I want to disable these: [phpcs] @copyright tag must contain a year and the name of the copyright holder all doc comment sniffs (I don‘t...
muuvmuuv
1

votes
1

answer
502

Views

Ingnore or bypass errors phpcs

How to bypass or ignore specific errors/warnings in vscode?, I am using phpcs.
bashman
1

votes
0

answer
104

Views

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 to achieve this with phpcs and want to conditionally enab...
Sudar
1

votes
0

answer
108

Views

How to find phpcs current default standard

I want to know my current PHPCS standard in Visual Studio e.g: { 'phpcs.standard': 'PSR2' } how to set it is given in the documentation phpcs --config-set default_standard value
lokender singh
1

votes
1

answer
64

Views

where does phpcs store values on windows os

I am able to do successfully the command phpcs --config-set show_progress 1 but I don't know where phpcs stores this values on my disk on Windows 7 Operating System.
alpine_anil
1

votes
1

answer
478

Views

git filter-branch get only changed files?

We want to run git filter-branch over a large codebase reformatting PHP files. Since we have over 21k commits phpcbf wants to format the whole codebase every commit of filter-branch. Is it possible to get just the files that have changed for each commit and format them specifically? Something like.....
Elliot Chance
1

votes
1

answer
102

Views

Is there a tool to analyze PHP code to check whether returned value is used properly?

Let's say I have the following code: $result = $thirdPartyAPI->doSomething(); // returns false if error if ($result == false) { return $someErrorCode; } // process the valid $result I have lots of calls to the $thirdPartyAPI spread throughout the code, so I don't want to forget about checking if $re...
rchavarria
1

votes
1

answer
707

Views

Run PHP CS fixer with GrumPHP

I'm using GrumPhp to sniff my commit in my symfony project: https://github.com/phpro/grumphp Here is my config: parameters: git_dir: . bin_dir: vendor/bin tasks: phpcsfixer: config_file: ~ config: sf23 fixers: [psr2, symfony, indentation] level: psr2 verbose: true My question is: Is there a way for...
Kevin
1

votes
1

answer
290

Views

Sublime Text 3 - PHPcs plugin adding fullstops

I'm have an issue with my phpcs coding standards using Sublime Text 3. The issue outlined: I run phpcs automatically on save within each of my documents, and it's doing an amazing job. I have correct spaces and tabs, but my problem occurs when I am committing my work. My commits are almost unreadabl...
Sweet Chilly Philly
1

votes
1

answer
1.2k

Views

Configuration PHPcs in Sublime 3

I have copy paste the default phpcs.sublime-settings to User and set phpcs_execute_on_save to true but it does not work. it shows me an error Exception in thread Thread-9: Traceback (most recent call last): File './python3.3/subprocess.py', line 1104, in _execute_child FileNotFoundError: [WinError 2...
hu7sy
1

votes
1

answer
221

Views

phpcs error references old project path — how do I update the path?

When I run phpcs, it prints an error that references the path where my project formerly was located, but is no longer located... PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'DirectoryIterator::__construct(/my/old/directory/public_html/coder/coder_sniffer): failed to...
arnoldbird
1

votes
1

answer
311

Views

PHPCS / PHPMD : Is there a PHP Code Sniffer / Mess Detector way to ensure there are docblocks? [duplicate]

This question already has an answer here: Is there a PHPCS standard targeting PHP docblocks? 3 answers Is there a way I can use PHP Code Sniffer and/or PHP Mess Detector to detect if my classes/properties/methods have proper docblocks? For example: class Foo { protected $bar; public function doStuf...
Giel Berkers
1

votes
1

answer
253

Views

how to set custom rule for unused variable and method in php code sinffer?

I am using php code sniffer with smyfony 3.1. Package Name:Squiz I am trying to run phpcs command in my symfony based project. Command: phpcs --standard=/c/xampp/php/pear/PHP/CodeSniffer/Standards/Squiz src/MYBundle/Controller/MYController.php Command is working fine, In this controller/class i...
1

votes
1

answer
179

Views

How do PEAR class comment and file comment sniffs cooperate?

The PEAR standard has File and Class comment code sniffs and I am uncertain as to how they interact. The first part of the PEAR class comment check is $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[...
GrahamL
1

votes
1

answer
61

Views

adding fixable errors using phpcs

When I call addFixableError in phpcs the output shows a fixable error as expected, however in the sniff code I check the return and this is false and I would therefore expect the output from phpcs to show that the error is not fixable. I am correct in this assumptino or am I missing something? It se...
GrahamL
1

votes
1

answer
156

Views

Storing results of phpcs fixer into a file

Is there any option to store the output of the phpcs fixer results into a file ? I tried the below phpcs --standard='Symfony' -a 'path' --report-file='~/Users/uname/Desktop/PHPcs' But it gives an error: ERROR: The specified report file path '~/Users/uname/Desktop/PHPcs' points to a non-existent dir...
Jignesh Rawal
1

votes
1

answer
180

Views

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( Exception $e, array $data = [] ) { } although this code is gi...
Amit Bisht
1

votes
1

answer
0

Views

PHPCS cannot be set to PSR2 by default

I'm trying to set up PHPCS to run with PSR2 by default instead of having to specify it on each run. I set the default with phpcs --config-set standard PSR2 When I check the configuration, it appears to be set: $ phpcs --config-show Using config file: /usr/bin/CodeSniffer.conf standard: PSR2 When I...
user984869
1

votes
1

answer
0

Views

PhpStorm is throwing an error if running phpcs

First of all, let me list some versions so you know the setup. OS: Windows 10 php: 7.2.7 NTS with xDebug 2.6.1 active PhpStorm: 2016.2.2 PHP_CodeSniffer: version 3.4.0 (stable) by Squiz (http://www.squiz.net) PEAR: 1.10.7 Now let me describe the problem: The code sniffer was installed via pear. I'm...
Simon Aberle
1

votes
1

answer
0

Views

PHP CodeSniffer: ERROR: The specified sniff code “Generic.Files.LineEndings.InvalidEOLChar” is invalid

My attempt to exclude the check for the EOL char on my Windows machine always results in this error message: >vendor\bin\phpcs.bat --standard=PSR2 --exclude=Generic.Files.LineEndings.InvalidEOLChar src\version.php ERROR: The specified sniff code 'Generic.Files.LineEndings.InvalidEOLChar' is invalid...
Tobias Uhmann
1

votes
1

answer
184

Views

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 found error. If anyone has a suggestion, I would be...
user573
1

votes
1

answer
277

Views

phpcs errors on Linux Mint

I have installed composer and phpcs on Linux Mint, after running the command in terminal phpcs --standard=WordPress-VIP class-wpeka-auto-updater.php it throws the following errors PHP Fatal error: Uncaught PHP_CodeSniffer_Exception: Referenced sniff 'Generic.PHP.DisallowAlternativePHPTags' does n...
Ratnesh Kadam
1

votes
1

answer
62

Views

Configuring phpcs to disallow spaces after closing bracket and before closing bracket

Most of our projects are WordPress, and while we agree with the most of coding standards it sets, there are some which we disagree on and do not want to use in our own private projects. Somehow pieces of those disagreements still end up in the codebase due to devs copypasting solutions they found on...
Christian
1

votes
1

answer
789

Views

phpcs: Missing parameter comment

I have the following code: /** * @param TranscodingJob $transcodingJob * * @return TranscodingJob * @throws \Lexik\Bundle\WorkflowBundle\Exception\WorkflowException */ public function onTranscodingJobError(TranscodingJob $transcodingJob) { ... ... and I find that when I hover over the annotation, t...
Patrick at work
1

votes
1

answer
135

Views

PhpStorm: How to disable PHPCS for Javascript

PHPCS is checking my JS files on PhpStorm, I need to disable this feature I added this line in the file phpcs.xml.dist but no luck *\.(inc|css|js)
UnLoCo
1

votes
1

answer
997

Views

PHPMD and PHPCS Camelcase for Tests

I just installed both PHPMD and PHPCS with my Project. Now, I would like to customize them a bit, but can't seem to achieve it. I get 2 warnings that I would like to remove for all my project: phpcs: public method name MyTests::my_test_that_should_pass is not in camel caps format phpmd: the method...
12

votes
2

answer
2.7k

Views

phpcs: How can I modify PSR2 to check that the brace is on the same line as the method?

I've spent now over 2h on trying to figure out how to require the { in the same line as the method declaration instead of the default requirement being the next line. How can I get this done? I've copied the PSR2 standard to a new folder named PSR2 to be ably to modify it to my liking. So the base I...
burzum
1

votes
1

answer
540

Views

Error with PHP Code Sniffer and PhpStorm

17:18 PHP Code Sniffer No response from /home/my_user/.composer/vendor/squizlabs/php_codesniffer/bin/phpcs after 5000 ms Disable inspection Any idea? I've tried a lot of solutions like disable xdebug, increment response time. It does not work in PhpStorm but works in the terminal.
Juan Wilde
2

votes
2

answer
52

Views

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 sniff? Thaks for your answers and advices.
ETNyx
4

votes
1

answer
983

Views

Configure PHP-cs-fixer indentation for 2 spaces rather than 4?

Not sure if this a better question for here or SuperUser. If it belongs there feel free to move it. I'm using php-cs-fixer, and I have a unique requirement on indentations - I need two spaces rather than four. Is there a way to change this setting? Note that I'm using atom-beautifier to run php-cs-f...
David Dale
3

votes
1

answer
761

Views

Unable to install PHP CodeSniffer in wamp or xampp in windows 10 system

I am trying to install code sniffer in my localhost but unable to install it. System: Windows 10 PHP: PHP 5.4+ I have tried below methods. Open command prompt with administrative permissions (select “run as administrator “) Go to your php install directory. For example : \wamp\bin\php\php5.5.12...
RJParikh
3

votes
1

answer
1.1k

Views

PHP CodeSniffer ignore/exclude underscore rule in methods

When running phpcs, I am getting an error of Protected member variable 'myMethod' must contain a leading underscore. How do I exclude/ignore this error on the ruleset.xml? The PSR-2 coding standard. 0 0 0 0
basagabi
2

votes
1

answer
478

Views

phpcbf complains about missing CodeSniffer

The Problem phpcbf complains about missing CodeSniffer but it appears to be missing from its own phar. My setup Ubuntu 14.04 using ondrej ppa for PHP 5.6 Here's what I've tried for installation and the output to verify installation sudo pear install PHP_CodeSniffer pear list => PHP_CodeSniffer 2.6.0...
mkaatman
3

votes
1

answer
136

Views

WordPress Coding Standards – phpcs Warnings

I'm using the WordPress-Core rules for a project I just started in PhpStorm (involves developing a custom plugin and theme), and I find it strange that most of the default php files in a clean WordPress install (for example, wp-config.php, wp-mail.php, etc.) don't pass the phpcs test when any of the...
sgr12
2

votes
1

answer
1.1k

Views

Configure CodeSniffer on PhpStorm using Docker

I am developing a project using PhpStorm and I am using Php 7.1 with Docker. I would like to integrate PHP code sniffer in PhpStorm. In PhpStorm I go to Settings|Languages&Frameworks|PHP|CodeSniffer and I try to add a new configuration, I provide as PHP Code Sniffer (phpcs) path the path of a script...
marcosh
1

votes
2

answer
157

Views

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 before '?'; newline found 38 | ERROR | [x] Expected 1 space before ':'; newline found My code looks...
jager91
2

votes
2

answer
526

Views

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 of those files, I get a message at the top of the...
Nicolas

View additional questions