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

phpcs - Prevent showing "Opening parenthesis of a multi-line function call must be the last content on the line"

The error occur for this code: $posts = App\Post::whereHas('comments', function (Builder $query) { $query->where('content', 'like', 'foo%'); }); I'm using phpcs vscode and need all of the default rules of phpcs except this one! Could you please…
Ali
  • 185
  • 11
3
votes
1 answer

PHPCS WordPress Core standard: Tabs must be used to indent lines; spaces are not allowed. Already using Tabs for indentation

I already have lines indented with Tabs inside my plugin file. But PHPCS still reports the following: Tabs must be used to indent lines; spaces are not allowed 32 | ERROR | [x] Tabs must be used to indent lines; spaces are not allowed | …
Subrata Sarkar
  • 2,975
  • 6
  • 45
  • 85
3
votes
1 answer

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…
RJParikh
  • 4,096
  • 1
  • 19
  • 36
3
votes
1 answer

Custom coding standards sniffs not working - PHP_CodeSniffer_Exception

I am working on creating a custom ruleset for sniffing code in WordPress, and I'm using PHP_CodeSniffer for that. The custom ruleset can be found here: https://github.com/infinum/coding-standards-wp. Now when I try to use them I get this error Fatal…
dingo_d
  • 11,160
  • 11
  • 73
  • 132
3
votes
1 answer

Pear CodeSniffer Cyclomatic Complexity

The Pear CodeSniffer seems to come with a Cyclomatic Complexity Sniff (CyclomaticComplexitySniff.php). Does anyone know how to use it? I'd like to calculate the complexity of the code I'm analyzing. I'd like to use the Zend coding standard, but no…
3
votes
1 answer

PhpCS exclude sniffs not working

I am running Php 7.0 on my machine but I need to check code that executes in both 7.0 and 5.6. As such, I get a load of Squiz.Commenting.FunctionComment.ScalarTypeHintMissing errors when using the -s flag. I have installed PhpCS via composer for…
myol
  • 8,857
  • 19
  • 82
  • 143
3
votes
1 answer

Zend Coding Standard in Netbeans

How to configure Netbeans PHP to follow Zend Coding Standard? I'm struggling with this quite a while, and still get phpcs errors on multi line function arguments. Would you share your settings?
takeshin
  • 49,108
  • 32
  • 120
  • 164
3
votes
1 answer

Can I specify a CodeSniffer standard as a dev composer dependency?

Say I have two or three projects, and they all use different PHP CodeSniffer standards (custom made). I'd like to be able to include them as require-dev dependencies with Composer, so that when spinning up a project repository they will be installed…
scrowler
  • 24,273
  • 9
  • 60
  • 92
3
votes
3 answers

PhpStorm - How to detect PHP error "Non-static method should not be called statically"?

With PHP, static method can be used in both static method and non-static method, and non-static method can only used in non-static method. That's why calling a dynamic method statically generates the E_STRICT error. For example:
Guicara
  • 1,668
  • 2
  • 20
  • 34
3
votes
2 answers

End of line character is invalid

I checked my code using php codesniffer and got this error: It says the error happened in the first line of the code, but all I have in the first line of my code is a php opening tag:
NL500
  • 1,165
  • 2
  • 9
  • 13
3
votes
2 answers

PHPCS sniff names don't seem to match to PHPCBF fixes

I have some sniffs defined in a phpcs.xml, like so: My intention is to gradually tighten up the CS rules (there are many more excludes) in a…
bcmcfc
  • 25,966
  • 29
  • 109
  • 181
3
votes
1 answer

PHPCodeSniffer - blank lines before function

I'm using PHP CodeSniffer, and one of the rules specifies that there must be a blank line for each function (CodeStandard.WhiteSpace.FunctionSpacing.Before) Whilst this works fine, it also includes the first function at the top of the class. I would…
JonoB
  • 5,801
  • 17
  • 55
  • 77
3
votes
1 answer

PHP Code Sniffer Rules

I'm having trouble getting these rules to work: No space after function name: // good public function cities() // bad public function cities () Ensure space between equals: // good $test = 'test'; // bad $test ='test'; $test= 'test'; Must have…
Rob
  • 10,851
  • 21
  • 69
  • 109
3
votes
1 answer

Using Jenkins and PHP Code Sniffer in ANT Build Script

I am using the PHP Code Sniffer plugins in Jenkins. It generates a checkstyle.xml file but the jenkins server cannot parse the file I get the following in the Build Console Output. phpdox: ... [exec] Parsing checkstyle logfile failed: loading…
Whales
  • 388
  • 1
  • 3
  • 10
3
votes
1 answer

How to correctly change line character limit configuration in PHP CodeSniffer?

So I want to change the values for $lineLimit and $absoluteLineLimit that PHP CodeSniffer uses when checking files. After some googling I tried to make my own standard to facilitate this but I haven't got it working. Working on Ubuntu 12.04.4LTS and…
The Ice Mage
  • 445
  • 1
  • 7
  • 17