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
1
vote
1 answer

How can I find out what rule produces an error?

I'm setting up PHP CodeSniffer as a linter for my code and I have an error which I want to ignore. In order to do that, I should be able to put the line // phpcs:ignore Name.Of.The.Rule before the line that is an exception to that…
SteeveDroz
  • 6,006
  • 6
  • 33
  • 65
1
vote
1 answer

Versioning and development process setup for php + mysql with atlassian helpers

I have been researching a bit to try and configure a good development and release process for a 20+ strength development team with multi project responsibilities. I wanted to go with GIT as the versioning system since it is easy to use, setup,…
user816083
  • 11
  • 1
1
vote
0 answers

Use placeholders and $wpdb->prepare(); found interpolated variable $now

I have a problem with placeholders in $wpdb->get_results. With the code below I have all the results correctly but I have an error when I use the code sniffer $now = current_time('mysql', true); $allPosts = $wpdb->get_results(" SELECT DISTINCT …
C. Max
  • 45
  • 1
  • 7
1
vote
1 answer

Fixing function multiline arguments to a certain structure using phpcs or php-cs-fixer

I'm working on a project which developed many developers for many years, and as it often happens there is no coding standard. There are many code blocks which in general is similar but written in a different way. For example: return…
Serhii Popov
  • 3,326
  • 2
  • 25
  • 36
1
vote
1 answer

Can PHP Code Sniffer advise me which rule has been violated and how to turn it off?

Is it possible to have the sniffer output the rule has been broken and therefore which line of my config I can change to stop these violations appearing? e.g. I am getting a large number of array related violations but I am happy with my array…
Jon Winstanley
  • 23,010
  • 22
  • 73
  • 116
1
vote
1 answer

How to find and alter rulesets in codesniffer?

I'm using codesniffer in a pre-commit git hook like this phpcs --standard=PSR2,PSR1 src/ However, I don't like the intend policy with tabs. My problem is I don't find the xml that defines the ruleset. When I try to find the available standards with…
agoldev
  • 2,078
  • 3
  • 23
  • 38
1
vote
0 answers

What is the replacement for 'require_once' in PHP for Magento2 to resolve CodeSniffer test issue in Magento store?

I'm a beginner at PHP and Magento have developed a Magento2 extension and used this line code in it: require_once '/../knownuserv3/KnownUser.php'; But when I tried to put my extension in Magento Store, I got a series of test failure from Code…
S.Cheginy
  • 424
  • 2
  • 15
1
vote
3 answers

PHP multiple function return types String|int

I've come across a bit unusual scenario where my function returns multiple types string or integer. I'm trying to declare return types. Could anyone please suggest me the best practice here to declare. I'm aware that null or other type I can use…
Developer
  • 3,857
  • 4
  • 37
  • 47
1
vote
1 answer

phpcs keeps scanning the whole project and not the specified directory

I am trying to run PHP code sniffer on a specific directory, but PHP code sniffer is ignoring the flag and scan the whole project. Here is the command I am running: ./vendor/bin/phpcs -p . --extensions=php docs/ I am using the current…
1
vote
2 answers

preg_match first string after string in parentheses

I've looked around for solutions close to this but have not been successful in finding a solution. I'm looking to clean up some legacy code via php_codesniffer but the fixer doesn't fix comments or arrays that go past 80 cols just lets you know…
vaene
  • 189
  • 2
  • 12
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
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

Visualize PHP code with Checkstyle report (from CodeSniffer)

PHP CodeSniffer is a very good tool to help us check our PHP source code. But the report from CodeSniffer is not easy to read. I found that CodeSniffer can output 'Checkstyle' xml report. Is that any way to Visualize PHP code with Checkstyle xml…
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
1
vote
1 answer

How do I uninstall PHP CodeSniffer on Mac OSX (10.11.6)?

I used Pear to install PHP CodeSniffer, and something went terribly wrong. It seems like most of the files weren't copied over. Perhaps I should have installed it with root privileges. It doesn't work, it's a mess, and I want to uninstall it and…