Giter Site home page Giter Site logo

squizlabs / php_codesniffer Goto Github PK

View Code? Open in Web Editor NEW
10.6K 196.0 1.5K 197.16 MB

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

License: BSD 3-Clause "New" or "Revised" License

PHP 98.09% JavaScript 1.41% CSS 0.47% Batchfile 0.02% HTML 0.02%
php coding-standards automation cli qa static-analysis

php_codesniffer's Introduction

Warning

This repository has been abandoned. Its successor is PHPCSStandards/PHP_CodeSniffer

See issue #3932 for more information.

About

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

Build Status Build Status Code consistency Join the chat at https://gitter.im/squizlabs/PHP_CodeSniffer

Requirements

PHP_CodeSniffer requires PHP version 5.4.0 or greater, although individual sniffs may have additional requirements such as external applications and scripts. See the Configuration Options manual page for a list of these requirements.

If you're using PHP_CodeSniffer as part of a team, or you're running it on a CI server, you may want to configure your project's settings using a configuration file.

Installation

The easiest way to get started with PHP_CodeSniffer is to download the Phar files for each of the commands:

# Download using curl
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar

# Or download using wget
wget https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
wget https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar

# Then test the downloaded PHARs
php phpcs.phar -h
php phpcbf.phar -h

Composer

If you use Composer, you can install PHP_CodeSniffer system-wide with the following command:

composer global require "squizlabs/php_codesniffer=*"

Make sure you have the composer bin dir in your PATH. The default value is ~/.composer/vendor/bin/, but you can check the value that you need to use by running composer global config bin-dir --absolute.

Or alternatively, include a dependency for squizlabs/php_codesniffer in your composer.json file. For example:

{
    "require-dev": {
        "squizlabs/php_codesniffer": "3.*"
    }
}

You will then be able to run PHP_CodeSniffer from the vendor bin directory:

./vendor/bin/phpcs -h
./vendor/bin/phpcbf -h

Phive

If you use Phive, you can install PHP_CodeSniffer as a project tool using the following commands:

phive install phpcs
phive install phpcbf

You will then be able to run PHP_CodeSniffer from the tools directory:

./tools/phpcs -h
./tools/phpcbf -h

PEAR

If you use PEAR, you can install PHP_CodeSniffer using the PEAR installer. This will make the phpcs and phpcbf commands immediately available for use. To install PHP_CodeSniffer using the PEAR installer, first ensure you have installed PEAR and then run the following command:

pear install PHP_CodeSniffer

Git Clone

You can also download the PHP_CodeSniffer source and run the phpcs and phpcbf commands directly from the Git clone:

git clone https://github.com/squizlabs/PHP_CodeSniffer.git
cd PHP_CodeSniffer
php bin/phpcs -h
php bin/phpcbf -h

Getting Started

The default coding standard used by PHP_CodeSniffer is the PEAR coding standard. To check a file against the PEAR coding standard, simply specify the file's location:

phpcs /path/to/code/myfile.php

Or if you wish to check an entire directory you can specify the directory location instead of a file.

phpcs /path/to/code-directory

If you wish to check your code against the PSR-12 coding standard, use the --standard command line argument:

phpcs --standard=PSR12 /path/to/code-directory

If PHP_CodeSniffer finds any coding standard errors, a report will be shown after running the command.

Full usage information and example reports are available on the usage page.

Documentation

The documentation for PHP_CodeSniffer is available on the Github wiki.

Issues

Bug reports and feature requests can be submitted on the Github Issue Tracker.

Contributing

See CONTRIBUTING.md for information.

Versioning

PHP_CodeSniffer uses a MAJOR.MINOR.PATCH version number format.

The MAJOR version is incremented when:

  • backwards-incompatible changes are made to how the phpcs or phpcbf commands are used, or
  • backwards-incompatible changes are made to the ruleset.xml format, or
  • backwards-incompatible changes are made to the API used by sniff developers, or
  • custom PHP_CodeSniffer token types are removed, or
  • existing sniffs are removed from PHP_CodeSniffer entirely

The MINOR version is incremented when:

  • new backwards-compatible features are added to the phpcs and phpcbf commands, or
  • backwards-compatible changes are made to the ruleset.xml format, or
  • backwards-compatible changes are made to the API used by sniff developers, or
  • new sniffs are added to an included standard, or
  • existing sniffs are removed from an included standard

NOTE: Backwards-compatible changes to the API used by sniff developers will allow an existing sniff to continue running without producing fatal errors but may not result in the sniff reporting the same errors as it did previously without changes being required.

The PATCH version is incremented when:

  • backwards-compatible bug fixes are made

NOTE: As PHP_CodeSniffer exists to report and fix issues, most bugs are the result of coding standard errors being incorrectly reported or coding standard errors not being reported when they should be. This means that the messages produced by PHP_CodeSniffer, and the fixes it makes, are likely to be different between PATCH versions.

php_codesniffer's People

Contributors

aboks avatar alekitto avatar andygrunwald avatar bondas83 avatar carusogabriel avatar fabacino avatar fredden avatar gmponos avatar gsherwood avatar josephzidell avatar jrfnl avatar kdebisschop avatar klausi avatar kukulich avatar masterodin avatar michalbundyra avatar morozov avatar nubs avatar pfrenssen avatar phil-davis avatar photodude avatar rmccue avatar sebastianbergmann avatar sertand avatar thewilkybarkid avatar thiemowmde avatar tim-bezhashvyly avatar uniquexor avatar vincentlanglet avatar wimg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php_codesniffer's Issues

Reference check fails

Currently CS fails on references with the update to 1.5.5.

This is the part of code:

   /**
     * Get an array with all the invalid general form inputs
     *
     * @param array &$errors an array with all the errors
     */
    public function getFormErrors(array &$errors);

This is the message I receive back

FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
 144 | ERROR | Doc comment for var &$errors does not match actual variable name
     |       | $errors at position 1
--------------------------------------------------------------------------------

It worked perfect with CodeSniffer 1.5.4, but no longer with 1.5.5.

I am using the Symfony2 standard from a different repository, however that one has not been updated recently, which leads me to the feeling a change in CodeSniffer caused this issue.

DocCommentSniff reporting single-line block comments as error

There are 2 way how you can write a block comment:

class Something
{
    /**
     * Description.
     *
     * @var ClassName
     */
    protected $somethingMultiLine;

    /** @var ClassName Description */
    protected $somethingElse;

}

Same goes for method DocBlocks and DocBlocks for individual variables in the code.

However the DocCommentSniff reports 1st line in following code as error:

/** @var NodeElement $content_box_title */
$content_box_title = array_shift($content_box_titles);

Error text: The open comment tag must be the only content on the line
Error code: ContentAfterOpen

Reference: http://www.phpdoc.org/docs/latest/references/phpdoc/tags/var.html

JSON reporter broken in .phar files

In the .phar files the version of the JSON reporter that is packed doesn't implement a compatible signature for the method PHP_CodeSniffer_Reports_Json::generateFileReport which signature should be not compatible with PHP_CodeSniffer_Report::generateFileReport as it doesn't use the new PHP_CodeSniffer_File argument.

The --config-show option generates error when there is no config file

When I run ./scripts/phpcs --config-show in cloned project repository I see this:

PHP Warning:  array_keys() expects parameter 1 to be array, null given in .../CodeSniffer/CLI.php on line 849
PHP Stack trace:
PHP   1. {main}() .../scripts/phpcs:0
PHP   2. PHP_CodeSniffer_CLI->process($values = *uninitialized*) .../scripts/phpcs:37
PHP   3. PHP_CodeSniffer_CLI->getCommandLineValues() .../CodeSniffer/CLI.php:551
PHP   4. PHP_CodeSniffer_CLI->processLongArgument($arg = 'config-show', $pos = 1, $values = array ('files' => array (), 'standard' => NULL, 'verbosity' => 0, 'interactive' => FALSE, 'explain' => FALSE, 'local' => FALSE, 'showSources' => FALSE, 'extensions' => array (), 'sniffs' => array (), 'ignored' => array (), 'reportFile' => NULL, 'generator' => '', 'reports' => array (), 'errorSeverity' => NULL, 'warningSeverity' => NULL, 'tabWidth' => 0, 'encoding' => 'iso-8859-1', 'reportWidth' => 80, 'showProgress' => FALSE)) .../CodeSniffer/CLI.php:205
PHP   5. PHP_CodeSniffer_CLI->printConfigData($data = NULL) .../CodeSniffer/CLI.php:348
PHP   6. array_keys(NULL) .../CodeSniffer/CLI.php:849
PHP Warning:  Invalid argument supplied for foreach() in .../CodeSniffer/CLI.php on line 850
PHP Stack trace:
PHP   1. {main}() .../scripts/phpcs:0
PHP   2. PHP_CodeSniffer_CLI->process($values = *uninitialized*) .../scripts/phpcs:37
PHP   3. PHP_CodeSniffer_CLI->getCommandLineValues() .../CodeSniffer/CLI.php:551
PHP   4. PHP_CodeSniffer_CLI->processLongArgument($arg = 'config-show', $pos = 1, $values = array ('files' => array (), 'standard' => NULL, 'verbosity' => 0, 'interactive' => FALSE, 'explain' => FALSE, 'local' => FALSE, 'showSources' => FALSE, 'extensions' => array (), 'sniffs' => array (), 'ignored' => array (), 'reportFile' => NULL, 'generator' => '', 'reports' => array (), 'errorSeverity' => NULL, 'warningSeverity' => NULL, 'tabWidth' => 0, 'encoding' => 'iso-8859-1', 'reportWidth' => 80, 'showProgress' => FALSE)) .../CodeSniffer/CLI.php:205
PHP   5. PHP_CodeSniffer_CLI->printConfigData($data = NULL) .../CodeSniffer/CLI.php:348

Maybe this happens when I don't have any config. This happens on both master and phpcs-fixer branches.

Problem comes from https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer.php#L2192 line where @data_dir@/PHP_CodeSniffer/CodeSniffer.conf file isn't found and null is returned. Then that null ends up in array_keys function which shows that notice.

I think that CodeSniffer.conf.dist should be used in case if CodeSniffer.conf is not found. This is how PHPUnit/Behat does that as well.

I guess that @data_dir@ is replaced by PEAR at some point, but when we don't have any PEAR this ends badly.

A standard should beable to set the encoding to UTF-8

Problem:

// Hà Nội là thủ đô, đồng thời là thành phố đứng đầu Việt Nam về diện tích tự.
$foo = 'x';

Will cause a Line exceeds 80 characters warning in the Drupal standard although the line clearly does not exceed 80 character (UTF-8 characters).

This came up in https://www.drupal.org/node/2333251 and I would like to set UTF-8 as standard encoding for Drupal. Is that even possible? I could not find the place in the code where this could be determined from the ruleset.xml of a standard.

[phpcs-fixer] "Generic.WhiteSpace.DisallowSpaceIndent" sniff issue with class DocBlock

The Generic.WhiteSpace.DisallowSpaceIndent sniff mistakenly reports class DocBlock, which naturally have no indentation in the file, as Tabs must be used to indent lines; spaces are not allowed (code: SpacesUsed) error.

Example code:

<?php

defined('FULL_PATH') or die('restricted access!');

/**
 * Sample helper contains methods used in different classes
 *
 */
class SampleHelper extends kHelper
{



}

The 3 lines that start with * are being reported. I think that space before DocBlock asterisk should not be counted towards indentation at all.

PSR2 and alternative php syntax for template

I use PSR2 and alternative syntax for php in templates.

For example this code:

<?php if($foo):?>
  <?=$bar?>
<?php endif?>

After running phpsniffer, i'm see error like this: "Line indented incorrectly; expected 103 spaces, found 0"

What i can do for correct check files with alternative php code?

Exclude this files is not correct way because this files can include another errors in code.

How to override $allowedTypes

I've managed to get PHP CodeSniffer installed and working. I have also managed to write my own custom sniffs.

There is one issue that I cannot figure out - how do I override the $allowedTypes variable which is defined in the main PHP_CodeSniffer class:

    public static $allowedTypes = array(
       'array',
       'boolean',
       'float',
       'integer',
       'mixed',
       'object',
       'string',
       'resource',
       'callable',
    );

I would like to add 'bool' and 'int' options to this array, but without monkey patching the core repository.

False positive in ScopeIndentSniff when anonymous functions are used with method chaining

Minimal example:

class FooTest extends AbstractTestCase
{
    public function foo()
    {
        $mockedDatabase->expects($this->at(2))
            ->method('raw')
            ->with($this->callback(
                    function ($subject)
                    {
                    }
                )
            );

        /** @var Database $mockedDatabase */
        /** @var Container $mockedContainer */
        $subject = new HeartbeatRegistrator($mockedLogger, $mockedDatabase, $mockedContainer);

        $subject->addHeartbeatObjectsToQueue(array($mockedHeartbeatObject1, $mockedHeartbeatObject2));
    }
}

FOUND 4 ERRORS AFFECTING 4 LINES

32 | ERROR | [x] Line indented incorrectly; expected at least 12 spaces, found
| | 8
33 | ERROR | [x] Line indented incorrectly; expected at least 12 spaces, found
| | 8
34 | ERROR | [x] Line indented incorrectly; expected at least 12 spaces, found
| | 8
36 | ERROR | [x] Line indented incorrectly; expected at least 12 spaces, found
| | 8

Another undefined string offset

Hi, i've tried running up codesniffer against latest wordpress version and got following error several times:

Undefined offset: 1057 in squizlabs/php_codesniffer/CodeSniffer/Tokenizers/JS.php on line 907

full paste

You can recreate it by downloading WP 4.0 (.zip | .tar.gz | archive page) and running phpcs ..

PHPCS version: 1.5.4; got same thing for 2.0.x-dev (except for notice being raised on line 1004).

Difference between 2 installs of PHPCS

I have installed PHPCS on my local Mac and on a webserver running Centos 6, both via Composer and both using same version of PHPCS. I have then added an aditional Standard to both, again both from same source, same version etc.

When I run PHPCS against the same files the version on my Mac returns considerably less errors than the same files on my server?

This is the command I am running on the server:

./phpcs --standard="/var/www/html/ci.devapps.mmu.ac.uk/standards/vendor/cakephp/cakephp-codesniffer/CakePHP" /var/www/html/devapps.mmu.ac.uk/events/Controller/EventsController.php

Which generates:
FOUND 18 ERROR(S) AFFECTING 18 LINE(S)

And this is what I am running on the mac:

./phpcs --standard=CakePHP /Users/toby/Server/Sites/events/Controller/EventsController.php

But this reports nothing and indicates that it passes?

Can anyone suggest why they would be differing?

PHP Notices

Could you please fix these PHP Notices ? :
We use PHP_CodeSniffer version 1.5.5 (stable) by Squiz (http://www.squiz.net)

PHP Notice:  Uninitialized string offset: 0 in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 228
PHP Stack trace:
PHP   1. {main}() /home/travis/phpcs/scripts/phpcs:0
PHP   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
PHP   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
PHP   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
PHP   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226
PHP   6. PHP_CodeSniffer_Reports_Source->makeFriendlyName() /home/travis/phpcs/CodeSniffer/Reports/Source.php:148
Notice: Uninitialized string offset: 0 in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 228
Call Stack:
    0.0002     242184   1. {main}() /home/travis/phpcs/scripts/phpcs:0
    0.0099    1344128   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
   79.7224    3278896   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
   79.7224    3279464   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
   79.7225    3280920   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226
   79.7227    3282616   6. PHP_CodeSniffer_Reports_Source->makeFriendlyName() /home/travis/phpcs/CodeSniffer/Reports/Source.php:148
PHP Notice:  Array to string conversion in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 150
PHP Stack trace:
PHP   1. {main}() /home/travis/phpcs/scripts/phpcs:0
PHP   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
PHP   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
PHP   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
PHP   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226
Notice: Array to string conversion in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 150
Call Stack:
    0.0002     242184   1. {main}() /home/travis/phpcs/scripts/phpcs:0
    0.0099    1344128   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
   79.7224    3278896   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
   79.7224    3279464   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
   79.7225    3280920   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226


   PHP Notice:  Uninitialized string offset: 0 in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 228
PHP Stack trace:
PHP   1. {main}() /home/travis/phpcs/scripts/phpcs:0
PHP   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
PHP   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
PHP   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
PHP   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226
PHP   6. PHP_CodeSniffer_Reports_Source->makeFriendlyName() /home/travis/phpcs/CodeSniffer/Reports/Source.php:148
Notice: Uninitialized string offset: 0 in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 228
Call Stack:
    0.0002     242184   1. {main}() /home/travis/phpcs/scripts/phpcs:0
    0.0099    1344128   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
   79.7224    3278896   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
   79.7224    3279464   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
   79.7225    3280920   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226
   79.7247    3282720   6. PHP_CodeSniffer_Reports_Source->makeFriendlyName() /home/travis/phpcs/CodeSniffer/Reports/Source.php:148
PHP Notice:  Array to string conversion in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 150
PHP Stack trace:
PHP   1. {main}() /home/travis/phpcs/scripts/phpcs:0
PHP   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
PHP   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
PHP   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
PHP   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226
Notice: Array to string conversion in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 150
Call Stack:
    0.0002     242184   1. {main}() /home/travis/phpcs/scripts/phpcs:0
    0.0099    1344128   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
   79.7224    3278896   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
   79.7224    3279464   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
   79.7225    3280920   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226

   PHP Notice:  Uninitialized string offset: 0 in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 228
PHP Stack trace:
PHP   1. {main}() /home/travis/phpcs/scripts/phpcs:0
PHP   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
PHP   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
PHP   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
PHP   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226
PHP   6. PHP_CodeSniffer_Reports_Source->makeFriendlyName() /home/travis/phpcs/CodeSniffer/Reports/Source.php:148
Notice: Uninitialized string offset: 0 in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 228
Call Stack:
    0.0002     242184   1. {main}() /home/travis/phpcs/scripts/phpcs:0
    0.0099    1344128   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
   79.7224    3278896   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
   79.7224    3279464   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
   79.7225    3280920   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226
   79.7255    3282728   6. PHP_CodeSniffer_Reports_Source->makeFriendlyName() /home/travis/phpcs/CodeSniffer/Reports/Source.php:148
PHP Notice:  Array to string conversion in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 150
PHP Stack trace:
PHP   1. {main}() /home/travis/phpcs/scripts/phpcs:0
PHP   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
PHP   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
PHP   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
PHP   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226
Notice: Array to string conversion in /home/travis/phpcs/CodeSniffer/Reports/Source.php on line 150
Call Stack:
    0.0002     242184   1. {main}() /home/travis/phpcs/scripts/phpcs:0
    0.0099    1344128   2. PHP_CodeSniffer_CLI->process() /home/travis/phpcs/scripts/phpcs:37
   79.7224    3278896   3. PHP_CodeSniffer_CLI->printErrorReport() /home/travis/phpcs/CodeSniffer/CLI.php:641
   79.7224    3279464   4. PHP_CodeSniffer_Reporting->printReport() /home/travis/phpcs/CodeSniffer/CLI.php:693
   79.7225    3280920   5. PHP_CodeSniffer_Reports_Source->generate() /home/travis/phpcs/CodeSniffer/Reporting.php:226

Double check sniff error codes to be inline with error text

I suppose sniff error code is a shorter version of long error message text. If that is so, then error message 'Filename "%s" doesn\'t match the expected filename "%s"' in Generic_Sniffs_Files_LowercasedFilenameSniff should not have NotFound error code. Maybe it should be NotLowercase instead.

Maybe this is unique case, but maybe other sniffs also have their error codes out of sync with error messages.

Conditional breaks in case statements get incorrect indentions

vendor/bin/phpcbf --version
PHP_CodeSniffer version 2.0.0RC3 (beta) by Squiz (http://www.squiz.net)

vendor/bin/phpcbf --standard=PSR2 ./module/Application/src

incorrectly fixes indentions; here a git diff of before and after;

-            case in_array($maintain, ['purge', 'all']):
-                $maintainedCount += (integer) $this->purgeData();
-
-                if ($maintain == 'purge-data') {
-                    break;
-                }
-            // conditional break
-            case in_array($maintain, ['caches', 'all']):
-                $maintainedCount += (integer) $this->clearApcCache();
-
-                $maintainedCount += (integer) $this->clearMemcachedCache();
-
-                if ($maintain != 'all' && $maintain != 'caches') {
-                    break;
-                }
-            // conditional break
-            case in_array($maintain, ['file-cache', 'caches', 'all']):
-                $maintainedCount += (integer) $this->purgeTmpFiles();
-
-                if ($maintain != 'all' && $maintain != 'caches') {
-                    break;
-                }
+                case in_array($maintain, ['purge', 'all']):
+                    $maintainedCount += (integer) $this->purgeData();
+
+                    if ($maintain == 'purge') {
+                        break;
+                    }
+                // conditional break
+                    case in_array($maintain, ['caches', 'all']):
+                        $maintainedCount += (integer) $this->clearApcCache();
+
+                        $maintainedCount += (integer) $this->clearMemcachedCache();
+
+                        if ($maintain != 'all' && $maintain != 'caches') {
+                            break;
+                        }
+                    // conditional break
+                        case in_array($maintain, ['file-cache', 'caches', 'all']):
+                            $maintainedCount += (integer) $this->purgeTmpFiles();
+
+                            if ($maintain != 'all' && $maintain != 'caches') {
+                                break;
+                            }

Forbiddenfunctions visibility change?

While using the phar version of 2.0RC2 I noticed that the visibility has changed (to public) on the $forbiddenFunctions field. Was this intended? (current master it is still protected)

https://github.com/squizlabs/PHP_CodeSniffer/blob/ecfb4ed8e45469338292dbfe9b1c2204a71ebdb0/CodeSniffer/Standards/Generic/Sniffs/PHP/ForbiddenFunctionsSniff.php

I noticed this in other files within that directory as well, so perhaps this is a new thing. Please confirm, as it has a direct effect on https://github.com/wimg/PHPCompatibility

Standards from "installed_paths" not included in tests

When running tests via phpunit tests/AllTests.php command in cloned PHP_CodeSniffer repository, then custom standards from locations defined in installed_paths configuration setting are not tested.

This happens because of https://github.com/squizlabs/PHP_CodeSniffer/blob/master/tests/Standards/AllSniffs.php#L69 line. There we try to determine of we were installed. I guess this is PEAR related. But that line doesn't make any sense, because when PHP_CodeSniffer is installed via PEAR it doesn't have any tests with it.

The following call to the PHP_CodeSniffer::getInstalledStandards(true, $standardsDir) in https://github.com/squizlabs/PHP_CodeSniffer/blob/master/tests/Standards/AllSniffs.php#L74 doesn't resolve installed_paths config settings when explicit path is given (see https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer.php#L1991).

The interesting part is that even with $isInstalled set to false the automatically detected standard path exactly matches the path that is manually created for such case in AllSniffs.php.

I propose to remove 2 IF's with $isInstalled checks and always execute part in else.

One interesting thing, that I've noticed, that even though custom standards are located their actual path is lost in the process and they are included from regular place where default PHP_CodeSniffer standards live: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/tests/Standards/AllSniffs.php#L77-L81 (see, no per-starndard absolute path on how to find it)

[branch: phpcs-fixer] Missing DocBlock not detected

If it happens, that there is an inline comment before function declaration (which in turn belongs to another method), then it's treated as malformed DocBlock comment of that function:

/**
 * A simple function comment.
 *
 * @param string $str The string passed in by reference
 *
 * @return void
 * @return
 */
public function functionOutsideClass(&$str)
{
    return;
}//end functionOutsideClass()


function missingCommentOutsideClass()
{
    return;
}//end missingCommentOutsideClass()

Error at line with missingCommentOutsideClass declaration:

  • in phpcs-fixer branch: You must use "/**" style comments for a function comment (...Commenting.FunctionComment.WrongStyle)
  • in master branch: Missing function doc comment (...Commenting.FunctionComment.Missing)

Piece of code is taken from FunctionCommentUnitTest.1.inc test file of Squiz/PEAR FunctionComment sniff. It's line 166 there.

Phar version not running recursive

I am using the latest RC2 version as a phar, and it is not sniffing recursively through a project. I am specifying the location as '/path/of/my/project/' and also trying '/path/of/my/project/*', but it will not dig into sub-directories and find files. However, it will sniff all files within a given directory, just not within sub-folders.

Command I'm using:
php phpcs.phar -sv --extensions='/home/adamculp/PHPCompatibility' --standard='PHPCompatibility' --report-file=/home/adamculp/codesniffer_results.txt --extensions=module/php /home/adamculp/site/*

The result file is created properly, and all files within the 'site' folder are parsed, but not sub-folders.

Please provide LICENSE

The LICENSE file is availa in the repo,
Please add it to the package.xml so it will part of next official archive available from PEAR.

More issues with DocCommentSniff

In the following code the absence of short description is reported (code MissingShort), however for inline block comments, like @var or @type such thing isn't a required part.

Also some issue with missing blank lines is also reported, but I have no idea why it's reported (code SpacingAfter)

/** @var NodeElement $content_box_title */
$content_box_title = array_shift($content_box_titles);

phpcs output:

--------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------
  2 | ERROR | [x] There must be one blank line after the namespace declaration
    |       |     (PSR2.Namespaces.NamespaceDeclaration.BlankLineAfter)
 25 | ERROR | [ ] Missing short description in doc comment
    |       |     (CodingStandard.Commenting.DocCommentWrapper.MissingShort)
 25 | ERROR | [x] Additional blank lines found at end of doc comment
    |       |     (CodingStandard.Commenting.DocCommentWrapper.SpacingAfter)
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

This is the file: https://gist.github.com/aik099/fc192ba0b9148002421d

I think we seriously need to address this within sniff itself, because more and more reported issues doesn't make any sense in context of inline block comments that have @var or @type in them.

Related to #258

The "PARENT" class constant is tokenized as T_PARENT

I had a following PHP code:

class UserType {
    const CAREGIVER  = 1;
    const PARENT = 2;
}

echo UserType::PARENT;

The sniff was listening for T_PARENT token only and last line of the code was matched. What I expected to match was only code that looks like parent:: instead.

I had to do some pretty large workaround code to exclude false positives in https://github.com/aik099/CodingStandard/blob/master/CodingStandard/Sniffs/CodeAnalysis/WrongParentCallSniff.php .

I remember that some T_PARENT token related fixes were committed recently, but I'm not aware if that one was there as well.

Requires @return tag in void method (caused by anonymous function inside)

The following require @return tag which is wrong:

/**
 * Void method
 */
public function voidMethod()
{
    $this->string = "Some numbers: one: 1; two: 2; three: 3 end";
    $ten = 10;
    $this->newstring = preg_replace_callback(
        '/(\\d+)/',
        function($match) use ($ten) { return (($match[0] + $ten)); },
        $this->string
    );
}

Sniff: PEAR_Sniffs_Commenting_FunctionCommentSniff

Issue with "ContentAfterOpen" error fixing in the "Generic.Commenting.DocComment" sniff

I believe, that fixing of ContentAfterOpen error in Generic.Commenting.DocComment sniff is done wrong (see https://github.com/squizlabs/PHP_CodeSniffer/blob/phpcs-fixer/CodeSniffer/Standards/Generic/Sniffs/Commenting/DocCommentSniff.php#L86).

If it encounters code like this:

class Something
{

    /** Sets data source for validation
     *
     * @param kDBItem $object
     */
    public function setDataSource(&$object)

}

then fixed code will look like this

class Something
{

    /**
 * Sets data source for validation
     *
     * @param kDBItem $object
     */
    public function setDataSource(&$object)

}

because indentation of DocBlock start tag isn't taken into account when adding new line in https://github.com/squizlabs/PHP_CodeSniffer/blob/phpcs-fixer/CodeSniffer/Standards/Generic/Sniffs/Commenting/DocCommentSniff.php#L86 .

P.S.
I guess other usages of ->fixer->addNewline method in other sniffs should be inspected to determine if indentation needs to be preserved there as well. Maybe the ->fixer->addNewline method can be improved to automatically determine indentation at given $stackPtr and apply it to new line being added.

Can't fix errors automatically.

Hi! Firstly, we very appreciate the work you do! PHPCS is a very helpful tool!

We use PHPCS + WordPress coding standard in our project.
We want to use new --report=diff param ( this param should be available in the PHPCS 2.0 ) in order to fix thousands of the errors reported in our CI testing automatically.

But we couldn't make it work for us. Please see out test - case and give us advice if we do somesing wrong. Thanks in advance.

Step-by-step test case :

  1. Installing PHPCS

https://github.com/squizlabs/PHP_CodeSniffer


curl -OL https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.0.0RC1/phpcs.phar
curl -OL https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.0.0RC1/phpcbf.phar

  1. Installing wordpress standard

https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards


git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs
cd phpcs
scripts/phpcs --config-set installed_paths ../wpcs
  1. Command line commands

We have error in the file functions.php, we see it with command parameter --report=summary

php phpcs.phar --standard=wpcs/WordPress functions.php

dev@kuf:~/www/pmt/wp-content/themes/pmtsystem$ php phpcs.phar --standard=wpcs/WordPress functions.php

FILE: /home/dev/www/pmt/wp-content/themes/pmtsystem/functions.php
--------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
--------------------------------------------------------------------------------
 63 | ERROR | Space after opening control structure is required
 63 | ERROR | No space before opening parenthesis is prohibited
--------------------------------------------------------------------------------

Time: 37ms; Memory: 4Mb

We tried to create a patch in order to apply it and fix errors automatically
But functions.php.diff file is empty if we use a command below :
php phpcs.phar --standard=wpcs/WordPress --report-diff=functions.php.diff functions.php

Also we've tried to fix errors automatically with phpcbf command instead of the phpcs command:

php phpcbf.phar --standard=wpcs/WordPress functions.php.diff

But it doesn't make sense because patch file is empty.

We tried to execute this command for different coding standards. It caused the same effect ( empty patch file ):
php phpcs.phar --standard=PSR1 --report=summary functions.php

Redundant code in "Squiz_Sniffs_Classes_ClassDeclarationSniff" class

The check made in https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassDeclarationSniff.php#L162-L170 is covered at 100% in above lines https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassDeclarationSniff.php#L136-L160 in same class.

So if there is something on same line as class/interface close brace then it's being detected already.

Here are the errors reported on last line of fixture file:

Closing brace of a class must be followed by a single blank line (....Classes.ClassDeclaration.NoNewlineAfterCloseBrace)
Closing class brace must be on a line by itself (....Classes.ClassDeclaration.CloseBraceSameLine)

Create CONTRIBUTING.md file

The CONTRIBUTING.md file should be created where at least following should be explained:

  • all PR with bugfixes should target master branch
  • all PR with features (e.g. new sniffs) should target phpcs-fixer branch
  • every new sniff or sniff change should conform to PHPCS coding standard and be covered by tests

File containing only a namespace declaration raises undefined index notice

When validating a codebase, and some files contains only a namespace declaration (shouldn't happen to often):

<?php

namespace Foo;

NamespaceDeclarationSniff raises the following notice, and we never get the opportunity to know which file was being processed (I had to go through every file in my project to find the file triggering the notice).

I'll P/R a fix when I get the chance, but at least it's recorded here :)

PHP Notice:  Undefined offset: 9 in /project/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PSR2/Sniffs/Namespaces/NamespaceDeclarationSniff.php on line 68
PHP Stack trace:
PHP   1. {main}() /project/vendor/squizlabs/php_codesniffer/scripts/phpcs:0
PHP   2. PHP_CodeSniffer_CLI->process() /project/vendor/squizlabs/php_codesniffer/scripts/phpcs:37
PHP   3. PHP_CodeSniffer->process() /project/vendor/squizlabs/php_codesniffer/CodeSniffer/CLI.php:614
PHP   4. PHP_CodeSniffer->processFile() /project/vendor/squizlabs/php_codesniffer/CodeSniffer.php:488
PHP   5. PHP_CodeSniffer->_processFile() /project/vendor/squizlabs/php_codesniffer/CodeSniffer.php:1340
PHP   6. PHP_CodeSniffer_File->start() /project/vendor/squizlabs/php_codesniffer/CodeSniffer.php:1460
PHP   7. PSR2_Sniffs_Namespaces_NamespaceDeclarationSniff->process() /project/vendor/squizlabs/php_codesniffer/CodeSniffer/File.php:506
PHP Notice:  Undefined offset: 9 in /project/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PSR2/Sniffs/Namespaces/NamespaceDeclarationSniff.php on line 68

Open and close tag on same line can cause a PHP notice checking scope indent

We are getting a lot of notifications like this one, although the file we are sniffing has not violations in it.

Notice: Undefined index: 609 in CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php on line 392

We are using latest dev build of phpcs:

$ ./vendor/bin/phpcs --version
PHP_CodeSniffer version 2.0.0RC4 (beta) by Squiz (http://www.squiz.net)

Error with Magento-CodeSniffer

Hi, I use a Magento CodeSniffer extending your.
=> xxxxx

Here are the error I have in PHPStorm when using it.
Can you fix your document to check if the key exist in the array?

Cordially.

Automated way for creating ".fixed" files for unit tests

Not sure if that would be helpful to all, but for me it was crucial to quickly create .fixed files for every test fixture to assert in real time how my code fixing is going. So I created this: https://github.com/aik099/CodingStandard/blob/master/phpcs-validate.sh#L14-L27

I invoke script like this phpcs-validate.sh Classes.ClassDeclaration diff and then following happens:

  1. the test fixture files are located using standard notation (add UnitTest instead of Sniff to class end and look for what's matched)
  2. execute "diff" report for each of them
  3. save diff report in a patch file
  4. apply patch file (the original fixtures will be changed)
  5. copy each fixture file into ".fixed" file
  6. reverse apply patch

This way you not only can clearly see how good fixing code of each sniff is, but also to automatically ensure that code is fixed as needed next time regular regular check using that standard is made.

P.S.
Maybe some parts of that script can be improved using phpcbf instead of phpcs, because it can apply diff it creates automatically. But then how do I reverse apply the diff if I don't have it.

[master] DisallowSpaceIndentSniff + "tab_width=4"

When tab_width config option (or command line argument) is used, then each tab is converted to 4 spaces. In PHPCS 1.5.x this results in every sniff, that is looking specifically for TABs will fail, including DisallowSpaceIndentSniff.

In PHPCS 2.x version of that sniff this is fixed, because orig_content is used for checks, which still has TABs.

I wonder how safe it is to use tab_width option for projects, where TABs are used for indentation. I though it's main purpose was to help projects where indentation is done with spaces to deal with accidentally found TABs. Am I right?

Show not fixed violations during test run

After running coding standard tests you might get following message:

Failed to fix 2 fixable violations in <filename.inc>

This tells, that some of the sniffs that can fix an a reported problem failed to do so. However this message isn't pretty helpful, because it doesn't show which sniffs exactly and which errors within them failed to be fixed.

Listing failed sniff codes below that message will help a lot.

Best practice for abstract classes

The test code is:

<?php
namespace CameraLife;
require_once './schemaupdater.inc';

class SchemaUpdater1 extends SchemaUpdater
...

Where ./schemaupdater.inc defines an abstract class and has no side effects. I would argue that this is confirming code. The following error is produced which assumes incorrectly that the included file causes side effects.

FILE: /var/www/html/cameralife/setup/upgrade/schemaupdater1.inc
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------
 1 | WARNING | A file should declare new symbols (classes, functions,
   |         | constants, etc.) and cause no other side effects, or it should
   |         | execute logic with side effects, but should not do both. The
   |         | first symbol is defined on line 5 and the first side effect is
   |         | on line 3.
--------------------------------------------------------------------------------

How to supply a list of forbidden functions (Generic.PHP.ForbiddenFunctions)

I can't figure out how to provide a custom list of forbidden functions. I'm not sure if it's even possible, given that the $forbiddenFunctions property is protected. But the doc block says: "Can be used to forbid the use of any function." so perhaps I'm just doing something wrong.

I am using the following command:

$ phpcs -l -p src\lib --extensions=php --standard=phpcs.xml

And phpcs.xml looks like this:

<?xml version="1.0"?>
<ruleset name="Custom Standard">
    <description>Test Coding Standard</description>

    <rule ref="Generic.PHP.ForbiddenFunctions">
        <properties>
            <property name="forbiddenFunctionNames" type="array" value="eval,system,phpinfo"/>
        </properties>
    </rule>

</ruleset>

The error message is:

PHP Fatal error:  Cannot access protected property Generic_Sniffs_PHP_ForbiddenFunctionsSniff::$forbiddenFunctionNames

[phpcs-fixer] Diff in error is inverted

When fixing wasn't performed as defined in *.fixed file, then a diff is shown. However that diff is inverted: the actual fixed file is compared to expected fixed file, but it should be otherwise.

Expected file

<?php
$a = new \SomeNS\SomeClass();
$a = (new \SomeNS\SomeClass())->something();
$b = new \SomeNS\SomeClass();

Actual file

<?php
$a = new \SomeNS\SomeClass();
$a = (new \SomeNS\SomeClass())->something();
$b = new \SomeNS\SomeClass ();

Diff

--- CodingStandard/Tests/Classes/ClassCreateInstanceUnitTest.inc.fixed
+++ PHP_CodeSniffer
@@ -1,4 +1,4 @@
 <?php
 $a = new \SomeNS\SomeClass();
 $a = (new \SomeNS\SomeClass())->something();
-$b = new \SomeNS\SomeClass();
+$b = new \SomeNS\SomeClass ();

As you can see the row with + is adding space before parenthesis, while in fixed file the space is absent.

I think the diff should show what's missing between expected and actual file and not what needs to be changed to break file.

Make "callable" typehint optional

Right now (I'm not sure which sniff) tells, that if I have callable type hint in method's PHPDoc, then I also must add it to the method declaration. However following that advice will make code incompatible with PHP 5.3 and below.

Allow ScopeIndentSniff to check for and fix tab-based indent rules

The Generic_Sniffs_WhiteSpace_ScopeIndentSniff sniff indents the code (during auto-fixing process) using spaces and there is now way to configure it to use TABs instead.

When we're talking about finding errors in indentation-aware sniffs, then setting indent sniff parameter from 4 to 1 allowed to use TAB chars.

However, when auto-fixing comes in it's a different story, because we explicitly need to specify to PHP_CodeSniffer somewhere (or on per-sniff basis) what indentation sequence is ("4 spaces" or "1 tab").

This creates problems for example in WordPress/WordPress-Coding-Standards#247 (comment) task (see video).

Here is the line when 1 space as indentation unit is hardcoded: https://github.com/squizlabs/PHP_CodeSniffer/blob/phpcs-fixer/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php#L269

[--runtime-set key value] not working

Hi there,
I use PHPCS with the notation [--runtime-set key value], but the standart is not taken and it is the default one (PEAR).
To fix it, I have to call the key directly with '--' witch is ok, but I would like to report it,
maybe it should be taken anyway since it was add in the 1.5.1, or send back a error if it usefull.
Not working: (work but not use my standart seem's to use the default one)
phpcs --runtime-set encoding utf-8 --runtime-set tab_width 4 --runtime-set standard PSR2 ../bouncer/configuration.php

Working:
phpcs --encoding=utf-8 --tab-width=4 --standard=PSR2 ../bouncer/configuration.php

I use :
PHP_CodeSniffer version 1.5.3 (stable) by Squiz (http://www.squiz.net)

Sorry if it was already answered, but I didn't find it.

Regards,
Guillaume Seren.

Attempt to set a config value without argument throws an exception

This is the command I've used: phpcs --config-set tab_width (missing actual tab width).
The error I've got:

PHP Notice:  Undefined offset: 3 in /usr/local/lib/php/PHP/CodeSniffer/CLI.php on line 314
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phpcs:0
PHP   2. PHP_CodeSniffer_CLI->process($values = *uninitialized*) /usr/local/bin/phpcs:37
PHP   3. PHP_CodeSniffer_CLI->getCommandLineValues() /usr/local/lib/php/PHP/CodeSniffer/CLI.php:526
PHP   4. PHP_CodeSniffer_CLI->processLongArgument($arg = 'config-set', $pos = 1, $values = array ('files' => array (), 'standard' => NULL, 'verbosity' => 0, 'interactive' => FALSE, 'explain' => FALSE, 'local' => FALSE, 'showSources' => FALSE, 'extensions' => array (), 'sniffs' => array (), 'ignored' => array (), 'reportFile' => NULL, 'generator' => '', 'reports' => array (), 'errorSeverity' => NULL, 'warningSeverity' => NULL, 'tabWidth' => 4, 'encoding' => 'iso-8859-1', 'reportWidth' => 80, 'showProgress' => FALSE)) /usr/local/lib/php/PHP/CodeSniffer/CLI.php:205

What I thought is possible is to remove config value completely by not giving it any argument.

Report warnings but return a zero exit code

I want to report to console/checkstyle any warnings, but I do not want the exit code to be > 0. Currently warnings are returning a 1.

All I could find was suppressing but this means nothing is output.

ScopeIndentSniff hangs when processing nested closures

This ruleset with the below php file hangs and consumes 100% CPU.
The phpcs commit is 995d6e9

<?xml version="1.0"?>
<!DOCTYPE ruleset SYSTEM "ruleset.dtd">
<ruleset name="mine">
 <rule ref="Generic.WhiteSpace.ScopeIndent" />
</ruleset>
<?php function(){return function(){};}

The last lines from calling phpcs with -vvv

        *** START TOKEN PROCESSING ***
                Process token 0: T_OPEN_TAG => <?php·
                        Processing Generic_Sniffs_WhiteSpace_ScopeIndentSniff...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.