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

Overview

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.

Comments
  • PSR12 standard

    PSR12 standard

    I know this might be a bit too early as the Extended Coding Style Guide is still on Draft phase but IMO having early access to what could be the standard in the end could be helpful

    What anyone else think about this?

    Enhancement 
    opened by juliangut 61
  • RuntimeException: Undefined variable: childOutput in squizlabs/php_codesniffer/src/Runner.php on line 705

    RuntimeException: Undefined variable: childOutput in squizlabs/php_codesniffer/src/Runner.php on line 705

    • phpcs version : 3.3.2
    • php version: 7.2 and 7.3
    • operating system: osx

    Description

    I get this exception when i run phpcs using a parallel value greater than 1

    Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined variable: childOutput in /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php on line 705 in /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php:562
    Stack trace:
    #0 /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(705): PHP_CodeSniffer\Runner->handleErrors(8, 'Undefined varia...', '/Users/yoeunes/...', 705, Array)
    #1 /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(502): PHP_CodeSniffer\Runner->processChildProcs(Array)
    #2 /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()
    #3 /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
    #4 {main}
      thrown in /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php on line 562
    

    this is my phpcs.xml file:

    <?xml version="1.0"?>
    <ruleset name="coding standard">
        <description>coding standard</description>
    
        <arg name="extensions" value="php"/>
        
        <arg name="parallel" value="2"/>
    
        <file>src</file>
    
        <rule ref="PSR2" />
    
    </ruleset>
    
    opened by yoeunes 52
  • Selectively disable rules with codingStandardsIgnoreStart and codingStandardsIgnoreLine

    Selectively disable rules with codingStandardsIgnoreStart and codingStandardsIgnoreLine

    PHPCS supports comment directives like:

    // @codingStandardsIgnoreFile
    // @codingStandardsIgnoreStart
    // @codingStandardsIgnoreLine
    

    However, these are all or nothing. What would be even more useful is if we can selectively ignore certain sniffs or errors within sniffs. For instance:

    $q = new WP_Query( array(
        'posts_per_page' => 200, // @codingStandardsIgnoreLine WordPress.VIP.SlowDBQuery.slow_db_query 
    ) );
    

    or

    // @codingStandardsIgnoreStart WordPress.VIP.SlowDBQuery.slow_db_query
    $q = new WP_Query( array(
        'posts_per_page' => 200,
    ) );
    // @codingStandardsIgnoreEnd WordPress.VIP.SlowDBQuery.slow_db_query
    

    This draws inspiration from JSCS and its directives like:

    //jscs:disable requireCamelCaseOrUpperCaseIdentifiers
    

    We have this in the WordPress-Coding-Standards project in a sniff-specific ad hoc system of end-of-statement comments:

    echo $foo; // xss ok
    

    Which suppresses the WordPress.XSS.EscapeOutput sniff. But it would be very useful if this was standardized in PHPCS itself and available to all sniffs

    Enhancement High Priority 
    opened by westonruter 34
  •  Version 2.3.2: PHP Notice:  Undefined index:  in /usr/share/pear/PHP/CodeSniffer/File.php

    Version 2.3.2: PHP Notice: Undefined index: in /usr/share/pear/PHP/CodeSniffer/File.php

    Hello,

    running phpcs against a folder of php site, I have a huge number of this: PHP Notice: Undefined index: in /usr/share/pear/PHP/CodeSniffer/File.php on line 3476 PHP Notice: Undefined index: in /usr/share/pear/PHP/CodeSniffer/File.php on line 3464 (always same 2 lines in loop) on Centos 7.1, latest yum update

    command line: phpcs -d memory_limit=512M /path/to/folder nothing changhed in phpcs, just installed it 10mn ago

    opened by mathieuchateau 33
  • Refactor suggestion / move utility functions from File to static classes

    Refactor suggestion / move utility functions from File to static classes

    Since PHPCS 3.x now has a minimum PHP requirement of PHP 5.4, I was wondering whether it might be an idea to refactor a number of groups of methods in the File class to traits.

    The reasoning behind this is two-fold:

    1. Only a limited number of sniffs use the methods I have in mind for this, so having them in traits rather than in the File class makes the re-useable code more modular and easier to maintain.
    2. Over the years I have written a number of additional token walking utility methods which I think belong in PHPCS rather than in the WPCS/PHPCompatibility standards in which they now live. Traits would allow for these methods to be added to PHPCS more easily without making the File class even larger than it already is.

    Timing

    The transition could be made in PHPCS 3.x. In PHPCS 3.x, the File class would in that case use the new traits and for the transitioned methods just call the method in the trait under the hood. The methods in the File class would be deprecated and could be removed in PHPCS 4.x. This would allow external standards some time to implement the new way of doing things and make the BC break in PHPCS 4.x smaller as it can already be mitigated beforehand.

    Proposal details

    To be concrete, I'm currently thinking of the following Traits:

    • DeclarationName, containing:
      • getName(), previously called getDeclarationName()
    • FunctionDeclaration, containing:
      • getParameters(), previously called getMethodParameters()
      • getProperties(), previously called getMethodProperties()
      • and using DeclarationName for the getName() method
    • PropertyDeclaration, containing:
      • getMemberProperties()
    • ObjectDeclaration containing:
      • getClassProperties()
      • findExtendedClassName()
      • findImplementedInterfaceName()
      • findExtendedInterfaceNames() - open PR #2128
      • and using DeclarationName for the getName() method
    • Generic containing:
      • isReference()
    • ScopeConditions, containing:
      • hasCondition()
      • getCondition()

    Additionally, I'd be happy to pull the following based on battle-tested code I've written for WPCS/PHPCompatibility:

    • FunctionCall, containing:
      • hasParameters()
      • getParameterCount()
      • getParameters()
      • getParameter() (to get the details for the parameter at a specific position) These methods all work on both function calls as well as for splitting an array into the individual items and could be extended to cover isset(), unset() and list() as well.
    • And if there would be any interest in it - FQClassNames, containing:
      • getNameFromNewToken()
      • getNameFromDoubleColonToken()
      • getExtendedName()
      • getFQName()
      • isNamespaced()
      • determineNamespace()
      • getDeclaredNamespaceName()

    For the Generic trait, I could also offer an additional isShortList() method.

    I'm also still working on the logic for a TStringAnalyser which should reliably determine whether, for instance, a T_STRING token represents a function call, the use of a global constant or for instance a use statement alias.

    Open questions

    What I'd currently like to know, is:

    • Does the principle of this sound like a good idea for PHPCS ?
    • If so, does the implementation proposal for PHPCS 3.x/4.x sound like a good idea ?
    • If so, where should the traits live ? I.e. , should they be placed in a dedicated Traits directory or, for instance, in Util/Traits or should the directory be called something completely different ?
    • If so, feedback on the proposed initial Traits as outline above (trait names, function groupings etc)
    • And would there be interest in the additional traits/methods as outlined above ?
    opened by jrfnl 32
  • PHP 7 return type tokenize

    PHP 7 return type tokenize

    In PHP 7 we can declare return type for method:

    function m() : int {
    }
    

    In this case "int" is tokenized as T_RETURN_TYPE and it's fine.

    We can also declare there complex type:

    function n() : \MyNamespace\MyClass {
    }
    

    and in the second case I think it is wrong tokenized, because we have there:

    • \ - T_NS_SEPARATOR
    • MyNamespace - T_STRING
    • \ - T_NS_SEPARATOR
    • MyClass - T_RETURN_TYPE

    so we have 4 tokens, but I would expect only one: T_RETURN_TYPE with content \MyNamespace\MyClass. What do you think?

    Enhancement 
    opened by michalbundyra 32
  • Caching between runs for better performance

    Caching between runs for better performance

    First let me thank you for this great tool. :+1:

    I've been using this on my PHP projects, and I've found that it can take a while to sniff the code, especially on larger projects with complex configurations. Performance will naturally be determined largely by how well the sniffs used are written. However, I think that performance could be increased by caching the hash signatures of the files being sniffed. Then only those files which have changes since the last sniff was conducted would need to be sniffed (there are some caveats which I'll get to in a moment). This wouldn't improve the performance of the initial sniffing (and might even degrade it slightly), but would drastically improve performance for latter sniffings.

    As I noted above, there are some caveats:

    • The cache needs to be invalidated when the configuration changes. This would be when the XML config file is edited, for example, and possibly at other times as well. This could be facilitated by saving a hash signature of these configuration settings to the cache, and checking whether this matches the current configuration when the cache is being loaded.
    • If a file has errors, the errors still need to get reported on subsequent sniffings even if the file hasn't changed. This could be done by not caching files with errors, or by caching a list of the errors found and replaying them to the user without sniffing those files.

    There are probably other things I haven't thought of, maybe regarding interactive mode, reports, or automatic fixing, all of which I am unfamiliar with. And there would probably need to be an easy way for the user to bypass the cache as needed.

    There are probably also other things that could be cached between runs on a project as well.

    Exactly how the cache is saved is up to you. I was thinking of a .phpcs-cache in the root of the project being sniffed that would contain the cache represented as a JSON object.

    If this is something that you think could be done, I'd be happy to work up a PR if you'll give me a little guidance on how you'd like this implemented.

    Enhancement 
    opened by JDGrimes 32
  • composer.json + required changes

    composer.json + required changes

    This is all I had to do to get composer.json working. Please review the changes. I am curious to hear what we could do about the placeholders that pear's package.xml normally takes care of.

    This is the composer.json I used in one of my projects (so it pertains to the project dependencies, not a configuration for codesniffer itself):

    # cat composer.json 
    {
        "repositories": [
            {
                "type": "git",
                "url": "https://github.com/alcohol/PHP_CodeSniffer"
            }
        ],  
        "require": {
            "phpunit/phpunit": "*",
            "phpunit/dbunit": "*",
            "phpmd/phpmd": "*",
            "behat/behat": "*",
            "squizlabs/phpcs": "*",
            "kriswallsmith/buzz": "*"
        },
        "minimum-stability": "dev",
        "config": {
            "bin-dir": "bin/"
        }
    }
    

    I imagine the repositories property will no longer be required once you sign up @ packagist.org

    opened by alcohol 32
  • Add PHPStan

    Add PHPStan

    Hi, are you interested in adding PHPStan to your pipeline?

    In this I added phpstan to your pipeline and fixed some issues (mostly in phpdoc). Some of reported issues are not fixed yet and I would like to fix it with your help. In current state there is completely ignored error about not initialized variables.

    opened by adaamz 30
  • PHPCS freezes in an infinite loop under Windows if no standard is passed

    PHPCS freezes in an infinite loop under Windows if no standard is passed

    Although 2.4.0 still works, 2.5.0 and 2.5.1 run from the CLI under Windows freeze in an infinite loop with the CPUs at 50%. The test environment is Windows 10 64-bit, PHP 7.0.1 64-bit, but a small bit of experimenting indicates that's not important.

    Bug 
    opened by hardcover 30
  • Tokenizer: add support for PHP8 attributes

    Tokenizer: add support for PHP8 attributes

    I tried to add PHP8 attributes parsing functionalities in PHP tokenizer. Hope this could help completing PHP8 support on this great project.

    PS: Since its my first PR here, please indicate me if there's something wrong with it. Thanks

    opened by alekitto 28
  • Unsealed array shapes false positive error for Squiz.Commenting.FunctionComment.MissingParamTag and Squiz.Commenting.FunctionComment.MissingParamName

    Unsealed array shapes false positive error for Squiz.Commenting.FunctionComment.MissingParamTag and Squiz.Commenting.FunctionComment.MissingParamName

    Describe the bug Unsealed array shapes (https://psalm.dev/docs/annotating_code/type_syntax/array_types/#:~:text=theory%20perspective.-,Unsealed%20array%20and%20list%20shapes,-Starting%20from%20Psalm) create a false positive error with these rules:

    • Squiz.Commenting.FunctionComment.MissingParamName
    • Squiz.Commenting.FunctionComment.MissingParamTag

    Code sample

    	/**
    	 * do something
    	 *
    	 * @param array{foo: string, bar: string, ...} $data some data
    	 *
    	 * @return array<string, string>
    	 */
    	function foo( $data ) {}
    

    To reproduce Steps to reproduce the behavior:

    1. Create a file called test.php with the code sample above
    2. Run phpcs test.php ...
    3. See error message displayed
    Doc comment for parameter "$data" missing
    Missing parameter name
    

    Expected behavior No error.

    Versions (please complete the following information):

    • OS: RHEL 8
    • PHP: 7.4
    • PHPCS: master
    • Standard: Squiz
    opened by kkmuffme 0
  • Updating the documentation (demo included)

    Updating the documentation (demo included)

    One of the main issues for anyone to start using PHPCS (myself included) is the lack of documentation. When I started using a couple of years it was a very difficult task to implement it. I am using it with VSCode so I had to google for many hours/days to get it finally working.

    Documentation is available for many parts of the script, but it is:

    • Not comprehensive: many areas require further clarification/updating like sniffs.
    • Not organized: it is hard for a begginer to find where/how to start using it.

    I realize it is something have been discussed previously and the direction chosen by @gsherwood is to make the docs external and not use xml.

    Since I extensively use ESLint rules in my projects, I thought something similar might be achievable for PHPCS.

    So, using various sources (wiki, xml docs, phpdoc in sniffs) I built this documentation using vitepress. It is not complete and needs more work to make it production ready but I think it is a start.

    Some examples from the demo:

    Using vitepress has many advantages over using GitHub wiki, for example:

    • I think the UI (and in turn the UX) is much easier to navigate.
    • Link to GitHub to edit a particular page.
    • Responsive.
    • Dark theme.

    Like many developers of open source, the maintainers of this project is busy with work/life/personal stuff ... etc. I think that the documentation will make it easier to attract developers who otherwise are turned off by spending hours aimlessly trying to figure out how to run a simple command.

    The documentation repo is available here: https://github.com/kalimah-apps/phpcs_docs

    opened by kalimah-apps 0
  • PHP 8.2 - DNF Support

    PHP 8.2 - DNF Support

    Describe the bug DNF in properties and as return types creates spurious formatting errors

    Code sample

    <?php
    
    declare(strict_types=1);
    
    namespace Test;
    
    interface A
    {
        public function foo(): void;
    }
    interface B
    {
        public function bar(): void;
    }
    
    class C implements A, B
    {
        public function foo(): void
        {
            echo 'foo';
        }
        public function bar(): void
        {
            echo 'bar';
        }
    }
    
    class Dnf
    {
        protected (A&B)|null $property;
    
        public function getProperty(): (A&B)|null
        {
            return $this->property;
        }
    }
    
    
    

    To reproduce Steps to reproduce the behavior:

    1. Create a file called test.php with the code sample above...
    2. Run phpcs test.php ...
    3. See error message displayed
    FILE: test.php
    -------------------------------------------------------------------------------------------------------
    FOUND 12 ERRORS AFFECTING 5 LINES
    -------------------------------------------------------------------------------------------------------
     11 | ERROR | [ ] Each interface must be in a file by itself
     16 | ERROR | [ ] Each interface must be in a file by itself
     28 | ERROR | [ ] Each class must be in a file by itself
     30 | ERROR | [x] Expected at least 1 space before "&"; 0 found
     30 | ERROR | [x] Expected at least 1 space after "&"; 0 found
     30 | ERROR | [x] Expected at least 1 space before "|"; 0 found
     30 | ERROR | [x] Expected at least 1 space after "|"; 0 found
     32 | ERROR | [ ] There must be a single space between the colon and type in a return type declaration
     32 | ERROR | [x] Expected at least 1 space before "&"; 0 found
     32 | ERROR | [x] Expected at least 1 space after "&"; 0 found
     32 | ERROR | [x] Expected at least 1 space before "|"; 0 found
     32 | ERROR | [x] Expected at least 1 space after "|"; 0 found
    -------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 8 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------
    

    Expected behavior Ignoring the "each interface/class must be in a file by itself" all the rest of the errors marked are NOT errors and definitely should not be autocorrecting

    The single space between colon and type declaration doesn't apparently recognize the parentheses () as part of the type declaration

    Versions (please complete the following information):

    • OS: all
    • PHP: 8.2
    • PHPCS: version 4.0.0 (alpha)
    • Standard: PSR12
    opened by auroraeosrose 4
  • PSR12 / There must be 1 space after the property type

    PSR12 / There must be 1 space after the property type

    Describe the bug

    Code sample

    class test 
    {
        public FlightHeader  $flight_header;
        public Carbon        $flight_date;
        public BookingNumber $booking_number;
    }
    

    Custom ruleset

    <?xml version="1.0"?>
    <ruleset name="schauinsland" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
        <rule ref="PSR12"/>
        <rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"/>
        <rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps"/>
        <rule ref="Squiz.NamingConventions.ValidVariableName.StringNotCamelCaps"/>
        <rule ref="Generic.Arrays.DisallowLongArraySyntax">
            <type>warning</type>
        </rule>
        <rule ref="Generic.PHP.ForbiddenFunctions">
            <properties>
                <property name="forbiddenFunctions" type="array">
                    <element key="sizeof" value="count"/>
                    <element key="delete" value="unset"/>
                    <element key="print" value="echo"/>
                    <element key="create_function" value="null"/>
                </property>
            </properties>
        </rule>
    
        <exclude-pattern>/vendor/</exclude-pattern>
    </ruleset>
    

    To reproduce

     11 | ERROR | [x] There must be 1 space after the property type
        |       |     declaration; 2 found
     12 | ERROR | [x] There must be 1 space after the property type
        |       |     declaration; 8 found
    

    Expected behavior no error

    Reason The PSR12 does not disalow multiple spaces after the declaration:

    There MUST be a space between type declaration and property name.

    it just says there must be a space, not one space

    opened by Phillip85 0
  • Does not work with readonly classes introduced in PHP 8.2

    Does not work with readonly classes introduced in PHP 8.2

    May be closed by ~#3686~ #3728

    Describe the bug In PHP 8.2, "readonly class" feature was introduced. Using readonly classes, we can shorten readonly property declarations as follows:

    class Foo {
        public function __construct(
            private readonly string $foo,
            private readonly int $bar,
        ) {
        }
    }
    

    equals to:

    readonly class Foo {
        public function __construct(
            private string $foo,
            private string $bar,
        ) {
        }
    }
    

    However, the latest version of phpcs v3.7.1 does not work on the classes which are marked as "readonly". (The phpcs error output is in "To reproduce" section)

    Code sample

    readonly class Foo {
        public function __construct(
            private string $foo,
            private string $bar,
        ) {
        }
    }
    

    Custom ruleset N/A

    To reproduce Steps to reproduce the behavior:

    1. Run phpcs with the default ruleset, with the code sample above.
    FILE: /project/Foo.php
    ----------------------------------------------------------------------
    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 13
       |         | and the first side effect is on line 13.
       |         | (PSR1.Files.SideEffects.FoundWithSymbols)
    ----------------------------------------------------------------------
    

    Expected behavior A clear and concise description of what you expected to happen.

    Versions (please complete the following information):

    • OS: macOS Ventura 13.0.1 (Apple M1 Max; aarch64-apple-darwin)
    • PHP: 8.2.0
    • PHPCS: 3.7.1
    • Standard: PSR12

    Additional context N/A

    opened by siketyan 2
Releases(3.7.1)
  • 3.7.1(Jun 18, 2022)

  • 3.7.0(Jun 13, 2022)

    PHP 8.1 Language Feature Support

    PHP_CodeSniffer has run correctly under PHP 8.1 since PHP 8 support was added, but it has not supported new 8.1 language features until this release. Version 3.7.0 adds support for the following PHP 8.1 language features:

    • Enums
    • Explicit octal notation
    • Readonly properties
    • Intersection types
    • The never type

    Note: Standards and sniffs included with PHP_CodeSniffer have been updated to support these language features, but external standards and sniffs may need updating before they are able to detect them correctly.

    Changelog

    • Added support for PHP 8.1 explicit octal notation
      • This new syntax has been backfilled for PHP versions less than 8.1
      • Thanks to Mark Baker (@MarkBaker) for the patch
      • Thanks to Juliette Reinders Folmer (@jrfnl) for additional fixes
    • Added support for PHP 8.1 enums
      • This new syntax has been backfilled for PHP versions less than 8.1
      • Includes a new T_ENUM_CASE token to represent the case statements inside an enum
      • Thanks to Jaroslav Hanslík (@kukulich) for the patch
      • Thanks to Juliette Reinders Folmer (@jrfnl) for additional core and sniff support
    • Added support for the PHP 8.1 readonly token
      • Tokenzing of the readonly keyword has been backfilled for PHP versions less than 8.1
      • Thanks to Jaroslav Hanslík (@kukulich) for the patch
    • Added support for PHP 8.1 intersection types
      • Includes a new T_TYPE_INTERSECTION token to represent the ampersand character inside intersection types
      • Thanks to Jaroslav Hanslík (@kukulich) for the patch
    • File::getMethodParameters now supports the new PHP 8.1 readonly token
      • When constructor property promotion is used, a new property_readonly array index is included in the return value
        • This is a boolean value indicating if the property is readonly
      • If the readonly token is detected, a new readonly_token array index is included in the return value
        • This contains the token index of the readonly keyword
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Support for new PHP 8.1 readonly keyword has been added to the following sniffs:
      • Generic.PHP.LowerCaseKeyword
      • PSR2.Classes.PropertyDeclaration
      • Squiz.Commenting.BlockComment
      • Squiz.Commenting.DocCommentAlignment
      • Squiz.Commenting.VariableComment
      • Squiz.WhiteSpace.ScopeKeywordSpacing
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patches
    • The parallel feature is now more efficient and runs faster in some situations due to improved process management
      • Thanks to Sergei Morozov (@morozov) for the patch
    • The list of installed coding standards now has consistent ordering across all platforms
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Generic.PHP.UpperCaseConstant and Generic.PHP.LowerCaseConstant now ignore type declarations
      • These sniffs now only report errors for true/false/null when used as values
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Generic.PHP.LowerCaseType now supports the PHP 8.1 never type
      • Thanks to Jaroslav Hanslík (@kukulich) for the patch
    • Fixed bug #3502 : A match statement within an array produces Squiz.Arrays.ArrayDeclaration.NoKeySpecified
    • Fixed bug #3503 : Squiz.Commenting.FunctionComment.ThrowsNoFullStop false positive when one line @throw
    • Fixed bug #3505 : The nullsafe operator is not counted in Generic.Metrics.CyclomaticComplexity
      • Thanks to Mark Baker (@MarkBaker) for the patch
    • Fixed bug #3526 : PSR12.Properties.ConstantVisibility false positive when using public final const syntax
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Fixed bug #3530 : Line indented incorrectly false positive when using match-expression inside switch case
    • Fixed bug #3534 : Name of typed enum tokenized as T_GOTO_LABEL
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Fixed bug #3546 : Tokenizer/PHP: bug fix - parent/static keywords in class instantiations
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Fixed bug #3550 : False positive from PSR2.ControlStructures.SwitchDeclaration.TerminatingComment when using trailing comment
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Fixed bug #3575: Squiz.Scope.MethodScope misses visibility keyword on previous line
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Fixed bug #3604: Tokenizer/PHP: bug fix for double quoted strings using ${
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.32 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.32 MB)
    phpcs.phar.asc(587 bytes)
  • 3.6.2(Dec 12, 2021)

    • Processing large code bases that use tab indenting inside comments and strings will now be faster
      • Thanks to Thiemo Kreuz (@thiemowmde) for the patch
    • Fixed bug #3388 : phpcs does not work when run from WSL drives
      • Thanks to Juliette Reinders Folmer (@jrfnl) and Graham Wharton (@gwharton) for the patch
    • Fixed bug #3422 : Squiz.WhiteSpace.ScopeClosingBrace fixer removes HTML content when fixing closing brace alignment
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Fixed bug #3437 : PSR12 does not forbid blank lines at the start of the class body
      • Added new PSR12.Classes.OpeningBraceSpace sniff to enforce this
    • Fixed bug #3440 : Squiz.WhiteSpace.MemberVarSpacing false positives when attributes used without docblock
      • Thanks to Vadim Borodavko (@javer) for the patch
    • Fixed bug #3448 : PHP 8.1 deprecation notice while generating running time value
      • Thanks to Juliette Reinders Folmer (@jrfnl) and Andy Postnikov (@andypost) for the patch
    • Fixed bug #3456 : PSR12.Classes.ClassInstantiation.MissingParentheses false positive using attributes on anonymous class
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Fixed bug #3460 : Generic.Formatting.MultipleStatementAlignment false positive on closure with parameters
      • Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
    • Fixed bug #3468 : do/while loops are double-counted in Generic.Metrics.CyclomaticComplexity
      • Thanks to Mark Baker (@MarkBaker) for the patch
    • Fixed bug #3469 : Ternary Operator and Null Coalescing Operator are not counted in Generic.Metrics.CyclomaticComplexity
      • Thanks to Mark Baker (@MarkBaker) for the patch
    • Fixed bug #3472 : PHP 8 match() expression is not counted in Generic.Metrics.CyclomaticComplexity
      • Thanks to Mark Baker (@MarkBaker) for the patch
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(2.39 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(2.39 MB)
    phpcs.phar.asc(587 bytes)
  • 3.6.1(Oct 11, 2021)

    • PHPCS annotations can now be specified using hash-style comments
      • Previously, only slash-style and block-style comments could be used to do things like disable errors
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed an issue where some sniffs would not run on PHP files that only used the short echo tag
      • The following sniffs were affected:
        • Generic.Files.ExecutableFile
        • Generic.Files.LowercasedFilename
        • Generic.Files.LineEndings
        • Generic.Files.EndFileNewline
        • Generic.Files.EndFileNoNewline
        • Generic.PHP.ClosingPHPTag
        • Generic.PHP.Syntax
        • Generic.VersionControl.GitMergeConflict
        • Generic.WhiteSpace.DisallowSpaceIndent
        • Generic.WhiteSpace.DisallowTabIndent
      • Thanks to Juliette Reinders Folmer for the patch
    • The new PHP 8.1 tokenisation for ampersands has been reverted to use the existing PHP_CodeSniffer method
      • The PHP 8.1 tokens T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG and T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG are unsued
      • Ampersands continue to be tokenized as T_BITWISE_AND for all PHP versions
      • Thanks to Juliette Reinders Folmer and Anna Filina for the patch
    • File::getMethodParameters() no longer incorrectly returns argument attributes in the type hint array index
      • A new has_attributes array index is available and set to TRUE if the argument has attributes defined
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.NamingConventions.ConstructorName no longer throws deprecation notices on PHP 8.1
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Commenting.BlockComment now correctly applies rules for block comments after a short echo tag
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed false positives when using attributes in the following sniffs:
      • PEAR.Commenting.FunctionComment
      • Squiz.Commenting.InlineComment
      • Squiz.Commenting.BlockComment
      • Squiz.Commenting.VariableComment
      • Squiz.WhiteSpace.MemberVarSpacing
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3294 : Bug in attribute tokenization when content contains PHP end token or attribute closer on new line
      • Thanks to Alessandro Chitolina for the patch
      • Thanks to Juliette Reinders Folmer for the tests
    • Fixed bug #3296 : PSR2.ControlStructures.SwitchDeclaration takes phpcs:ignore as content of case body
    • Fixed bug #3297 : PSR2.ControlStructures.SwitchDeclaration.TerminatingComment does not handle try/finally blocks
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3302 : PHP 8.0 | Tokenizer/PHP: bugfix for union types using namespace operator
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3303 : findStartOfStatement() doesn't work with T_OPEN_TAG_WITH_ECHO
    • Fixed bug #3316 : Arrow function not tokenized correctly when using null in union type
    • Fixed bug #3317 : Problem with how phpcs handles ignored files when running in parallel
      • Thanks to Emil Andersson for the patch
    • Fixed bug #3324 : PHPCS hangs processing some nested arrow functions inside a function call
    • Fixed bug #3326 : Generic.Formatting.MultipleStatementAlignment error with const DEFAULT
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3333 : Squiz.Objects.ObjectInstantiation: null coalesce operators are not recognized as assignment
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3340 : Ensure interface and trait names are always tokenized as T_STRING
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3342 : PSR12/Squiz/PEAR standards all error on promoted properties with docblocks
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3345 : IF statement with no braces and double catch turned into syntax error by auto-fixer
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3352 : PSR2.ControlStructures.SwitchDeclaration can remove comments on the same line as the case statement while fixing
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3357 : Generic.Functions.OpeningFunctionBraceBsdAllman removes return type when additional lines are present
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3362 : Generic.WhiteSpace.ScopeIndent false positive for arrow functions inside arrays
    • Fixed bug #3384 : Squiz.Commenting.FileComment.SpacingAfterComment false positive on empty file
    • Fixed bug #3394 : Fix PHP 8.1 auto_detect_line_endings deprecation notice
    • Fixed bug #3400 : PHP 8.1: prevent deprecation notices about missing return types
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3424 : PHPCS fails when using PHP 8 Constructor property promotion with attributes
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3425 : PHP 8.1 | Runner::processChildProcs(): fix passing null to non-nullable bug
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3445 : Nullable parameter after attribute incorrectly tokenized as ternary operator
      • Thanks to Juliette Reinders Folmer for the patch
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.26 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.26 MB)
    phpcs.phar.asc(587 bytes)
  • 3.6.0(Apr 9, 2021)

    PHP 8 Language Feature Support

    PHP_CodeSniffer has run under PHP 8 for some time, but it has not supported all new language features until this release. Version 3.6.0 adds support for all new PHP 8 language features, including:

    • Attributes
    • Constructor property promotion
    • Named arguments
    • Union types
    • Match expressions
    • Static and Mixed return types

    Note: All standards and sniffs included with PHP_CodeSniffer have been updated to support these language features, but external standards and sniffs may need updating before they are able to detect them correctly.

    Changelog

    • Added support for PHP 8.0 union types
      • A new T_TYPE_UNION token is available to represent the pipe character
      • File::getMethodParameters(), getMethodProperties(), and getMemberProperties() will now return union types
      • Thanks to Juliette Reinders Folmer for the patch
    • Added support for PHP 8.0 named function call arguments
      • A new T_PARAM_NAME token is available to represent the label with the name of the function argument in it
      • Thanks to Juliette Reinders Folmer for the patch
    • Added support for PHP 8.0 attributes
      • The PHP-supplied T_ATTRIBUTE token marks the start of an attribute
      • A new T_ATTRIBUTE_END token is available to mark the end of an attribute
      • New attribute_owner and attribute_closer indexes are available in the tokens array for all tokens inside an attribute
      • Tokenizing of attributes has been backfilled for older PHP versions
      • The following sniffs have been updated to support attributes:
        • PEAR.Commenting.ClassComment
        • PEAR.Commenting.FileComment
        • PSR1.Files.SideEffects
        • PSR12.Files.FileHeader
        • Squiz.Commenting.ClassComment
        • Squiz.Commenting.FileComment
        • Squiz.WhiteSpace.FunctionSpacing
          • Thanks to Vadim Borodavko for the patch
      • Thanks to Alessandro Chitolina for the patch
    • Added support for PHP 8.0 dereferencing of text strings with interpolated variables
      • Thanks to Juliette Reinders Folmer for the patch
    • Added support for PHP 8.0 match expressions
      • Match expressions are now tokenised with parenthesis and scope openers and closers
        • Sniffs can listen for the T_MATCH token to process match expressions
        • Note that the case and default statements inside match expressions do not have scopes set
      • A new T_MATCH_ARROW token is available to represent the arrows in match expressions
      • A new T_MATCH_DEFAULT token is available to represent the default keyword in match expressions
      • All tokenizing of match expressions has been backfilled for older PHP versions
      • The following sniffs have been updated to support match expressions:
        • Generic.CodeAnalysis.AssignmentInCondition
        • Generic.CodeAnalysis.EmptyPHPStatement
          • Thanks to Vadim Borodavko for the patch
        • Generic.CodeAnalysis.EmptyStatement
        • Generic.PHP.LowerCaseKeyword
        • PEAR.ControlStructures.ControlSignature
        • PSR12.ControlStructures.BooleanOperatorPlacement
        • Squiz.Commenting.LongConditionClosingComment
        • Squiz.Commenting.PostStatementComment
        • Squiz.ControlStructures.LowercaseDeclaration
        • Squiz.ControlStructures.ControlSignature
        • Squiz.Formatting.OperatorBracket
        • Squiz.PHP.DisallowMultipleAssignments
        • Squiz.Objects.ObjectInstantiation
        • Squiz.WhiteSpace.ControlStructureSpacing
      • Thanks to Juliette Reinders Folmer for the patch
    • The value of the T_FN_ARROW token has changed from "T_FN_ARROW" to "PHPCS_T_FN_ARROW" to avoid package conflicts
      • This will have no impact on custom sniffs unless they are specifically looking at the value of the T_FN_ARROW constant
      • If sniffs are just using constant to find arrow functions, they will continue to work without modification
      • Thanks to Juliette Reinders Folmer for the patch
    • File::findStartOfStatement() now works correctly when passed the last token in a statement
    • File::getMethodParameters() now supports PHP 8.0 constructor property promotion
      • Returned method params now include a property_visibility and visibility_token index if property promotion is detected
      • Thanks to Juliette Reinders Folmer for the patch
    • File::getMethodProperties() now includes a return_type_end_token index in the return value
      • This indicates the last token in the return type, which is helpful when checking union types
      • Thanks to Juliette Reinders Folmer for the patch
    • Include patterns are now ignored when processing STDIN
      • Previously, checks using include patterns were excluded when processing STDIN when no file path was provided via --stdin-path
      • Now, all include and exclude rules are ignored when no file path is provided, allowing all checks to run
      • If you want include and exclude rules enforced when checking STDIN, use --stdin-path to set the file path
      • Thanks to Juliette Reinders Folmer for the patch
    • Spaces are now correctly escaped in the paths to external on Windows
      • Thanks to Juliette Reinders Folmer for the patch
    • Added Generic.NamingConventions.AbstractClassNamePrefix to enforce that class names are prefixed with "Abstract"
      • Thanks to Anna Borzenko for the contribution
    • Added Generic.NamingConventions.InterfaceNameSuffix to enforce that interface names are suffixed with "Interface"
      • Thanks to Anna Borzenko for the contribution
    • Added Generic.NamingConventions.TraitNameSuffix to enforce that trait names are suffixed with "Trait"
      • Thanks to Anna Borzenko for the contribution
    • Generic.CodeAnalysis.UnusedFunctionParameter can now be configured to ignore variable usage for specific type hints
      • This allows you to suppress warnings for some variables that are not required, but leave warnings for others
      • Set the ignoreTypeHints array property to a list of type hints to ignore
      • Thanks to Petr Bugyík for the patch
    • Generic.Formatting.MultipleStatementAlignment can now align statements at the start of the assignment token
      • Previously, the sniff enforced that the values were aligned, even if this meant the assignment tokens were not
      • Now, the sniff can enforce that the assignment tokens are aligned, even if this means the values are not
      • Set the alignAtEnd sniff property to false to align the assignment tokens
      • The default remains at true, so the assigned values are aligned
      • Thanks to John P. Bloch for the patch
    • Generic.PHP.LowerCaseType now supports checking of typed properties
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.PHP.LowerCaseType now supports checking of union types
      • Thanks to Juliette Reinders Folmer for the patch
    • PEAR.Commenting.FunctionComment and Squiz.Commenting.FunctionComment sniffs can now ignore private and protected methods
      • Set the minimumVisibility sniff property to protected to ignore private methods
      • Set the minimumVisibility sniff property to public to ignore both private and protected methods
      • The default remains at private, so all methods are checked
      • Thanks to Vincent Langlet for the patch
    • PEAR.Commenting.FunctionComment and Squiz.Commenting.FunctionComment sniffs can now ignore return tags in any method
      • Previously, only __construct and __destruct were ignored
      • Set the list of method names to ignore in the specialMethods sniff property
      • The default remains at __construct and __destruct only
      • Thanks to Vincent Langlet for the patch
    • PSR2.ControlStructures.SwitchDeclaration now supports nested switch statements where every branch terminates
      • Previously, if a CASE only contained a SWITCH and no direct terminating statement, a fall-through error was displayed
      • Now, the error is suppressed if every branch of the SWITCH has a terminating statement
      • Thanks to Vincent Langlet for the patch
    • The PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket error message is now reported on the closing parenthesis token
      • Previously, the error was being reported on the function keyword, leading to confusing line numbers in the error report
    • Squiz.Commenting.FunctionComment is now able to ignore function comments that are only inheritdoc statements
      • Set the skipIfInheritdoc sniff property to true to skip checking function comments if the content is only {@inhertidoc}
      • The default remains at false, so these comments will continue to report errors
      • Thanks to Jess Myrbo for the patch
    • Squiz.Commenting.FunctionComment now supports the PHP 8 mixed type
      • Thanks to Vadim Borodavko for the patch
    • Squiz.PHP.NonExecutableCode now has improved handling of syntax errors
      • Thanks to Thiemo Kreuz for the patch
    • Squiz.WhiteSpace.ScopeKeywordSpacing now checks spacing when using PHP 8.0 constructor property promotion
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed an issue that could occur when checking files on network drives, such as with WSL2 on Windows 10
      • This works around a long-standing PHP bug with is_readable()
      • Thanks to Michael S for the patch
    • Fixed a number of false positives in the Squiz.PHP.DisallowMultipleAssignments sniff
      • Sniff no longer errors for default value assignments in arrow functions
      • Sniff no longer errors for assignments on first line of closure
      • Sniff no longer errors for assignments after a goto label
      • Thanks to Jaroslav Hanslík for the patch
    • Fixed bug #2913 : Generic.WhiteSpace.ScopeIndent false positive when opening and closing tag on same line inside conditional
    • Fixed bug #2992 : Enabling caching using a ruleset produces invalid cache files when using --sniffs and --exclude CLI args
    • Fixed bug #3003 : Squiz.Formatting.OperatorBracket autofix incorrect when assignment used with null coalescing operator
    • Fixed bug #3145 : Autoloading of sniff fails when multiple classes declared in same file
    • Fixed bug #3157 : PSR2.ControlStructures.SwitchDeclaration.BreakIndent false positive when case keyword is not indented
    • Fixed bug #3163 : Undefined index error with pre-commit hook using husky on PHP 7.4
      • Thanks to Ismo Vuorinen for the patch
    • Fixed bug #3165 : Squiz.PHP.DisallowComparisonAssignment false positive when comparison inside closure
    • Fixed bug #3167 : Generic.WhiteSpace.ScopeIndent false positive when using PHP 8.0 constructor property promotion
    • Fixed bug #3170 : Squiz.WhiteSpace.OperatorSpacing false positive when using negation with string concat
      • This also fixes the same issue in the PSR12.Operators.OperatorSpacing sniff
    • Fixed bug #3177 : Incorrect tokenization of GOTO statements in mixed PHP/HTML files
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3184 : PSR2.Namespace.NamespaceDeclaration false positive on namespace operator
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3188 : Squiz.WhiteSpace.ScopeKeywordSpacing false positive for static return type
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3192 : findStartOfStatement doesn't work correctly inside switch
      • Thanks to Vincent Langlet for the patch
    • Fixed bug #3195 : Generic.WhiteSpace.ScopeIndent confusing message when combination of tabs and spaces found
    • Fixed bug #3197 : Squiz.NamingConventions.ValidVariableName does not use correct error code for all member vars
    • Fixed bug #3219 : Generic.Formatting.MultipleStatementAlignment false positive for empty anonymous classes and closures
    • Fixed bug #3258 : Squiz.Formatting.OperatorBracket duplicate error messages for unary minus
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3273 : Squiz.Functions.FunctionDeclarationArgumentSpacing reports line break as 0 spaces between parenthesis
    • Fixed bug #3277 : Nullable static return typehint causes whitespace error
    • Fixed bug #3284 : Unused parameter false positive when using array index in arrow function
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.25 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.25 MB)
    phpcs.phar.asc(587 bytes)
  • 3.5.8(Oct 23, 2020)

  • 3.5.7(Oct 22, 2020)

    • The PHP 8.0 T_NULLSAFE_OBJECT_OPERATOR token has been made available for older versions
      • Existing sniffs that check for T_OBJECT_OPERATOR have been modified to apply the same rules for the nullsafe object operator
      • Thanks to Juliette Reinders Folmer for the patch
    • The new method of PHP 8.0 tokenizing for namespaced names has been revert to the pre 8.0 method
      • This maintains backwards compatible for existing sniffs on PHP 8.0
      • This change will be removed in PHPCS 4.0 as the PHP 8.0 tokenizing method will be backported for pre 8.0 versions
      • Thanks to Juliette Reinders Folmer for the patch
    • Added support for changes to the way PHP 8.0 tokenizes hash comments
      • The existing PHP 5-7 behaviour has been replicated for version 8, so no sniff changes are required
      • Thanks to Juliette Reinders Folmer for the patch
    • The autoloader has been changed to fix sniff class name detection issues that may occur when running on PHP 7.4+
      • Thanks to Eloy Lafuente for the patch
    • Running the unit tests now includes warnings in the found and fixable error code counts
      • Thanks to Juliette Reinders Folmer for the patch
    • PSR12.ControlStructures.BooleanOperatorPlacement.FoundMixed error message is now more accurate when using the allowOnly setting
      • Thanks to Vincent Langlet for the patch
    • PSR12.Functions.NullableTypeDeclaration now supports the PHP8 static return type
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed Squiz.Formatting.OperatorBracket false positive when exiting with a negative number
    • Fixed Squiz.PHP.DisallowComparisonAssignment false positive for methods called on an object
    • Fixed bug #2882 : Generic.Arrays.ArrayIndent can request close brace indent to be less than the statement indent level
    • Fixed bug #2883 : Generic.WhiteSpace.ScopeIndent.Incorrect issue after NOWDOC
    • Fixed bug #2975 : Undefined offset in PSR12.Functions.ReturnTypeDeclaration when checking function return type inside ternary
    • Fixed bug #2988 : Undefined offset in Squiz.Strings.ConcatenationSpacing during live coding
      • Thanks to Thiemo Kreuz for the patch
    • Fixed bug #2989 : Incorrect auto-fixing in Generic.ControlStructures.InlineControlStructure during live coding
      • Thanks to Thiemo Kreuz for the patch
    • Fixed bug #3007 : Directory exclude pattern improperly excludes directories with names that start the same
      • Thanks to Steve Talbot for the patch
    • Fixed bug #3043 : Squiz.WhiteSpace.OperatorSpacing false positive for negation in arrow function
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3049 : Incorrect error with arrow function and parameter passed as reference
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3053 : PSR2 incorrect fix when multiple use statements on same line do not have whitespace between them
    • Fixed bug #3058 : Progress gets unaligned when 100% happens at the end of the available dots
    • Fixed bug #3059 : Squiz.Arrays.ArrayDeclaration false positive when using type casting
      • Thanks to Sergei Morozov for the patch
    • Fixed bug #3060 : Squiz.Arrays.ArrayDeclaration false positive for static functions
      • Thanks to Sergei Morozov for the patch
    • Fixed bug #3065 : Should not fix Squiz.Arrays.ArrayDeclaration.SpaceBeforeComma if comment between element and comma
      • Thanks to Sergei Morozov for the patch
    • Fixed bug #3066 : No support for namespace operator used in type declarations
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3075 : PSR12.ControlStructures.BooleanOperatorPlacement false positive when operator is the only content on line
    • Fixed bug #3099 : Squiz.WhiteSpace.OperatorSpacing false positive when exiting with negative number
      • Thanks to Sergei Morozov for the patch
    • Fixed bug #3102 : PSR12.Squiz.OperatorSpacing false positive for default values of arrow functions
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #3124 : PSR-12 not reporting error for empty lines with only whitespace
    • Fixed bug #3135 : Ignore annotations are broken on PHP 8.0
      • Thanks to Juliette Reinders Folmer for the patch
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.22 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.22 MB)
    phpcs.phar.asc(587 bytes)
  • 3.5.6(Aug 10, 2020)

    • Added support for PHP 8.0 magic constant dereferencing
      • Thanks to Juliette Reinders Folmer for the patch
    • Added support for changes to the way PHP 8.0 tokenizes comments
      • The existing PHP 5-7 behaviour has been replicated for version 8, so no sniff changes are required
      • Thanks to Juliette Reinders Folmer for the patch
    • File::getMethodProperties() now detects the PHP 8.0 static return type
      • Thanks to Juliette Reinders Folmer for the patch
    • The PHP 8.0 static return type is now supported for arrow functions
      • Thanks to Juliette Reinders Folmer for the patch
    • The cache is no longer used if the list of loaded PHP extensions changes
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.NamingConventions.CamelCapsFunctionName no longer reports __serialize and __unserialize as invalid names
      • Thanks to Filip Š for the patch
    • PEAR.NamingConventions.ValidFunctionName no longer reports __serialize and __unserialize as invalid names
      • Thanks to Filip Š for the patch
    • Squiz.Scope.StaticThisUsage now detects usage of $this inside closures and arrow functions
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #2877 : PEAR.Functions.FunctionCallSignature false positive for array of functions
      • Thanks to Vincent Langlet for the patch
    • Fixed bug #2888 : PSR12.Files.FileHeader blank line error with multiple namespaces in one file
    • Fixed bug #2926 : phpcs hangs when using arrow functions that return heredoc
    • Fixed bug #2943 : Redundant semicolon added to a file when fixing PSR2.Files.ClosingTag.NotAllowed
    • Fixed bug #2967 : Markdown generator does not output headings correctly
      • Thanks to Petr Bugyík for the patch
    • Fixed bug #2977 : File::isReference() does not detect return by reference for closures
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2994 : Generic.Formatting.DisallowMultipleStatements false positive for FOR loop with no body
    • Fixed bug #3033 : Error generated during tokenizing of goto statements on PHP 8
      • Thanks to Juliette Reinders Folmer for the patch
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.22 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.22 MB)
    phpcs.phar.asc(587 bytes)
  • 3.5.5(Apr 17, 2020)

    • The T_FN backfill now works more reliably so T_FN tokens only ever represent real arrow functions
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed an issue where including sniffs using paths containing multiple dots would silently fail
    • Generic.CodeAnalysis.EmptyPHPStatement now detects empty statements at the start of control structures
    • Error wording in PEAR.Functions.FunctionCallSignature now always uses "parenthesis" instead of sometimes using "bracket"
      • Thanks to Vincent Langlet for the patch
    • Fixed bug #2787 : Squiz.PHP.DisallowMultipleAssignments not ignoring typed property declarations
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2810 : PHPCBF fails to fix file with empty statement at start on control structure
    • Fixed bug #2812 : Squiz.Arrays.ArrayDeclaration not detecting some arrays with multiple arguments on the same line
      • Thanks to Jakub Chábek for the patch
    • Fixed bug #2826 : Generic.WhiteSpace.ArbitraryParenthesesSpacing doesn't detect issues for statements directly after a control structure
      • Thanks to Vincent Langlet for the patch
    • Fixed bug #2848 : PSR12.Files.FileHeader false positive for file with mixed PHP and HTML and no file header
    • Fixed bug #2849 : Generic.WhiteSpace.ScopeIndent false positive with arrow function inside array
    • Fixed bug #2850 : Generic.PHP.LowerCaseKeyword complains __HALT_COMPILER is uppercase
    • Fixed bug #2853 : Undefined variable error when using Info report
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2865 : Double arrow tokenized as T_STRING when placed after function named "fn"
    • Fixed bug #2867 : Incorrect scope matching when arrow function used inside IF condition
    • Fixed bug #2868 : phpcs:ignore annotation doesnt work inside a docblock
    • Fixed bug #2878 : PSR12.Files.FileHeader conflicts with Generic.Files.LineEndings
    • Fixed bug #2895 : PSR2.Methods.FunctionCallSignature.MultipleArguments false positive with arrow function argument
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.21 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.21 MB)
    phpcs.phar.asc(587 bytes)
  • 3.5.4(Jan 30, 2020)

    • The PHP 7.4 numeric separator backfill now works correctly for more float formats
      • Thanks to Juliette Reinders Folmer for the patch
    • The PHP 7.4 numeric separator backfill is no longer run on PHP version 7.4.0 or greater
    • File::getCondition() now accepts a 3rd argument that allows for the closest matching token to be returned
      • By default, it continues to return the first matched token found from the top of the file
    • Fixed detection of array return types for arrow functions
    • Added Generic.PHP.DisallowRequestSuperglobal to ban the use of the $_REQUEST superglobal
      • Thanks to Morerice for the contribution
    • Generic.ControlStructures.InlineControlStructure no longer shows errors for while and for statements without a body
      • Previously it required these to have curly braces, but there were no statements to enclose in them
      • Thanks to Juliette Reinders Folmer for the patch
    • PSR12.ControlStructures.BooleanOperatorPlacement can now be configured to enforce a specific operator position
      • By default, the sniff ensures that operators are all at the beginning or end of lines, but not a mix of both
      • Set the allowOnly property to first to enforce all boolean operators to be at the start of a line
      • Set the allowOnly property to last to enforce all boolean operators to be at the end of a line
      • Thanks to Vincent Langlet for the patch
    • PSR12.Files.ImportStatement now auto-fixes import statements by removing the leading slash
      • Thanks to Michał Bundyra for the patch
    • Squiz.ControlStructures.ForLoopDeclaration now has a setting to ignore newline characters
      • Default remains FALSE, so newlines are not allowed within for definitions
      • Override the ignoreNewlines setting in a ruleset.xml file to change
    • Squiz.PHP.InnerFunctions now handles multiple nested anon classes correctly
    • Fixed bug #2497 : Sniff properties not set when referencing a sniff using relative paths or non-native slashes
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2657 : Squiz.WhiteSpace.FunctionSpacing can remove spaces between comment and first/last method during auto-fixing
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2688 : Case statements not tokenized correctly when switch is contained within ternary
    • Fixed bug #2698 : PHPCS throws errors determining auto report width when shell_exec is disabled
      • Thanks to Matthew Peveler for the patch
    • Fixed bug #2730 : PSR12.ControlStructures.ControlStructureSpacing does not ignore comments between conditions
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2732 : PSR12.Files.FileHeader misidentifies file header in mixed content file
    • Fixed bug #2745 : AbstractArraySniff wrong indices when mixed coalesce and ternary values
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #2748 : Wrong end of statement for fn closures
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #2751 : Autoload relative paths first to avoid confusion with files from the global include path
      • Thanks to Klaus Purer for the patch
    • Fixed bug #2763 : PSR12 standard reports errors for multi-line FOR definitions
    • Fixed bug #2768 : Generic.Files.LineLength false positive for non-breakable strings at exactly the soft limit
      • Thanks to Alex Miles for the patch
    • Fixed bug #2773 : PSR2.Methods.FunctionCallSignature false positive when arrow function has array return type
    • Fixed bug #2790 : PSR12.Traits.UseDeclaration ignores block comments
      • Thanks to Vincent Langlet for the patch
    • Fixed bug #2791 : PSR12.Functions.NullableTypeDeclaration false positive when ternary operator used with instanceof
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2802 : Can't specify a report file path using the tilde shortcut
    • Fixed bug #2804 : PHP4-style typed properties not tokenized correctly
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2805 : Undefined Offset notice during live coding of arrow functions
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2843 : Tokenizer does not support alternative syntax for declare statements
      • Thanks to Juliette Reinders Folmer for the patch
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.21 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.21 MB)
    phpcs.phar.asc(587 bytes)
  • 3.5.3(Dec 4, 2019)

    • The PHP 7.4 T_FN token has been made available for older versions
      • T_FN represents the fn string used for arrow functions
      • The double arrow becomes the scope opener, and uses a new T_FN_ARROW token type
      • The token after the statement (normally a semicolon) becomes the scope closer
      • The token is also associated with the opening and closing parenthesis of the statement
      • Any functions named fn will have a T_FN token for the function name, but have no scope information
      • Thanks to Michał Bundyra for the help with this change
    • PHP 7.4 numeric separators are now tokenized in the same way when using older PHP versions
      • Previously, a number like 1_000 would tokenize as T_LNUMBER (1), T_STRING (_000)
      • Now, the number tokenizes as T_LNUMBER (1_000)
      • Sniff developers should consider how numbers with underscores impact their custom sniffs
    • The PHPCS file cache now takes file permissions into account
      • The cache is now invalidated for a file when its permissions are changed
    • File::getMethodParameters() now supports arrow functions
    • File::getMethodProperties() now supports arrow functions
    • Added Fixer::changeCodeBlockIndent() to change the indent of a code block while auto-fixing
      • Can be used to either increase or decrease the indent
      • Useful when moving the start position of something like a closure, where you want the content to also move
    • Added Generic.Files.ExecutableFile sniff
      • Ensures that files are not executable
      • Thanks to Matthew Peveler for the contribution
    • Generic.CodeAnalysis.EmptyPhpStatement now reports unnecessary semicolons after control structure closing braces
      • Thanks to Vincent Langlet for the patch
    • Generic.PHP.LowerCaseKeyword now enforces that the fn keyword is lowercase
      • Thanks to Michał Bundyra for the patch
    • Generic.WhiteSpace.ScopeIndent now supports static arrow functions
    • PEAR.Functions.FunctionCallSignature now adjusts the indent of function argument contents during auto-fixing
      • Previously, only the first line of an argument was changed, leading to inconsistent indents
      • This change also applies to PSR2.Methods.FunctionCallSignature
    • PSR2.ControlStructures.ControlStructureSpacing now checks whitespace before the closing parenthesis of multi-line control structures
      • Previously, it incorrectly applied the whitespace check for single-line definitions only
    • PSR12.Functions.ReturnTypeDeclaration now checks the return type of arrow functions
      • Thanks to Michał Bundyra for the patch
    • PSR12.Traits.UseDeclaration now ensures all trait import statements are grouped together
      • Previously, the trait import section of the class ended when the first non-import statement was found
      • Checking now continues throughout the class to ensure all statements are grouped together
      • This also ensures that empty lines are not requested after an import statement that isn't the last one
    • Squiz.Functions.LowercaseFunctionKeywords now enforces that the fn keyword is lowercase
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #2586 : Generic.WhiteSpace.ScopeIndent false positives when indenting open tags at a non tab-stop
    • Fixed bug #2638 : Squiz.CSS.DuplicateClassDefinitionSniff sees comments as part of the class name
      • Thanks to Raphael Horber for the patch
    • Fixed bug #2640 : Squiz.WhiteSpace.OperatorSpacing false positives for some negation operators
      • Thanks to Jakub Chábek and Juliette Reinders Folmer for the patch
    • Fixed bug #2674 : Squiz.Functions.FunctionDeclarationArgumentSpacing prints wrong argument name in error message
    • Fixed bug #2676 : PSR12.Files.FileHeader locks up when file ends with multiple inline comments
    • Fixed bug #2678 : PSR12.Classes.AnonClassDeclaration incorrectly enforcing that closing brace be on a line by itself
    • Fixed bug #2685 : File::getMethodParameters() setting typeHintEndToken for vars with no type hint
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2694 : AbstractArraySniff produces invalid indices when using ternary operator
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #2702 : Generic.WhiteSpace.ScopeIndent false positive when using ternary operator with short arrays
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.21 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.21 MB)
    phpcs.phar.asc(587 bytes)
  • 3.5.2(Oct 28, 2019)

    • Generic.ControlStructures.DisallowYodaConditions now returns less false positives
      • False positives were being returned for array comparisions, or when performing some function calls
    • Squiz.WhiteSpace.SemicolonSpacing.Incorrect error message now escapes newlines and tabs
      • Provides a clearer error message as whitespace is now visible
      • Also allows for better output for report types such as CSV and XML
    • The error message for PSR12.Files.FileHeader.SpacingAfterBlock has been made clearer
      • It now uses the wording from the published PSR-12 standard to indicate that blocks must be separated by a blank line
      • Thanks to Craig Duncan for the patch
    • Fixed bug #2654 : Incorrect indentation for arguments of multiline function calls
    • Fixed bug #2656 : Squiz.WhiteSpace.MemberVarSpacing removes comments before first member var during auto fixing
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2663 : Generic.NamingConventions.ConstructorName complains about old constructor in interfaces
    • Fixed bug #2664 : PSR12.Files.OpenTag incorrectly identifies PHP file with only an opening tag
    • Fixed bug #2665 : PSR12.Files.ImportStatement should not apply to traits
    • Fixed bug #2673 : PSR12.Traits.UseDeclaration does not allow comments or blank lines between use statements
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.20 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.20 MB)
    phpcs.phar.asc(587 bytes)
  • 3.5.1(Oct 16, 2019)

    • Very very verbose diff report output has slightly changed to improve readability
      • Output is printed when running PHPCS with the --report=diff and -vvv command line arguments
      • Fully qualified class names have been replaced with sniff codes
      • Tokens being changed now display the line number they are on
    • PSR2, PSR12, and PEAR standards now correctly check for blank lines at the start of function calls
      • This check has been missing from these standards, but has now been implemented
      • When using the PEAR standard, the error code is PEAR.Functions.FunctionCallSignature.FirstArgumentPosition
      • When using PSR2 or PSR12, the error code is PSR2.Methods.FunctionCallSignature.FirstArgumentPosition
    • PSR12.ControlStructures.BooleanOperatorPlacement no longer complains when multiple expressions appear on the same line
      • Previously, boolean operators were enforced to appear at the start or end of lines only
      • Boolean operators can now appear in the middle of the line
    • PSR12.Files.FileHeader no longer ignores comments preceding a use, namespace, or declare statement
    • PSR12.Files.FileHeader now allows a hashbang line at the top of the file
    • Fixed bug #2506 : PSR2 standard can't auto fix multi-line function call inside a string concat statement
    • Fixed bug #2530 : PEAR.Commenting.FunctionComment does not support intersection types in comments
    • Fixed bug #2615 : Constant visibility false positive on non-class constants
    • Fixed bug #2616 : PSR12.Files.FileHeader false positive when file only contains docblock
    • Fixed bug #2619 : PSR12.Files.FileHeader locks up when inline comment is the last content in a file
    • Fixed bug #2621 : PSR12.Classes.AnonClassDeclaration.CloseBraceSameLine false positive for anon class passed as function argument
      • Thanks to Martins Sipenko for the patch
    • Fixed bug #2623 : PSR12.ControlStructures.ControlStructureSpacing not ignoring indentation inside multi-line string arguments
    • Fixed bug #2624 : PSR12.Traits.UseDeclaration doesnt apply the correct indent during auto fixing
    • Fixed bug #2626 : PSR12.Files.FileHeader detects @var annotations as file docblocks
    • Fixed bug #2628 : PSR12.Traits.UseDeclaration does not allow comments above a USE declaration
    • Fixed bug #2632 : Incorrect indentation of lines starting with "static" inside closures
    • Fixed bug #2641 : PSR12.Functions.NullableTypeDeclaration false positive when using new static()
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.20 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.20 MB)
    phpcs.phar.asc(587 bytes)
  • 3.5.0(Sep 26, 2019)

    PSR-12 Standard Ready

    PHP_CodeSniffer has included an in-progress PSR-12 standard since 3.3.0, but this release includes the completed standard. You can now check your code using the PSR-12 standard:

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

    Most of the errors found can also be automatically fixed by PHPCBF:

    phpcbf --standard=PSR12 /path/to/code
    

    Changelog

    • Added support for PHP 7.4 typed properties
      • The nullable operator is now tokenized as T_NULLABLE inside property types, as it is elsewhere
      • To get the type of a member var, use the File::getMemberProperties() method, which now contains a type array index
        • This contains the type of the member var, or a blank string if not specified
        • If the type is nullable, the return type will contain the leading ?
        • If a type is specified, the position of the first token in the type will be set in a type_token array index
        • If a type is specified, the position of the last token in the type will be set in a type_end_token array index
        • If the type is nullable, a nullable_type array index will also be set to TRUE
        • If the type contains namespace information, it will be cleaned of whitespace and comments in the return value
    • The PSR1 standard now correctly bans alternate PHP tags
      • Previously, it only banned short open tags and not the pre-7.0 alternate tags
    • Added support for only checking files that have been locally staged in a git repo
      • Use --filter=gitstaged to check these files
      • You still need to give PHPCS a list of files or directories in which to apply the filter
      • Thanks to Juliette Reinders Folmer for the contribution
    • JSON reports now end with a newline character
    • The phpcs.xsd schema now validates phpcs-only and phpcbf-only attributes correctly
      • Thanks to Juliette Reinders Folmer for the patch
    • The tokenizer now correctly identifies inline control structures in more cases
    • All helper methods inside the File class now throw RuntimeException instead of TokenizerException
      • Some tokenizer methods were also throwing RuntimeExpection but now correctly throw TokenizerException
      • Thanks to Juliette Reinders Folmer for the patch
    • The File::getMethodParameters() method now returns more information, and supports closure USE groups
      • If a type hint is specified, the position of the last token in the hint will be set in a type_hint_end_token array index
      • If a default is specified, the position of the first token in the default value will be set in a default_token array index
      • If a default is specified, the position of the equals sign will be set in a default_equal_token array index
      • If the param is not the last, the position of the comma will be set in a comma_token array index
      • If the param is passed by reference, the position of the reference operator will be set in a reference_token array index
      • If the param is variable length, the position of the variadic operator will be set in a variadic_token array index
    • The T_LIST token and it's opening and closing parentheses now contain references to each other in the tokens array
      • Uses the same parenthesis_opener/closer/owner indexes as other tokens
      • Thanks to Juliette Reinders Folmer for the patch
    • The T_ANON_CLASS token and it's opening and closing parentheses now contain references to each other in the tokens array
      • Uses the same parenthesis_opener/closer/owner indexes as other tokens
      • Only applicable if the anon class is passing arguments to the constructor
      • Thanks to Juliette Reinders Folmer for the patch
    • The PHP 7.4 T_BAD_CHARACTER token has been made available for older versions
      • Allows you to safely look for this token, but it will not appear unless checking with PHP 7.4+
    • Metrics are now available for Squiz.WhiteSpace.FunctionSpacing
      • Use the info report to see blank lines before/after functions
      • Thanks to Juliette Reinders Folmer for the patch
    • Metrics are now available for Squiz.WhiteSpace.MemberVarSpacing
      • Use the info report to see blank lines before member vars
      • Thanks to Juliette Reinders Folmer for the patch
    • Added Generic.ControlStructures.DisallowYodaConditions sniff
      • Ban the use of Yoda conditions
      • Thanks to Mponos George for the contribution
    • Added Generic.PHP.RequireStrictTypes sniff
      • Enforce the use of a strict types declaration in PHP files
    • Added Generic.WhiteSpace.SpreadOperatorSpacingAfter sniff
      • Checks whitespace between the spread operator and the variable/function call it applies to
      • Thanks to Juliette Reinders Folmer for the contribution
    • Added PSR12.Classes.AnonClassDeclaration sniff
      • Enforces the formatting of anonymous classes
    • Added PSR12.Classes.ClosingBrace sniff
      • Enforces that closing braces of classes/interfaces/traits/functions are not followed by a comment or statement
    • Added PSR12.ControlStructures.BooleanOperatorPlacement sniff
      • Enforces that boolean operators between conditions are consistently at the start or end of the line
    • Added PSR12.ControlStructures.ControlStructureSpacing sniff
      • Enforces that spacing and indents are correct inside control structure parenthesis
    • Added PSR12.Files.DeclareStatement sniff
      • Enforces the formatting of declare statements within a file
    • Added PSR12.Files.FileHeader sniff
      • Enforces the order and formatting of file header blocks
    • Added PSR12.Files.ImportStatement sniff
      • Enforces the formatting of import statements within a file
    • Added PSR12.Files.OpenTag sniff
      • Enforces that the open tag is on a line by itself when used at the start of a php-only file
    • Added PSR12.Functions.ReturnTypeDeclaration sniff
      • Enforces the formatting of return type declarations in functions and closures
    • Added PSR12.Properties.ConstantVisibility sniff
      • Enforces that constants must have their visibility defined
      • Uses a warning instead of an error due to this conditionally requiring the project to support PHP 7.1+
    • Added PSR12.Traits.UseDeclaration sniff
      • Enforces the formatting of trait import statements within a class
    • Generic.Files.LineLength ignoreComments property now ignores comments at the end of a line
      • Previously, this property was incorrectly causing the sniff to ignore any line that ended with a comment
      • Now, the trailing comment is not included in the line length, but the rest of the line is still checked
    • Generic.Files.LineLength now only ignores unwrappable comments when the comment is on a line by itself
      • Previously, a short unwrappable comment at the end of the line would have the sniff ignore the entire line
    • Generic.Functions.FunctionCallArgumentSpacing no longer checks spacing around assignment operators inside function calls
      • Use the Squiz.WhiteSpace.OperatorSpacing sniff to enforce spacing around assignment operators
        • Note that this sniff checks spacing around all assignment operators, not just inside function calls
      • The Generic.Functions.FunctionCallArgumentSpacing.NoSpaceBeforeEquals error has been removed
        • use Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore instead
      • The Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterEquals error has been removed
        • use Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter instead
      • This also changes the PEAR/PSR2/PSR12 standards so they no longer check assignment operators inside function calls
        • They were previously checking these operators when they should not have
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.WhiteSpace.ScopeIndent no longer performs exact indents checking for chained method calls
      • Other sniffs can be used to enforce chained method call indent rules
      • Thanks to Pieter Frenssen for the patch
    • PEAR.WhiteSpace.ObjectOperatorIndent now supports multi-level chained statements
      • When enabled, chained calls must be indented 1 level more or less than the previous line
      • Set the new multilevel setting to TRUE in a ruleset.xml file to enable this behaviour
      • Thanks to Marcos Passos for the patch
    • PSR2.ControlStructures.ControlStructureSpacing now allows whitespace after the opening parenthesis if followed by a comment
      • Thanks to Michał Bundyra for the patch
    • PSR2.Classes.PropertyDeclaration now enforces a single space after a property type keyword
      • The PSR2 standard itself excludes this new check as it is not defined in the written standard
      • Using the PSR12 standard will enforce this check
    • Squiz.Commenting.BlockComment no longer requires blank line before comment if it's the first content after the PHP open tag
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Functions.FunctionDeclarationArgumentSpacing now has more accurate error messages
      • This includes renaming the SpaceAfterDefault error code to SpaceAfterEquals, which reflects the real error
    • Squiz.Functions.FunctionDeclarationArgumentSpacing now checks for no space after a reference operator
      • If you don't want this new behaviour, exclude the SpacingAfterReference error message in a ruleset.xml file
    • Squiz.Functions.FunctionDeclarationArgumentSpacing now checks for no space after a variadic operator
      • If you don't want this new behaviour, exclude the SpacingAfterVariadic error message in a ruleset.xml file
    • Squiz.Functions.MultiLineFunctionDeclaration now has improved fixing for the FirstParamSpacing and UseFirstParamSpacing errors
    • Squiz.Operators.IncrementDecrementUsage now suggests pre-increment of variables instead of post-increment
      • This change does not enforce pre-increment over post-increment; only the suggestion has changed
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.PHP.DisallowMultipleAssignments now has a second error code for when assignments are found inside control structure conditions
      • The new error code is Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
      • All other multiple assignment cases use the existing error code Squiz.PHP.DisallowMultipleAssignments.Found
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.WhiteSpace.FunctionSpacing now applies beforeFirst and afterLast spacing rules to nested functions
      • Previously, these rules only applied to the first and last function in a class, interface, or trait
      • These rules now apply to functions nested in any statement block, including other functions and conditions
    • Squiz.WhiteSpace.OperatorSpacing now has improved handling of parse errors
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.WhiteSpace.OperatorSpacing now checks spacing around the instanceof operator
      • Thanks to Jakub Chábek for the patch
    • Squiz.WhiteSpace.OperatorSpacing can now enforce a single space before assignment operators
      • Previously, the sniff this spacing as multiple assignment operators are sometimes aligned
      • Now, you can set the ignoreSpacingBeforeAssignments sniff property to FALSE to enable checking
      • Default remains TRUE, so spacing before assignments is not checked by default
      • Thanks to Jakub Chábek for the patch
    • Fixed bug #2391 : Sniff-specific ignore rules inside rulesets are filtering out too many files
      • Thanks to Juliette Reinders Folmer and Willington Vega for the patch
    • Fixed bug #2478 : FunctionCommentThrowTag.WrongNumber when exception is thrown once but built conditionally
    • Fixed bug #2479 : Generic.WhiteSpace.ScopeIndent error when using array destructing with exact indent checking
    • Fixed bug #2498 : Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed autofix breaks heredoc
    • Fixed bug #2502 : Generic.WhiteSpace.ScopeIndent false positives with nested switch indentation and case fall-through
    • Fixed bug #2504 : Generic.WhiteSpace.ScopeIndent false positives with nested arrays and nowdoc string
    • Fixed bug #2511 : PSR2 standard not checking if closing paren of single-line function declaration is on new line
    • Fixed bug #2512 : Squiz.PHP.NonExecutableCode does not support alternate SWITCH control structure
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2522 : Text generator throws error when code sample line is too long
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2526 : XML report format has bad syntax on Windows
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2529 : Generic.Formatting.MultipleStatementAlignment wrong error for assign in string concat
    • Fixed bug #2534 : Unresolvable installed_paths can lead to open_basedir errors
      • Thanks to Oliver Nowak for the patch
    • Fixed bug #2541 : Text doc generator does not allow for multi-line rule explanations
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2549 : Searching for a phpcs.xml file can throw warnings due to open_basedir restrictions
      • Thanks to Matthew Peveler for the patch
    • Fixed bug #2558 : PHP 7.4 throwing offset syntax with curly braces is deprecated message
      • Thanks to Matthew Peveler for the patch
    • Fixed bug #2561 : PHP 7.4 compatibility fix / implode argument order
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2562 : Inline WHILE triggers SpaceBeforeSemicolon incorrectly
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2565 : Generic.ControlStructures.InlineControlStructure confused by mixed short/long tags
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2566 : Author tag email validation doesn't support all TLDs
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2575 : Custom error messages don't have data replaced when cache is enabled
    • Fixed bug #2601 : Squiz.WhiteSpace.FunctionSpacing incorrect fix when spacing is 0
    • Fixed bug #2608 : PSR2 throws errors for use statements when multiple namespaces are defined in a file
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.19 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.19 MB)
    phpcs.phar.asc(587 bytes)
  • 3.4.2(Apr 11, 2019)

    • Squiz.Arrays.ArrayDeclaration now has improved handling of syntax errors
    • Fixed an issue where the PCRE JIT on PHP 7.3 caused PHPCS to die when using the parallel option
      • PHPCS now disables the PCRE JIT before running
    • Fixed bug #2368 : MySource.PHP.AjaxNullComparison throws error when first function has no doc comment
    • Fixed bug #2414 : Indention false positive in switch/case/if combination
    • Fixed bug #2423 : Squiz.Formatting.OperatorBracket.MissingBrackets error with static
    • Fixed bug #2450 : Indentation false positive when closure containing nested IF conditions used as function argument
    • Fixed bug #2452 : LowercasePHPFunctions sniff failing on "new \File()"
    • Fixed bug #2453 : Squiz.CSS.SemicolonSpacingSniff false positive when style name proceeded by an asterisk
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2464 : Fixer conflict between Generic.WhiteSpace.ScopeIndent and Squiz.WhiteSpace.ScopeClosingBrace when class indented 1 space
    • Fixed bug #2465 : Excluding a sniff by path is not working
    • Fixed bug #2467 : PHP open/close tags inside CSS files are replaced with internal PHPCS token strings when auto fixing
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.13 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.13 MB)
    phpcs.phar.asc(587 bytes)
  • 3.4.1(Mar 19, 2019)

    Note for PEAR Users

    The PEAR installable version of PHPCS was missing some files, which have been re-included in this release. The result of these omissions were:

    • The code report was not previously available for PEAR installs
    • The Generic.Formatting.SpaceBeforeCast sniff was not previously available for PEAR installs
    • The Generic.WhiteSpace.LanguageConstructSpacing sniff was not previously available for PEAR installs

    Thanks to Juliette Reinders Folmer for the patch

    Changelog

    • PHPCS will now refuse to run if any of the required PHP extensions are not loaded
      • Previously, PHPCS only relied on requirements being checked by PEAR and Composer
      • Thanks to Juliette Reinders Folmer for the patch
    • Ruleset XML parsing errors are now displayed in a readable format so they are easier to correct
      • Thanks to Juliette Reinders Folmer for the patch
    • The PSR2 standard no longer throws duplicate errors for spacing around FOR loop parentheses
      • Thanks to Juliette Reinders Folmer for the patch
    • T_PHPCS_SET tokens now contain sniffCode, sniffProperty, and sniffPropertyValue indexes
      • Sniffs can use this information instead of having to parse the token content manually
    • Added more guard code for syntax errors to various CSS sniffs
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Commenting.DocComment error messages now contain the name of the comment tag that caused the error
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.ControlStructures.InlineControlStructure now handles syntax errors correctly
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Debug.JSHint now longer requires rhino and can be run directly from the npm install
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Files.LineEndings no longer adds superfluous new line at the end of JS and CSS files
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Formatting.DisallowMultipleStatements no longer tries fix lines containing phpcs:ignore statements
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Functions.FunctionCallArgumentSpacing now has improved performance and anonymous class support
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.WhiteSpace.ScopeIndent now respects changes to the exact property using phpcs:set mid-way through a file
      • This allows you change the exact rule for only some parts of a file
    • Generic.WhiteSpace.ScopeIndent now disables exact indent checking inside all arrays
      • Previously, this was only done when using long array syntax, but it now works for short array syntax as well
    • PEAR.Classes.ClassDeclaration now has improved handling of PHPCS annotations and tab indents
    • PSR12.Classes.ClassInstantiation has changed it's error code from MissingParenthesis to MissingParentheses
    • PSR12.Keywords.ShortFormTypeKeywords now ignores all spacing inside type casts during both checking and fixing
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Classes.LowercaseClassKeywords now examines the class keyword for anonymous classes
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.ControlStructures.ControlSignature now has improved handling of parse errors
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Commenting.PostStatementComment fixer no longer adds a blank line at the start of a JS file that begins with a comment
      • Fixes a conflict between this sniff and the Squiz.WhiteSpace.SuperfluousWhitespace sniff
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Commenting.PostStatementComment now ignores comments inside control structure conditions, such as FOR loops
      • Fixes a conflict between this sniff and the Squiz.ControlStructures.ForLoopDeclaration sniff
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Commenting.FunctionCommentThrowTag now has improved support for unknown exception types and namespaces
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.ControlStructures.ForLoopDeclaration has improved whitespace, closure, and empty expression support
      • The SpacingAfterSecondNoThird error code has been removed as part of these fixes
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.CSS.ClassDefinitionOpeningBraceSpace now handles comments and indentation correctly
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.CSS.ClassDefinitionClosingBrace now handles comments, indentation, and multiple statements on the same line correctly
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.CSS.Opacity now handles comments correctly
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.CSS.SemicolonSpacing now handles comments and syntax errors correctly
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.NamingConventions.ValidVariableName now supports variables inside anonymous classes correctly
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.PHP.LowercasePHPFunctions now handles use statements, namespaces, and comments correctly
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.WhiteSpace.FunctionSpacing now fixes function spacing correctly when a function is the first content in a file
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.WhiteSpace.SuperfluousWhitespace no longer throws errors for spacing between functions and properties in anon classes
      • Thanks to Juliette Reinders Folmer for the patch
    • Zend.Files.ClosingTag no longer adds a semi-colon during fixing of a file that only contains a comment
      • Thanks to Juliette Reinders Folmer for the patch
    • Zend.NamingConventions.ValidVariableName now supports variables inside anonymous classes correctly
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2298 : PSR2.Classes.ClassDeclaration allows extended class on new line
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #2337 : Generic.WhiteSpace.ScopeIndent incorrect error when multi-line function call starts on same line as open tag
    • Fixed bug #2348 : Cache not invalidated when changing a ruleset included by another
    • Fixed bug #2376 : Using __halt_compiler() breaks Generic.PHP.ForbiddenFunctions unless it's last in the function list
      • Thanks to Sijun Zhu for the patch
    • Fixed bug #2393 : The gitmodified filter will infinitely loop when encountering deleted file paths
      • Thanks to Lucas Manzke for the patch
    • Fixed bug #2396 : Generic.WhiteSpace.ScopeIndent incorrect error when multi-line IF condition mixed with HTML
    • Fixed bug #2431 : Use function/const not tokenized as T_STRING when preceded by comment
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.12 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.12 MB)
    phpcs.phar.asc(587 bytes)
  • 3.4.0(Dec 20, 2018)

    Deprecations

    Generic.Formatting.NoSpaceAfterCast Sniff

    The Generic.Formatting.NoSpaceAfterCast sniff has been deprecated and will be removed in version 4.

    The functionality of this sniff is now available in the Generic.Formatting.SpaceAfterCast sniff. Include the Generic.Formatting.SpaceAfterCast sniff and set the spacing property to 0 to retain the existing functionality. As soon as possible, replace all instances of the old sniff code with the new sniff code and property setting in your ruleset.xml files. The existing sniff will continue to work until version 4 has been released.

    Other Changes

    • Rule include patterns in a ruleset.xml file are now evaluated as OR instead of AND
      • Previously, a file had to match every include pattern and no exclude patterns to be included
      • Now, a file must match at least one include pattern and no exclude patterns to be included
      • This is a bug fix as include patterns are already documented to work this way
    • New token T_BITWISE_NOT added for the bitwise not operator
      • This token was previously tokenized as T_NONE
      • Any sniffs specifically looking for T_NONE tokens with a tilde as the contents must now also look for T_BITWISE_NOT
      • Sniffs can continue looking for T_NONE as well as T_BITWISE_NOT to support older PHP_CodeSniffer versions
    • All types of binary casting are now tokenized as T_BINARY_CAST
      • Previously, the b in b"some string with $var" would be a T_BINARY_CAST, but only when the string contained a var
      • This change ensures the b is always tokenized as T_BINARY_CAST
      • This change also converts (binary) from T_STRING_CAST to T_BINARY_CAST
      • Thanks to Juliette Reinders Folmer for the help with this patch
    • Array properties set inside a ruleset.xml file can now extend a previous value instead of always overwriting it
      • e.g., if you include a ruleset that defines forbidden functions, can you now add to that list instead of having to redefine it
      • To use this feature, add extend="true" to the property tag
        • e.g., <property name="forbiddenFunctionNames" type="array" extend="true">
      • Thanks to Michael Moravec for the patch
    • If $XDG_CACHE_HOME is set and points to a valid directory, it will be used for caching instead of the system temp directory
    • PHPCBF now disables parallel running if you are passing content on STDIN
      • Stops an error from being shown after the fixed output is printed
    • The progress report now shows files with tokenizer errors as skipped (S) instead of a warning (W)
      • The tokenizer error is still displayed in reports as normal
      • Thanks to Juliette Reinders Folmer for the patch
    • The Squiz standard now ensures there is no space between an increment/decrement operator and its variable
    • The File:: getMethodProperties() method now includes a has_body array index in the return value
      • FALSE if the method has no body (as with abstract and interface methods) or TRUE otherwise
      • Thanks to Chris Wilkinson for the patch
    • The File::getTokensAsString() method now throws an exception if the $start param is invalid
      • If the $length param is invalid, an empty string will be returned
      • Stops an infinite loop when the function is passed invalid data
      • Thanks to Juliette Reinders Folmer for the patch
    • Added new Generic.CodeAnalysis.EmptyPHPStatement sniff
      • Warns when it finds empty PHP open/close tag combinations or superfluous semicolons
      • Thanks to Juliette Reinders Folmer for the contribution
    • Added new Generic.Formatting.SpaceBeforeCast sniff
      • Ensures there is exactly 1 space before a type cast, unless the cast statement is indented or multi-line
      • Thanks to Juliette Reinders Folmer for the contribution
    • Added new Generic.VersionControl.GitMergeConflict sniff
      • Detects merge conflict artifacts left in files
      • Thanks to Juliette Reinders Folmer for the contribution
    • Added Generic.WhiteSpace.IncrementDecrementSpacing sniff
      • Ensures there is no space between the operator and the variable it applies to
      • Thanks to Juliette Reinders Folmer for the contribution
    • Added PSR12.Functions.NullableTypeDeclaration sniff
      • Ensures there is no space after the question mark in a nullable type declaration
      • Thanks to Timo Schinkel for the contribution
    • A number of sniffs have improved support for methods in anonymous classes
      • These sniffs would often throw the same error twice for functions in nested classes
      • Error messages have also been changed to be less confusing
      • The full list of affected sniffs is:
        • Generic.NamingConventions.CamelCapsFunctionName
        • PEAR.NamingConventions.ValidFunctionName
        • PSR1.Methods.CamelCapsMethodName
        • PSR2.Methods.MethodDeclaration
        • Squiz.Scope.MethodScope
        • Squiz.Scope.StaticThisUsage
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.CodeAnalysis.UnusedFunctionParameter now only skips functions with empty bodies when the class implements an interface
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.CodeAnalysis.UnusedFunctionParameter now has additional error codes to indicate where unused params were found
      • The new error code prefixes are:
        • FoundInExtendedClass: when the class extends another
        • FoundInImplementedInterface: when the class implements an interface
        • Found: used in all other cases, including closures
      • The new error code suffixes are:
        • BeforeLastUsed: the unused param was positioned before the last used param in the function signature
        • AfterLastUsed: the unused param was positioned after the last used param in the function signature
      • This makes the new error code list for this sniff:
        • Found
        • FoundBeforeLastUsed
        • FoundAfterLastUsed
        • FoundInExtendedClass
        • FoundInExtendedClassBeforeLastUsed
        • FoundInExtendedClassAfterLastUsed
        • FoundInImplementedInterface
        • FoundInImplementedInterfaceBeforeLastUsed
        • FoundInImplementedInterfaceAfterLastUsed
      • These errors code make it easier for specific cases to be ignored or promoted using a ruleset.xml file
      • Thanks to Juliette Reinders Folmer for the contribution
    • Generic.Classes.DuplicateClassName now inspects traits for duplicate names as well as classes and interfaces
      • Thanks to Chris Wilkinson for the patch
    • Generic.Files.InlineHTML now ignores a BOM at the start of the file
      • Thanks to Chris Wilkinson for the patch
    • Generic.PHP.CharacterBeforePHPOpeningTag now ignores a BOM at the start of the file
      • Thanks to Chris Wilkinson for the patch
    • Generic.Formatting.SpaceAfterCast now has a setting to specify how many spaces are required after a type cast
      • Default remains 1
      • Override the spacing setting in a ruleset.xml file to change
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Formatting.SpaceAfterCast now has a setting to ignore newline characters after a type cast
      • Default remains FALSE, so newlines are not allowed
      • Override the ignoreNewlines setting in a ruleset.xml file to change
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Formatting.SpaceAfterNot now has a setting to specify how many spaces are required after a NOT operator
      • Default remains 1
      • Override the spacing setting in a ruleset.xml file to change
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Formatting.SpaceAfterNot now has a setting to ignore newline characters after the NOT operator
      • Default remains FALSE, so newlines are not allowed
      • Override the ignoreNewlines setting in a ruleset.xml file to change
      • Thanks to Juliette Reinders Folmer for the patch
    • PEAR.Functions.FunctionDeclaration now checks spacing before the opening parenthesis of functions with no body
      • Thanks to Chris Wilkinson for the patch
    • PEAR.Functions.FunctionDeclaration now enforces no space before the semicolon in functions with no body
      • Thanks to Chris Wilkinson for the patch
    • PSR2.Classes.PropertyDeclaration now checks the order of property modifier keywords
      • This is a rule that is documented in PSR-2 but was not enforced by the included PSR2 standard until now
      • This sniff is also able to fix the order of the modifier keywords if they are incorrect
      • Thanks to Juliette Reinders Folmer for the patch
    • PSR2.Methods.MethodDeclaration now checks method declarations inside traits
      • Thanks to Chris Wilkinson for the patch
    • Squiz.Commenting.InlineComment now has better detection of comment block boundaries
    • Squiz.Classes.ClassFileName now checks that a trait name matches the filename
      • Thanks to Chris Wilkinson for the patch
    • Squiz.Classes.SelfMemberReference now supports scoped declarations and anonymous classes
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Classes.SelfMemberReference now fixes multiple errors at once, increasing fixer performance
      • Thanks to Gabriel Ostrolucký for the patch
    • Squiz.Functions.LowercaseFunctionKeywords now checks abstract and final prefixes, and auto-fixes errors
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Objects.ObjectMemberComma.Missing has been renamed to Squiz.Objects.ObjectMemberComma.Found
      • The error is thrown when the comma is found but not required, so the error code was incorrect
      • If you are referencing the old error code in a ruleset XML file, please use the new code instead
      • If you wish to maintain backwards compatibility, you can provide rules for both the old and new codes
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.WhiteSpace.ObjectOperatorSpacing is now more tolerant of parse errors
    • Squiz.WhiteSpace.ObjectOperatorSpacing now fixes errors more efficiently
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2109 : Generic.Functions.CallTimePassByReference false positive for bitwise and used in function argument
    • Fixed bug #2165 : Conflict between Squiz.Arrays.ArrayDeclaration and ScopeIndent sniffs when heredoc used in array
    • Fixed bug #2167 : Generic.WhiteSpace.ScopeIndent shows invalid error when scope opener indented inside inline HTML
    • Fixed bug #2178 : Generic.NamingConventions.ConstructorName matches methods in anon classes with same name as containing class
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2190 : PEAR.Functions.FunctionCallSignature incorrect error when encountering trailing PHPCS annotation
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2194 : Generic.Whitespace.LanguageConstructSpacing should not be checking namespace operators
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2202 : Squiz.WhiteSpace.OperatorSpacing throws error for negative index when using curly braces for string access
      • Same issue fixed in Squiz.Formatting.OperatorBracket
      • Thanks to Andreas Buchenrieder for the patch
    • Fixed bug #2210 : Generic.NamingConventions.CamelCapsFunctionName not ignoring SoapClient __getCookies() method
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2211 : PSR2.Methods.MethodDeclaration gets confused over comments between modifier keywords
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2212 : FUNCTION and CONST in use groups being tokenised as T_FUNCTION and T_CONST
      • Thanks to Chris Wilkinson for the patch
    • Fixed bug #2214 : File::getMemberProperties() is recognizing method params as properties
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2236 : Memory info measurement unit is Mb but probably should be MB
    • Fixed bug #2246 : CSS tokenizer does not tokenize class names correctly when they contain the string NEW
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2278 : Squiz.Operators.ComparisonOperatorUsage false positive when inline IF contained in parentheses
      • Thanks to Arnout Boks for the patch
    • Fixed bug #2284 : Squiz.Functions.FunctionDeclarationArgumentSpacing removing type hint during fixing
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #2297 : Anonymous class not tokenized correctly when used as argument to another anon class
      • Thanks to Michał Bundyra for the patch
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.11 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.11 MB)
    phpcs.phar.asc(587 bytes)
  • 2.9.2(Nov 7, 2018)

    Final 2.9 Release

    Version 2.9.2 will be the final release of the PHP_CodeSniffer 2.9 branch, first released over 4 years ago. All developers still using version 2 are strongly encouraged to migrate to version 3.

    Version 3 was first released as stable on the 4th of May 2017 and is a large refactoring of the code base that breaks backwards compatibility for all custom sniffs and custom reports. An upgrade guide for sniff and report developers is available here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Version-3.0-Upgrade-Guide

    Note: If you only use the built-in coding standards (such as PEAR or PSR2), or you have a custom ruleset.xml file that only makes use of the sniffs and reports distributed with PHP_CodeSniffer, you do not need to make any changes to begin using PHP_CodeSniffer version 3.

    Other Changes

    • PHPCS should now run under PHP 7.3 without deprecation warnings
      • Thanks to Nick Wilde for the patch
    • Fixed bug #1496 : Squiz.Strings.DoubleQuoteUsage not unescaping dollar sign when fixing
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #1549 : Squiz.PHP.EmbeddedPhp fixer conflict with // comment before PHP close tag
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1890 : Incorrect Squiz.WhiteSpace.ControlStructureSpacing.NoLineAfterClose error between catch and finally statements
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(514.88 KB)
    phpcs.phar(514.87 KB)
  • 3.3.2(Sep 23, 2018)

    • Fixed a problem where the report cache was not being cleared when the sniffs inside a standard were updated
    • The info report (--report=info) now has improved formatting for metrics that span multiple lines
      • Thanks to Juliette Reinders Folmer for the patch
    • The unit test runner now skips .bak files when looking for test cases
      • Thanks to Juliette Reinders Folmer for the patch
    • The Squiz standard now ensures underscores are not used to indicate visibility of private members vars and methods
      • Previously, this standard enforced the use of underscores
    • Generic.PHP.NoSilencedErrors error messages now contain a code snippet to show the context of the error
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Arrays.ArrayDeclaration no longer reports errors for a comma on a line new after a here/nowdoc
      • Also stops a parse error being generated when auto-fixing
      • The SpaceBeforeComma error message has been changed to only have one data value instead of two
    • Squiz.Commenting.FunctionComment no longer errors when trying to fix indents of multi-line param comments
    • Squiz.Formatting.OperatorBracket now correctly fixes statements that contain strings
    • Squiz.PHP.CommentedOutCode now ignores more @-style annotations and includes better comment block detection
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed a problem where referencing a relative file path in a ruleset XML file could add unnecessary sniff exclusions
      • This didn't actually exclude anything, but caused verbose output to list strange exclusion rules
    • Fixed bug #2110 : Squiz.WhiteSpace.FunctionSpacing is removing indents from the start of functions when fixing
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2115 : Squiz.Commenting.VariableComment not checking var types when the @var line contains a comment
    • Fixed bug #2120 : Tokenizer fails to match T_INLINE_ELSE when used after function call containing closure
    • Fixed bug #2121 : Squiz.PHP.DisallowMultipleAssignments false positive in while loop conditions
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2127 : File::findExtendedClassName() doesn't support nested classes
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2138 : Tokenizer detects wrong token for php ::class feature with spaces
    • Fixed bug #2143 : PSR2.Namespaces.UseDeclaration does not properly fix "use function" and "use const" statements
      • Thanks to Chris Wilkinson for the patch
    • Fixed bug #2144 : Squiz.Arrays.ArrayDeclaration does incorrect align calculation in array with cyrillic keys
    • Fixed bug #2146 : Zend.Files.ClosingTag removes closing tag from end of file without inserting a semicolon
    • Fixed bug #2151 : XML schema not updated with the new array property syntax
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.08 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.08 MB)
    phpcs.phar.asc(587 bytes)
  • 3.3.1(Jul 26, 2018)

    HHVM Support Dropped

    Support for HHVM has been dropped due to recent unfixed bugs and HHVM's refocus on Hack only. Thanks to Walt Sorensen and Juliette Reinders Folmer for helping to remove all HHVM exceptions from the core.

    Other Changes

    • The full report (the default report) now has improved word wrapping for multi-line messages and sniff codes
      • Thanks to Juliette Reinders Folmer for the patch
    • The summary report now sorts files based on their directory location instead of just a basic string sort
      • Thanks to Juliette Reinders Folmer for the patch
    • The source report now orders error codes by name when they have the same number of errors
      • Thanks to Juliette Reinders Folmer for the patch
    • The junit report no longer generates validation errors with the Jenkins xUnit plugin
      • Thanks to Nikolay Geo for the patch
    • Generic.Commenting.DocComment no longer generates the SpacingBeforeTags error if tags are the first content in the docblock
      • The sniff will still generate a MissingShort error if there is no short comment
      • This allows the MissingShort error to be suppressed in a ruleset to make short descriptions optional
    • Generic.Functions.FunctionCallArgumentSpacing now properly fixes multi-line function calls with leading commas
      • Previously, newlines between function arguments would be removed
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.PHP.Syntax will now use PHP_BINARY instead of trying to discover the executable path
      • This ensures that the sniff will always syntax check files using the PHP version that PHPCS is running under
      • Setting the php_path config var will still override this value as normal
      • Thanks to Willem Stuursma-Ruwen for the patch
    • PSR2.Namespaces.UseDeclaration now supports commas at the end of group use declarations
      • Also improves checking and fixing for use statements containing parse errors
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Arrays.ArrayDeclaration no longer removes the array opening brace while fixing
      • This could occur when the opening brace was on a new line and the first array key directly followed
      • This change also stops the KeyNotAligned error message being incorrectly reported in these cases
    • Squiz.Arrays.ArrayDeclaration no longer tries to change multi-line arrays to single line when they contain comments
      • Fixes a conflict between this sniff and some indentation sniffs
    • Squiz.Classes.ClassDeclaration no longer enforces spacing rules when a class is followed by a function
      • Fixes a conflict between this sniff and the Squiz.WhiteSpace.FunctionSpacing sniff
    • The Squiz.Classes.ValidClassName.NotCamelCaps message now references PascalCase instead of CamelCase
      • The CamelCase class name metric produced by the sniff has been changed to PascalCase class name
      • This reflects the fact that the class name check is actually a Pascal Case check and not really Camel Case
      • Thanks to Tom H Anderson for the patch
    • Squiz.Commenting.InlineComment no longer enforces spacing rules when an inline comment is followed by a docblock
      • Fixes a conflict between this sniff and the Squiz.WhiteSpace.FunctionSpacing sniff
    • Squiz.WhiteSpace.OperatorSpacing no longer tries to fix operator spacing if the next content is a comment on a new line
      • Fixes a conflict between this sniff and the Squiz.Commenting.PostStatementComment sniff
      • Also stops PHPCS annotations from being moved to a different line, potentially changing their meaning
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.WhiteSpace.FunctionSpacing no longer checks spacing of functions at the top of an embedded PHP block
      • Fixes a conflict between this sniff and the Squiz.PHP.EmbeddedPHP sniff
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.WhiteSpace.MemberVarSpacing no longer checks spacing before member vars that come directly after methods
      • Fixes a conflict between this sniff and the Squiz.WhiteSpace.FunctionSpacing sniff
    • Squiz.WhiteSpace.SuperfluousWhitespace now recognizes unicode whitespace at the start and end of a file
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2029 : Squiz.Scope.MemberVarScope throws fatal error when a property is found in an interface
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2047 : PSR12.Classes.ClassInstantiation false positive when instantiating class from array index
    • Fixed bug #2048 : GenericFormatting.MultipleStatementAlignment false positive when assigning values inside an array
    • Fixed bug #2053 : PSR12.Classes.ClassInstantiation incorrectly fix when using member vars and some variable formats
    • Fixed bug #2065 : Generic.ControlStructures.InlineControlStructure fixing fails when inline control structure contains closure
    • Fixed bug #2072 : Squiz.Arrays.ArrayDeclaration throws NoComma error when array value is a shorthand IF statement
    • Fixed bug #2082 : File with "defined() or define()" syntax triggers PSR1.Files.SideEffects.FoundWithSymbols
    • Fixed bug #2095 : PSR2.Namespaces.NamespaceDeclaration does not handle namespaces defined over multiple lines
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.08 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.08 MB)
    phpcs.phar.asc(587 bytes)
  • 3.3.0(Jun 7, 2018)

    Deprecations

    Squiz.WhiteSpace.LanguageConstructSpacing Sniff

    The Squiz.WhiteSpace.LanguageConstructSpacing sniff has been deprecated and will be removed in version 4.

    The sniff has been moved to the Generic standard, with a new code of Generic.WhiteSpace.LanguageConstructSpacing. The new Generic sniff now also checks many more language constructs to enforce additional spacing rules. The existing Squiz sniff will continue to work until version 4 has been released. Thanks to Mponos George for the contribution.

    As soon as possible, replace all instances of the old sniff code with the new sniff code in your ruleset.xml files.

    Setting Array Properties

    The current method for setting array properties in ruleset files has been deprecated and will be removed in version 4.

    Currently, setting an array value uses the string syntax print=>echo,create_function=>null. Now, individual array elements are specified using a new element tag with key and value attributes.

    For example, the following array of forbidden functions:

    <property name="forbiddenFunctions" type="array" value="sizeof=>count,delete=>unset,print=>echo,is_null=>null,create_function=>null"/>
    

    Will be rewritten using this format:

    <property name="forbiddenFunctions" type="array">
        <element key="sizeof" value="count"/>
        <element key="delete" value="unset"/>
        <element key="print" value="echo"/>
        <element key="is_null" value="null"/>
        <element key="create_function" value="null"/>
    </property>
    

    Thanks to Michał Bundyra for the patch.

    T_ARRAY_HINT Token

    The T_ARRAY_HINT token has been deprecated and will be removed in version 4.

    The token was used to ensure array type hints were not tokenized as T_ARRAY, but no other type hints were given a special token. Array type hints now use the standard T_STRING token instead.

    Sniffs referencing this token type will continue to run without error until version 4, but will not find any T_ARRAY_HINT tokens.

    T_RETURN_TYPE Token

    The T_RETURN_TYPE token has been deprecated and will be removed in version 4.

    The token was used to ensure array/self/parent/callable return types were tokenized consistently. But for namespaced return types, only the last part of the string (the class name) was tokenized as T_RETURN_TYPE. This was not consistent and so return types are now left using their original token types so they are not skipped by sniffs. The exception are array return types, which are tokenized as T_STRING instead of T_ARRAY, as they are used for type hints.

    Sniffs referencing this token type will continue to run without error until version 4, but will not find any T_RETUTN_TYPE tokens.

    To get the return type of a function, use the File::getMethodProperties() method, which now contains a return_type array index. This index contains the return type of the function or closer, or a blank string if not specified. If the return type is nullable, the return type will contain the leading? and a nullable_return_type array index in the return value will also be set to true. If the return type contains namespace information, it will be cleaned of whitespace and comments. To access the original return value string, use the main tokens array.

    PSR-12 Standard In-Progress

    This release contains an incomplete version of the PSR-12 coding standard. Errors found using this standard should be valid, but it will miss a lot of violations until it is complete. If you'd like to test and help, you can use the standard by running PHPCS with --standard=PSR12

    Other Changes

    • Config values set using --runtime-set now override any config values set in rulesets or the CodeSniffer.conf file
    • You can now apply include-pattern rules to individual message codes in a ruleset like you can with exclude-pattern rules
      • Previously, include-pattern rules only applied to entire sniffs
      • If a message code has both include and exclude patterns, the exclude patterns will be ignored
    • Using PHPCS annotations to selectively re-enable sniffs is now more flexible
      • Previously, you could only re-enable a sniff/category/standard using the exact same code that was disabled
      • Now, you can disable a standard and only re-enable a specific category or sniff
      • Or, you can disable a specific sniff and have it re-enable when you re-enable the category or standard
    • The value of array sniff properties can now be set using phpcs:set annotations
      • e.g., phpcs:set Standard.Category.SniffName property[] key=>value,key2=>value2
      • Thanks to Michał Bundyra for the patch
    • PHPCS annotations now remain as T_PHPCS_* tokens instead of reverting to comment tokens when --ignore-annotations is used
      • This stops sniffs (especially commenting sniffs) from generating a large number of false errors when ignoring
      • Any custom sniffs that are using the T_PHPCS_* tokens to detect annotations may need to be changed to ignore them
        • Check $phpcsFile->config->annotations to see if annotations are enabled and ignore when false
    • You can now use fully or partially qualified class names for custom reports instead of absolute file paths
      • To support this, you must specify an autoload file in your ruleset.xml file and use it to register an autoloader
      • Your autoloader will need to load your custom report class when requested
      • Thanks to Juliette Reinders Folmer for the patch
    • The JSON report format now does escaping in error source codes as well as error messages
      • Thanks to Martin Vasel for the patch
    • Invalid installed_paths values are now ignored instead of causing a fatal error
    • Improved testability of custom rulesets by allowing the installed standards to be overridden
      • Thanks to Timo Schinkel for the patch
    • The key used for caching PHPCS runs now includes all set config values
      • This fixes a problem where changing config values (e.g., via --runtime-set) used an incorrect cache file
    • The "Function opening brace placement" metric has been separated into function and closure metrics in the info report
      • Closures are no longer included in the "Function opening brace placement" metric
      • A new "Closure opening brace placement" metric now shows information for closures
    • Multi-line T_YIELD_FROM statements are now replicated properly for older PHP versions
    • The PSR2 standard no longer produces 2 error messages when the AS keyword in a foreach loop is not lowercase
    • Specifying a path to a non-existent dir when using the --report-[reportType]=/path/to/report CLI option no longer throws an exception
      • This now prints a readable error message, as it does when using --report-file
    • The File::getMethodParamaters() method now includes a type_hint_token array index in the return value
      • Provides the position in the token stack of the first token in the type hint
    • The File::getMethodProperties() method now includes a return_type_token array index in the return value
      • Provides the position in the token stack of the first token in the return type
    • The File::getTokensAsString() method can now optionally return original (non tab-replaced) content
      • Thanks to Juliette Reinders Folmer for the patch
    • Removed Squiz.PHP.DisallowObEndFlush from the Squiz standard
      • If you use this sniff and want to continue banning ob_end_flush(), use Generic.PHP.ForbiddenFunctions instead
      • You will need to set the forbiddenFunctions property in your ruleset.xml file
    • Removed Squiz.PHP.ForbiddenFunctions from the Squiz standard
      • Replaced by using the forbiddenFunctions property of Generic.PHP.ForbiddenFunctions in the Squiz ruleset.xml
      • Functionality of the Squiz standard remains the same, but the error codes are now different
      • Previously, Squiz.PHP.ForbiddenFunctions.Found and Squiz.PHP.ForbiddenFunctions.FoundWithAlternative
      • Now, Generic.PHP.ForbiddenFunctions.Found and Generic.PHP.ForbiddenFunctions.FoundWithAlternative
    • Added new Generic.PHP.LowerCaseType sniff
      • Ensures PHP types used for type hints, return types, and type casting are lowercase
      • Thanks to Juliette Reinders Folmer for the contribution
    • Added new Generic.WhiteSpace.ArbitraryParenthesesSpacing sniff
      • Generates an error for whitespace inside parenthesis that don't belong to a function call/declaration or control structure
      • Generates a warning for any empty parenthesis found
      • Allows the required spacing to be set using the spacing sniff property (default is 0)
      • Allows newlines to be used by setting the ignoreNewlines sniff property (default is false)
      • Thanks to Juliette Reinders Folmer for the contribution
    • Added new PSR12.Classes.ClassInstantiation sniff
      • Ensures parenthesis are used when instantiating a new class
    • Added new PSR12.Keywords.ShortFormTypeKeywords sniff
      • Ensures the short form of PHP types is used when type casting
    • Added new PSR12.Namespaces.CompundNamespaceDepth sniff
      • Ensures compound namespace use statements have a max depth of 2 levels
      • The max depth can be changed by setting the 'maxDepth' sniff property in a ruleset.xml file
    • Added new PSR12.Operators.OperatorSpacing sniff
      • Ensures operators are preceded and followed by at least 1 space
    • Improved core support for grouped property declarations
      • Also improves support in Squiz.WhiteSpace.ScopeKeywordSpacing and Squiz.WhiteSpace.MemberVarSpacing
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Commenting.DocComment now produces a NonParamGroup error when tags are mixed in with the @param tag group
      • It would previously throw either a NonParamGroup or ParamGroup error depending on the order of tags
      • This change allows the NonParamGroup error to be suppressed in a ruleset to allow the @param group to contain other tags
      • Thanks to Phil Davis for the patch
    • Generic.Commenting.DocComment now continues checks param tags even if the doc comment short description is missing
      • This change allows the MissingShort error to be suppressed in a ruleset without all other errors being suppressed as well
      • Thanks to Phil Davis for the patch
    • Generic.CodeAnalysis.AssignmentInCondition now reports a different error code for assignments found in WHILE conditions
      • The return value of a function call is often assigned in a WHILE condition, so this change makes it easier to exclude these cases
      • The new code for this error message is Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
      • The error code for all other cases remains as Generic.CodeAnalysis.AssignmentInCondition.Found
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Functions.OpeningFunctionBraceBsdAllman now longer leaves trailing whitespace when moving the opening brace during fixing
      • Also applies to fixes made by PEAR.Functions.FunctionDeclaration and Squiz.Functions.MultiLineFunctionDeclaration
    • Generic.WhiteSpace.ScopeIndent now does a better job of fixing the indent of multi-line comments
    • Generic.WhiteSpace.ScopeIndent now does a better job of fixing the indent of PHP open and close tags
    • PEAR.Commenting.FunctionComment now report a different error code for param comment lines with too much padding
      • Previously, any lines of a param comment that don't start at the exact comment position got the same error code
      • Now, only comment lines with too little padding use ParamCommentAlignment as they are clearly mistakes
      • Comment lines with too much padding may be using precision alignment as now use ParamCommentAlignmentExceeded
      • This allows for excessive padding to be excluded from a ruleset while continuing to enforce a minimum padding
    • PEAR.WhiteSpace.ObjectOperatorIndent now checks the indent of more chained operators
      • Previously, it only checked chains beginning with a variable
      • Now, it checks chains beginning with function calls, static class names, etc
    • Squiz.Arrays.ArrayDeclaration now continues checking array formatting even if the key indent is not correct
      • Allows for using different array indent rules while still checking/fixing double arrow and value alignment
    • Squiz.Commenting.BlockComment has improved support for tab-indented comments
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Commenting.BlockComment auto fixing no longer breaks when two block comments follow each other
      • Also stopped single-line block comments from being auto fixed when they are embedded in other code
      • Also fixed as issue found when PHPCS annotations were used inside a block comment
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Commenting.BlockComment.LastLineIndent is now able to be fixed with phpcbf
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Commenting.BlockComment now aligns star-prefixed lines under the opening tag while fixing, instead of indenting them
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Commenting.FunctionComment.IncorrectTypeHint message no longer contains cut-off suggested type hints
    • Squiz.Commenting.InlineComment now uses a new error code for inline comments at the end of a function
      • Previously, all inline comments followed by a blank line threw a Squiz.Commenting.InlineComment.SpacingAfter error
      • Now, inline comments at the end of a function will instead throw Squiz.Commenting.InlineComment.SpacingAfterAtFunctionEnd
      • If you previously excluded SpacingAfter, add an exclusion for SpacingAfterAtFunctionEnd to your ruleset as well
      • If you previously only included SpacingAfter, consider including SpacingAfterAtFunctionEnd as well
      • The Squiz standard now excludes SpacingAfterAtFunctionEnd as the blank line is checked elsewhere
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.ControlStructures.ControlSignature now errors when a comment follows the closing brace of an earlier body
      • Applies to catch, finally, else, elseif, and do/while structures
      • The included PSR2 standard now enforces this rule
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Formatting.OperatorBracket.MissingBrackets message has been changed to remove the word "arithmetic"
      • The sniff checks more than just arithmetic operators, so the message is now clearer
    • Sniffs.Operators.ComparisonOperatorUsage now detects more cases of implicit true comparisons
      • It could previously be confused by comparisons used as function arguments
    • Squiz.PHP.CommentedOutCode now ignores simple @-style annotation comments so they are not flagged as commented out code
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.PHP.CommentedOutCode now ignores a greater number of short comments so they are not flagged as commented out code
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.PHP.DisallowComparisonAssignment no longer errors when using the null coalescing operator
      • Given this operator is used almost exclusively to assign values, it didn't make sense to generate an error
    • Squiz.WhiteSpacing.FunctionSpacing now has a property to specify how many blank lines should be before the first class method
      • Only applies when a method is the first code block in a class (i.e., there are no member vars before it)
      • Override the 'spacingBeforeFirst' property in a ruleset.xml file to change
      • If not set, the sniff will use whatever value is set for the existing 'spacing' property
    • Squiz.WhiteSpacing.FunctionSpacing now has a property to specify how many blank lines should be after the last class method
      • Only applies when a method is the last code block in a class (i.e., there are no member vars after it)
      • Override the 'spacingAfterLast' property in a ruleset.xml file to change
      • If not set, the sniff will use whatever value is set for the existing 'spacing' property
    • Fixed bug #1863 : File::findEndOfStatement() not working when passed a scope opener
    • Fixed bug #1876 : PSR2.Namespaces.UseDeclaration not giving error for use statements before the namespace declaration
      • Adds a new PSR2.Namespaces.UseDeclaration.UseBeforeNamespace error message
    • Fixed bug #1881 : Generic.Arrays.ArrayIndent is indenting sub-arrays incorrectly when comma not used after the last value
    • Fixed bug #1882 : Conditional with missing braces confused by indirect variables
    • Fixed bug #1915 : JS tokenizer fails to tokenize regular expression proceeded by boolean not operator
    • Fixed bug #1920 : Directory exclude pattern improperly excludes files with names that start the same
      • Thanks to Jeff Puckett for the patch
    • Fixed bug #1922 : Equal sign alignment check broken when list syntax used before assignment operator
    • Fixed bug #1925 : Generic.Formatting.MultipleStatementAlignment skipping assignments within closures
    • Fixed bug #1931 : Generic opening brace placement sniffs do not correctly support function return types
    • Fixed bug #1932 : Generic.ControlStructures.InlineControlStructure fixer moves new PHPCS annotations
    • Fixed bug #1938 : Generic opening brace placement sniffs incorrectly move PHPCS annotations
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1939 : phpcs:set annotations do not cause the line they are on to be ignored
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1949 : Squiz.PHP.DisallowMultipleAssignments false positive when using namespaces with static assignments
    • Fixed bug #1959 : SquizMultiLineFunctionDeclaration error when param has trailing comment
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1963 : Squiz.Scope.MemberVarScope does not work for multiline member declaration
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1971 : Short array list syntax not correctly tokenized if short array is the first content in a file
    • Fixed bug #1979 : Tokenizer does not change heredoc to nowdoc token if the start tag contains spaces
    • Fixed bug #1982 : Squiz.Arrays.ArrayDeclaration fixer sometimes puts a comma in front of the last array value
    • Fixed bug #1993 : PSR1/PSR2 not reporting or fixing short open tags
    • Fixed bug #1996 : Custom report paths don't work on case-sensitive filesystems
    • Fixed bug #2006 : Squiz.Functions.FunctionDeclarationArgumentSpacing fixer removes comment between parens when no args
      • The SpacingAfterOpenHint error message has been removed
        • It is replaced by the the existing SpacingAfterOpen message
      • The error message format for the SpacingAfterOpen and SpacingBeforeClose messages has been changed
        • These used to contain 3 pieces of data, but now only contain 2
      • If you have customised the error messages of this sniff, please review your ruleset after upgrading
    • Fixed bug #2018 : Generic.Formatting.MultipleStatementAlignment does see PHP close tag as end of statement block
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #2027 : PEAR.NamingConventions.ValidFunctionName error when function name includes double underscore
      • Thanks to Juliette Reinders Folmer for the patch
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.08 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.08 MB)
    phpcs.phar.asc(587 bytes)
  • 3.2.3(Feb 20, 2018)

    • The new phpcs: comment syntax can now be prefixed with an at symbol ( @phpcs: )
      • This restores the behaviour of the previous syntax where these comments are ignored by doc generators
    • The current PHP version ID is now used to generate cache files
      • This ensures that only cache files generated by the current PHP version are selected
      • This change fixes caching issues when using sniffs that produce errors based on the current PHP version
    • A new Tokens::$phpcsCommentTokens array is now available for sniff developers to detect phpcs: comment syntax
      • Thanks to Juliette Reinders Folmer for the patch
    • Error message codes generated by Generic.CodeAnalysis.EmptyStatement are no longer all-uppercase
      • For example Generic.CodeAnalysis.EmptyStatement.DetectedCATCH becomes Generic.CodeAnalysis.EmptyStatement.DetectedCatch
    • The PEAR.Commenting.FunctionComment.Missing error message now includes the name of the function
      • Thanks to Yorman Arias for the patch
    • The PEAR.Commenting.ClassComment.Missing and Squiz.Commenting.ClassComment.Missing error messages now include the name of the class
      • Thanks to Yorman Arias for the patch
    • PEAR.Functions.FunctionCallSignature now only forces alignment at a specific tab stop while fixing
      • It was enforcing this during checking, but this meant invalid errors if the OpeningIndent message was being muted
      • This fixes incorrect errors when using the PSR2 standard with some code blocks
    • Generic.Files.LineLength now ignores lines that only contain phpcs: annotation comments
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.Formatting.MultipleStatementAlignment now skips over arrays containing comments
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.PHP.Syntax now forces display_errors to ON when linting
      • Thanks to Raúl Arellano for the patch
    • PSR2.Namespaces.UseDeclaration has improved syntax error handling and closure detection
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.PHP.CommentedOutCode now has improved comment block detection for improved accuracy
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.PHP.NonExecutableCode could fatal error while fixing file with syntax error
    • Squiz.PHP.NonExecutableCode now detects unreachable code after a goto statement
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.WhiteSpace.LanguageConstructSpacing has improved syntax error handling while fixing
      • Thanks to Juliette Reinders Folmer for the patch
    • Improved phpcs: annotation syntax handling for a number of sniffs
      • Thanks to Juliette Reinders Folmer for the patch
    • Improved auto-fixing of files with incomplete comment blocks for various commenting sniffs
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed test suite compatibility with PHPUnit 7
    • Fixed bug #1793 : PSR2 forcing exact indent for function call opening statements
    • Fixed bug #1803 : Squiz.WhiteSpace.ScopeKeywordSpacing removes member var name while fixing if no space after scope keyword
    • Fixed bug #1817 : Blank line not enforced after control structure if comment on same line as closing brace
    • Fixed bug #1827 : A phpcs:enable comment is not tokenized correctly if it is outside a phpcs:disable block
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1828 : Squiz.WhiteSpace.SuperfluousWhiteSpace ignoreBlankLines property ignores whitespace after single line comments
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1840 : When a comment has too many asterisks, phpcbf gives FAILED TO FIX error
    • Fixed bug #1867 : Cant use phpcs:ignore where the next line is HTML
    • Fixed bug #1870 : Invalid warning in multiple assignments alignment with closure or anon class
    • Fixed bug #1890 : Incorrect Squiz.WhiteSpace.ControlStructureSpacing.NoLineAfterClose error between catch and finally statements
    • Fixed bug #1891 : Comment on last USE statement causes false positive for PSR2.Namespaces.UseDeclaration.SpaceAfterLastUse
      • Thanks to Matt Coleman, Daniel Hensby, and Juliette Reinders Folmer for the patch
    • Fixed bug #1901 : Fixed PHPCS annotations in multi-line tab-indented comments + not ignoring whole line for phpcs:set
      • Thanks to Juliette Reinders Folmer for the patch
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.02 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.02 MB)
    phpcs.phar.asc(587 bytes)
  • 3.2.2(Dec 19, 2017)

  • 3.2.1(Dec 18, 2017)

    • Fixed problems with some scripts and plugins waiting for STDIN
      • This was a notable problem with IDE plugins (e.g., PHPStorm) and build systems
    • Empty diffs are no longer followed by a newline character (request #1781)
    • Generic.Functions.OpeningFunctionBraceKernighanRitchie no longer complains when the open brace is followed by a close tag
      • This makes the sniff more useful when used in templates
      • Thanks to Joseph Zidell for the patch
    • Fixed bug #1782 : Incorrect detection of operator in ternary + anonymous function
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.01 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.01 MB)
    phpcs.phar.asc(587 bytes)
  • 3.2.0(Dec 12, 2017)

    Comment Syntax Changes

    This release deprecates the @codingStandards comment syntax used for sending commands to PHP_CodeSniffer. The existing syntax will continue to work in all version 3 releases, but will be removed in version 4

    The comment formats have been replaced by a shorter syntax:

    • @codingStandardsIgnoreFile becomes phpcs:ignoreFile
    • @codingStandardsIgnoreStart becomes phpcs:disable
    • @codingStandardsIgnoreEnd becomes phpcs:enable
    • @codingStandardsIgnoreLine becomes phpcs:ignore
    • @codingStandardsChangeSetting becomes phpcs:set

    The new syntax allows for additional developer comments to be added after a -- separator. This is useful for describing why a code block is being ignored, or why a setting is being changed. E.g., // phpcs:disable -- This code block must be left as-is.

    Comments using the new syntax are assigned new comment token types to allow them to be detected:

    • phpcs:ignoreFile has the token T_PHPCS_IGNORE_FILE
    • phpcs:disable has the token T_PHPCS_DISABLE
    • phpcs:enable has the token T_PHPCS_ENABLE
    • phpcs:ignore has the token T_PHPCS_IGNORE
    • phpcs:set has the token T_PHPCS_SET

    Other Changes

    • The phpcs:disable and phpcs:ignore comments can now selectively ignore specific sniffs (request #604)
      • E.g., // phpcs:disable Generic.Commenting.Todo.Found for a specific message
      • E.g., // phpcs:disable Generic.Commenting.Todo for a whole sniff
      • E.g., // phpcs:disable Generic.Commenting for a whole category of sniffs
      • E.g., // phpcs:disable Generic for a whole standard
      • Multiple sniff codes can be specified by comma separating them
        • E.g., // phpcs:disable Generic.Commenting.Todo,PSR1.Files
    • @codingStandardsIgnoreLine comments now only ignore the following line if they are on a line by themselves
      • If they are at the end of an existing line, they will only ignore the line they are on
      • Stops some lines from accidentally being ignored
      • Same rule applies for the new phpcs:ignore comment syntax
    • PSR1.Files.SideEffects now respects the new phpcs:disable comment syntax
      • The sniff will no longer check any code that is between phpcs:disable and phpcs:enable comments
      • The sniff does not support phpcs:ignore; you must wrap code structures with disable/enable comments
      • Previously, there was no way to have this sniff ignore parts of a file
    • Fixed a problem where PHPCS would sometimes hang waiting for STDIN, or read incomplete versions of large files
      • Thanks to Arne Jørgensen for the patch
    • Array properties specified in ruleset files now have their keys and values trimmed
      • This saves having to do this in individual sniffs and stops errors introduced by whitespace in rulesets
      • Thanks to Juliette Reinders Folmer for the patch
    • Added phpcs.xsd to allow validation of ruleset XML files
      • Thanks to Renaat De Muynck for the contribution
    • File paths specified using --stdin-path can now point to fake file locations (request #1488)
      • Previously, STDIN files using fake file paths were excluded from checking
    • Setting an empty basepath (--basepath=) on the CLI will now clear a basepath set directly in a ruleset
      • Thanks to Xaver Loppenstedt for the patch
    • Ignore patterns are now checked on symlink target paths instead of symlink source paths
      • Restores previous behaviour of this feature
    • Metrics were being double counted when multiple sniffs were recording the same metric
    • Added support for bash process substitution
      • Thanks to Scott Dutton for the contribution
    • Files included in the cache file code hash are now sorted to aid in cache file reuse across servers
    • Windows BAT files can now be used outside a PEAR install
      • You must have the path to PHP set in your PATH environment variable
      • Thanks to Joris Debonnet for the patch
    • The JS unsigned right shift assignment operator is now properly classified as an assignment operator
      • Thanks to Juliette Reinders Folmer for the patch
    • The AbstractVariableSniff abstract sniff now supports anonymous classes and nested functions
      • Also fixes an issue with Squiz.Scope.MemberVarScope where member vars of anonymous classes were not being checked
    • Added AbstractArraySniff to make it easier to create sniffs that check array formatting
      • Allows for checking of single and multi line arrays easily
      • Provides a parsed structure of the array including positions of keys, values, and double arrows
    • Added Generic.Arrays.ArrayIndent to enforce a single tab stop indent for array keys in multi-line arrays
      • Also ensures the close brace is on a new line and indented to the same level as the original statement
      • Allows for the indent size to be set using an indent property of the sniff
    • Added Generic.PHP.DiscourageGoto to warn about the use of the GOTO language construct
      • Thanks to Juliette Reinders Folmer for the contribution
    • Generic.Debug.ClosureLinter was not running the gjslint command
      • Thanks to Michał Bundyra for the patch
    • Generic.WhiteSpace.DisallowSpaceIndent now fixes space indents in multi-line block comments
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.WhiteSpace.DisallowSpaceIndent now fixes mixed space/tab indents more accurately
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.WhiteSpace.DisallowTabIndent now fixes tab indents in multi-line block comments
      • Thanks to Juliette Reinders Folmer for the patch
    • PEAR.Functions.FunctionDeclaration no longer errors when a function declaration is the first content in a JS file
      • Thanks to Juliette Reinders Folmer for the patch
    • PEAR.Functions.FunctionCallSignature now requires the function name to be indented to an exact tab stop
      • If the function name is not the start of the statement, the opening statement must be indented correctly instead
      • Added a new fixable error code PEAR.Functions.FunctionCallSignature.OpeningIndent for this error
    • Squiz.Functions.FunctionDeclarationArgumentSpacing is no longer confused about comments in function declarations
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.PHP.NonExecutableCode error messages now indicate which line the code block ending is on
      • Makes it easier to identify where the code block exited or returned
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.Commenting.FunctionComment now supports nullable type hints
    • Squiz.Commenting.FunctionCommentThrowTag no longer assigns throw tags inside anon classes to the enclosing function
    • Squiz.WhiteSpace.SemicolonSpacing now ignores semicolons used for empty statements inside FOR conditions
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.ControlStructures.ControlSignature now allows configuring the number of spaces before the colon in alternative syntax
      • Override the requiredSpacesBeforeColon setting in a ruleset.xml file to change
      • Default remains at 1
      • Thanks to Nikola Kovacs for the patch
    • The Squiz standard now ensures array keys are indented 4 spaces from the main statement
      • Previously, this standard aligned keys 1 space from the start of the array keyword
    • The Squiz standard now ensures array end braces are aligned with the main statement
      • Previously, this standard aligned the close brace with the start of the array keyword
    • The standard for PHP_CodeSniffer itself now enforces short array syntax
    • The standard for PHP_CodeSniffer itself now uses the Generic.Arrays/ArrayIndent sniff rules
    • Improved fixer conflicts and syntax error handling for a number of sniffs
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1462 : Error processing cyrillic strings in Tokenizer
    • Fixed bug #1573 : Squiz.WhiteSpace.LanguageConstructSpacing does not properly check for tabs and newlines
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #1590 : InlineControlStructure CBF issue while adding braces to an if thats returning a nested function
    • Fixed bug #1718 : Unclosed strings at EOF sometimes tokenized as T_WHITESPACE by the JS tokenizer
    • Fixed bug #1731 : Directory exclusions do not work as expected when a single file name is passed to phpcs
    • Fixed bug #1737 : Squiz.CSS.EmptyStyleDefinition sees comment as style definition and fails to report error
    • Fixed bug #1746 : Very large reports can sometimes become garbled when using the parallel option
    • Fixed bug #1747 : Squiz.Scope.StaticThisUsage incorrectly looking inside closures
    • Fixed bug #1757 : Unknown type hint "object" in Squiz.Commenting.FunctionComment
    • Fixed bug #1758 : PHPCS gets stuck creating file list when processing circular symlinks
    • Fixed bug #1761 : Generic.WhiteSpace.ScopeIndent error on multi-line function call with static closure argument
    • Fixed bug #1762 : Generic.WhiteSpace.Disallow[Space/Tab]Indent not inspecting content before open tag
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1769 : Custom "define" function triggers a warning about declaring new symbols
    • Fixed bug #1776 : Squiz.Scope.StaticThisUsage incorrectly looking inside anon classes
    • Fixed bug #1777 : Generic.WhiteSpace.ScopeIndent incorrect indent errors when self called function proceeded by comme
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.01 MB)
    phpcbf.phar.asc(587 bytes)
    phpcs.phar(1.01 MB)
    phpcs.phar.asc(587 bytes)
  • 3.1.1(Oct 16, 2017)

    • Restored preference of non-dist files over dist files for phpcs.xml and phpcs.xml.dist
      • The order that the files are searched is now: .phpcs.xml, phpcs.xml, .phpcs.xml.dist, phpcs.xml.dist
      • Thanks to Juliette Reinders Folmer for the patch
    • Progress output now correctly shows skipped files
    • Progress output now shows 100% when the file list has finished processing (request #1697)
    • Stopped some IDEs complaining about testing class aliases
      • Thanks to Vytautas Stankus for the patch
    • Squiz.Commenting.InlineComment incorrectly identified comment blocks in some cases, muting some errors
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1512 : PEAR.Functions.FunctionCallSignature enforces spaces when no arguments if required spaces is not 0
    • Fixed bug #1522 : Squiz Arrays.ArrayDeclaration and Strings.ConcatenationSpacing fixers causing parse errors with here/nowdocs
    • Fixed bug #1570 : Squiz.Arrays.ArrayDeclaration fixer removes comments between array keyword and open parentheses
    • Fixed bug #1604 : File::isReference has problems with some bitwise operators and class property references
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1645 : Squiz.Commenting.InlineComment will fail to fix comments at the end of the file
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1656 : Using the --sniffs argument has a problem with case sensitivity
    • Fixed bug #1657 : Uninitialized string offset: 0 when sniffing CSS
    • Fixed bug #1669 : Temporary expression proceeded by curly brace is detected as function call
    • Fixed bug #1681 : Huge arrays are super slow to scan with Squiz.Arrays.ArrayDeclaration sniff
    • Fixed bug #1694 : Squiz.Arrays.ArrayBracketSpacing is removing some comments during fixing
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1702 : Generic.WhiteSpaceDisallowSpaceIndent fixer bug when line only contains superfluous whitespace
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1.00 MB)
    phpcs.phar(1.00 MB)
  • 3.1.0(Sep 19, 2017)

    Unit Test Changes

    • This release includes a change to support newer versions of PHPUnit (versions 4, 5, and 6 are now supported)
      • The custom PHP_CodeSniffer test runner now requires a bootstrap file
      • Developers with custom standards using the PHP_CodeSniffer test runner will need to do one of the following:
        • run your unit tests from the PHP_CodeSniffer root dir so the bootstrap file is included
        • specify the PHP_CodeSniffer bootstrap file on the command line: phpunit --bootstrap=/path/to/phpcs/tests/bootstrap.php
        • require the PHP_CodeSniffer bootstrap file from your own bootstrap file
      • If you don't run PHP_CodeSniffer unit tests, this change will not affect you
      • Thanks to Juliette Reinders Folmer for the patch

    Other Changes

    • A phpcs.xml or phpcs.xml.dist file now takes precedence over the default_standard config setting
      • Thanks to Björn Fischer for the patch
    • Both phpcs.xml and phpcs.xml.dist files can now be prefixed with a dot (request #1566)
      • The order that the files are searched is: .phpcs.xml, .phpcs.xml.dist, phpcs.xml, phpcs.xml.dist
    • The autoloader will now search for files during unit tests runs from the same locations as during normal phpcs runs
      • Allows for easier unit testing of custom standards that use helper classes or custom namespaces
    • Include patterns for sniffs now use OR logic instead of AND logic
      • Previously, a file had to be in each of the include patterns to be processed by a sniff
      • Now, a file has to only be in at least one of the patterns
      • This change reflects the original intention of the feature
    • PHPCS will now follow symlinks under the list of checked directories
      • This previously only worked if you specified the path to a symlink on the command line
    • Output from --config-show, --config-set, and --config-delete now includes the path to the loaded config file
    • PHPCS now cleanly exits if its config file is not readable
      • Previously, a combination of PHP notices and PHPCS errors would be generated
    • Comment tokens that start with /** are now always tokenized as docblocks
      • Thanks to Michał Bundyra for the patch
    • The PHP-supplied T_YIELD and T_YIELD_FROM tokens have been replicated for older PHP versions
      • Thanks to Michał Bundyra for the patch
    • Added new Generic.CodeAnalysis.AssignmentInCondition sniff to warn about variable assignments inside conditions
      • Thanks to Juliette Reinders Folmer for the contribution
    • Added Generic.Files.OneObjectStructurePerFile sniff to ensure there is a single class/interface/trait per file
      • Thanks to Mponos George for the contribution
    • Function call sniffs now check variable function names and self/static object creation
      • Specific sniffs are Generic.Functions.FunctionCallArgumentSpacing, PEAR.Functions.FunctionCallSignature, and PSR2.Methods.FunctionCallSignature
      • Thanks to Michał Bundyra for the patch
    • Generic.Files.LineLength can now be configured to ignore all comment lines, no matter their length
      • Set the ignoreComments property to TRUE (default is FALSE) in your ruleset.xml file to enable this
      • Thanks to Juliette Reinders Folmer for the patch
    • Generic.PHP.LowerCaseKeyword now checks self, parent, yield, yield from, and closure (function) keywords
      • Thanks to Michał Bundyra for the patch
    • PEAR.Functions.FunctionDeclaration now removes a blank line if it creates one by moving the curly brace during fixing
    • Squiz.Commenting.FunctionCommentThrowTag now supports PHP 7.1 multi catch exceptions
    • Squiz.Formatting.OperatorBracket no longer throws errors for PHP 7.1 multi catch exceptions
    • Squiz.Commenting.LongConditionClosingComment now supports finally statements
    • Squiz.Formatting.OperatorBracket now correctly fixes pipe separated flags
    • Squiz.Formatting.OperatorBracket now correctly fixes statements containing short array syntax
    • Squiz.PHP.EmbeddedPhp now properly fixes cases where the only content in an embedded PHP block is a comment
      • Thanks to Juliette Reinders Folmer for the patch
    • Squiz.WhiteSpace.ControlStructureSpacing now ignores comments when checking blank lines at the top of control structures
    • Squiz.WhiteSpace.ObjectOperatorSpacing now detects and fixes spaces around double colons
      • Thanks to Julius Šmatavičius for the patch
    • Squiz.WhiteSpace.MemberVarSpacing can now be configured to check any number of blank lines between member vars
      • Set the spacing property (default is 1) in your ruleset.xml file to set the spacing
    • Squiz.WhiteSpace.MemberVarSpacing can now be configured to check a different number of blank lines before the first member var
      • Set the spacingBeforeFirst property (default is 1) in your ruleset.xml file to set the spacing
    • Added a new PHP_CodeSniffer\Util\Tokens::$ooScopeTokens static member var for quickly checking object scope
      • Includes T_CLASS, T_ANON_CLASS, T_INTERFACE, and T_TRAIT
      • Thanks to Juliette Reinders Folmer for the patch
    • PHP_CodeSniffer\Files\File::findExtendedClassName() now supports extended interfaces
      • Thanks to Martin Hujer for the patch
    • Fixed bug #1550 : Squiz.Commenting.FunctionComment false positive when function contains closure
    • Fixed bug #1577 : Generic.InlineControlStructureSniff breaks with a comment between body and condition in do while loops
    • Fixed bug #1581 : Sniffs not loaded when one-standard directories are being registered in installed_paths
    • Fixed bug #1591 : Autoloader failing to load arbitrary files when installed_paths only set via a custom ruleset
    • Fixed bug #1605 : Squiz.WhiteSpace.OperatorSpacing false positive on unary minus after comment
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1615 : Uncaught RuntimeException when phpcbf fails to fix files
    • Fixed bug #1637 : Generic.WhiteSpaceScopeIndent closure argument indenting incorrect with multi-line strings
    • Fixed bug #1638 : Squiz.WhiteSpace.ScopeClosingBrace closure argument indenting incorrect with multi-line strings
    • Fixed bug #1640 : Squiz.Strings.DoubleQuoteUsage replaces tabs with spaces when fixing
      • Thanks to Juliette Reinders Folmer for the patch
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1023.63 KB)
    phpcs.phar(1023.62 KB)
  • 3.0.2(Jul 18, 2017)

    • Fixed a problem where the source report was not printing the correct number of errors found
    • Fixed a problem where the --cache=/path/to/cachefile CLI argument was not working
    • The code report now gracefully handles tokenizer exceptions
    • The phpcs and phpcbf scripts are now the only places that exit() in the code
      • This allows for easier usage of core PHPCS functions from external scripts
      • If you are calling Runner::runPHPCS() or Runner::runPHPCBF() directly, you will get back the full range of exit codes
      • If not, catch the new DeepExitException to get the error message ($e->getMessage()) and exit code ($e->getCode())
    • NOWDOC tokens are now considered conditions, just as HEREDOC tokens are
      • This makes it easier to find the start and end of a NOWDOC from any token within it
      • Thanks to Michał Bundyra for the patch
    • Custom autoloaders are now only included once in case multiple standards are using the same one
      • Thanks to Juliette Reinders Folmer for the patch
    • Improved tokenizing of fallthrough CASE and DEFAULT statements that share a closing statement and use curly braces
    • Improved the error message when Squiz.ControlStructures.ControlSignature detects a newline after the closing parenthesis
    • Fixed bug #1465 : Generic.WhiteSpace.ScopeIndent reports incorrect errors when indenting double arrows in short arrays
    • Fixed bug #1478 : Indentation in fallthrough CASE that contains a closure
    • Fixed bug #1497 : Fatal error if composer prepend-autoloader is set to false
      • Thanks to Kunal Mehta for the patch
    • Fixed bug #1503 : Alternative control structure syntax not always recognized as scoped
    • Fixed bug #1523 : Fatal error when using the --suffix argument
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1526 : Use of basepath setting can stop PHPCBF being able to write fixed files
    • Fixed bug #1530 : Generic.WhiteSpace.ScopeIndent can increase indent too much for lines within code blocks
    • Fixed bug #1547 : Wrong token type for backslash in use function
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #1549 : Squiz.PHP.EmbeddedPhp fixer conflict with // comment before PHP close tag
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1560 : Squiz.Commenting.FunctionComment fatal error when fixing additional param comment lines that have no indent
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1013.11 KB)
    phpcs.phar(1013.11 KB)
  • 3.0.1(Jun 14, 2017)

    Security Advisory

    • This release contains a fix for a security advisory related to the improper handling of a shell command
      • A properly crafted filename would allow for arbitrary code execution when using the --filter=gitmodified command line option
      • All version 3 users are encouraged to upgrade to this version, especially if you are checking 3rd-party code
        • e.g., you run PHPCS over libraries that you did not write
        • e.g., you provide a web service that runs PHPCS over user-uploaded files or 3rd-party repositories
        • e.g., you allow external tool paths to be set by user-defined values
      • If you are unable to upgrade but you check 3rd-party code, ensure you are not using the Git modified filter
      • This advisory does not affect PHP_CodeSniffer version 2.
      • Thanks to Sergei Morozov for the report and patch

    Other Changes

    • Arguments on the command line now override or merge with those specified in a ruleset.xml file in all cases
    • PHPCS now stops looking for a phpcs.xml file as soon as one is found, favoring the closest one to the current dir
    • Added missing help text for the --stdin-path CLI option to --help
    • Re-added missing help text for the --file-list and --bootstrap CLI options to --help
    • Runner::runPHPCS() and Runner::runPHPCBF() now return an exit code instead of exiting directly (request #1484)
    • The Squiz standard now enforces short array syntax by default
    • The autoloader is now working correctly with classes created with class_alias()
    • The autoloader will now search for files inside all directories in the installed_paths config var
      • This allows autoloading of files inside included custom coding standards without manually requiring them
    • You can now specify a namespace for a custom coding standard, used by the autoloader to load non-sniff helper files
      • Also used by the autoloader to help other standards directly include sniffs for your standard
      • Set the value to the namespace prefix you are using for sniff files (everything up to \Sniffs\)
      • e.g., if your namespace format is MyProject\CS\Standard\Sniffs\Category set the namespace to MyProject\CS\Standard
      • If omitted, the namespace is assumed to be the same as the directory name containing the ruleset.xml file
      • The namespace is set in the ruleset tag of the ruleset.xml file
      • e.g., <ruleset name="My Coding Standard" namespace="MyProject\CS\Standard">
    • Rulesets can now specify custom autoloaders using the new autoload tag
      • Autoloaders are included while the ruleset is being processed and before any custom sniffs are included
      • Allows for very custom autoloading of helper classes well before the bootstrap files are included
    • The PEAR standard now includes Squiz.Commenting.DocCommentAlignment
      • It previously broke comments onto multiple lines, but didn't align them
    • Fixed a problem where excluding a message from a custom standard's own sniff would exclude the whole sniff
      • This caused some PSR2 errors to be under-reported
    • Fixed bug #1442 : T_NULLABLE detection not working for nullable parameters and return type hints in some cases
    • Fixed bug #1447 : Running the unit tests with a phpunit config file breaks the test suite
      • Unknown arguments were not being handled correctly, but are now stored in $config->unknown
    • Fixed bug #1449 : Generic.Classes.OpeningBraceSameLine doesn't detect comment before opening brace
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1450 : Coding standard located under an installed_path with the same directory name throws an error
      • Thanks to Juliette Reinders Folmer for the patch
    • Fixed bug #1451 : Sniff exclusions/restrictions dont work with custom sniffs unless they use the PHP_CodeSniffer NS
    • Fixed bug #1454 : Squiz.WhiteSpace.OperatorSpacing is not checking spacing on either side of a short ternary operator
      • Thanks to Mponos George for the patch
    • Fixed bug #1495 : Setting an invalid installed path breaks all commands
    • Fixed bug #1496 : Squiz.Strings.DoubleQuoteUsage not unescaping dollar sign when fixing
      • Thanks to Michał Bundyra for the patch
    • Fixed bug #1501 : Interactive mode is broken
    • Fixed bug #1504 : PSR2.Namespaces.UseDeclaration hangs fixing use statement with no trailing code
    Source code(tar.gz)
    Source code(zip)
    phpcbf.phar(1007.81 KB)
    phpcs.phar(1007.81 KB)
  • 2.9.1(May 22, 2017)

Owner
Squiz Labs
Squiz Labs
Composer installer for PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

Dealerdirect 462 Dec 22, 2022
This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

PHPCSStandards 393 Feb 25, 2022
A tool to automatically fix PHP Coding Standards issues

PHP Coding Standards Fixer The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP codi

null 11.6k Jan 1, 2023
A tool to automatically fix Twig Coding Standards issues

Twig CS Fixer Installation This standard can be installed with the Composer dependency manager. Add the coding standard as a dependency of your projec

Vincent Langlet 50 Jan 6, 2023
Set of rules for PHP_CodeSniffer and PHP-CS-Fixer used by Symplify projects.

20+ Coding Standard checkers for PHP projects with focus on Clean Architecture

null 281 Dec 30, 2022
Documentation on clean coding and demonstration of studied clean coding principals with PHP.

practice-php-clean-code Documentation on clean coding and demonstration of studied clean coding principals with PHP. The document contained in this re

Ferdous Islam 1 Feb 21, 2022
Coding-standard - Magento PHP CodeSniffer Coding Standard

ECG Magento Code Sniffer Coding Standard ECG Magento Code Sniffer Coding Standard is a set of rules and sniffs for PHP_CodeSniffer tool. It allows aut

Magento ECG 309 Jan 3, 2023
Checks prefer-lowest installation for actually defined min versions in composer.json

Composer Prefer Lowest Validator This validator will strictly compare the specified minimum versions of your composer.json with the ones actually used

Mark Scherer 17 Aug 7, 2022
Banana detect adblock :Detects ad blockers (AdBlock, ublock, ...)

banana detect adblock :Detects ad blockers (AdBlock, ublock, ...)

banana 24 Dec 28, 2022
A wrapper around symplify/config-transformer used to update recipes and using easy coding standard for generating readable config files.

Symfony Recipes Yaml to PHP Converter This is a wrapper around the symplify/config-transformer used to convert Symfony core recipes which uses .yaml c

Alexander Schranz 3 Nov 24, 2022
Check modules in app/code and vendor for PHP 8 compatibility status - PHP_CodeSniffer & php-compatibility standard

M2 PHP version compatibility check How To use Requires PHP 7.3+ | PHP 8 This app will run PHP_CodeSniffer with phpcompatibility/php-compatibility on t

William Tran 24 Oct 13, 2022
Naive Bayes works by looking at a training set and making a guess based on that set.

Naive Bayes Naive Bayes works by looking at a training set and making a guess based on that set. It uses simple statistics and a bit of math to calcul

Assisted Mindfulness 29 Nov 27, 2022
The Easiest way to start using PHP CS Fixer and PHP_CodeSniffer with 0-knowledge

The Easiest Way to Use Any Coding Standard Features Blazing fast Parallel run Use PHP_CodeSniffer || PHP-CS-Fixer - anything you like 2nd run under fe

null 1.1k Jan 6, 2023
ExtDN PHP_CodeSniffer rules for Magento 2

ExtDN PHP_CodeSniffer rules for Magento 2 Introduction There are already many PHP CodeSniffer rules out there to aid in Magento 2 development: Magento

ExtDN 81 Dec 16, 2022
meterN is a lightweight set of PHP/JS files that make a " Home energy metering & monitoring " solution.

meterN - Home energy monitor - (PHP/JS Energy Metering & Monitoring) What can meterN do for you ? meterN is a lightweight set of PHP/JS files that mak

Jean-Marc Louviaux 4 Nov 30, 2022
Sitepackage for TYPO3 CMS that adheres to the recommended standards, maps all conceivable functional areas and contains examples for common use cases.

TYPO3 CMS Sitepackage This sitepackage sticks as closely as possible to the recommended standard and maps all conceivable functional areas. There are

Eric Bode 3 Dec 18, 2022
A collection of standards as PHP Enums: ISO3166, ISO4217, ISO639...

Standards A collection of standards as PHP Enums Setup Make sure you are running PHP 8.1 or higher to use this package To start right away, run the fo

null 295 Dec 20, 2022
Standards Alignment Tool

Standards Alignment Tool (SALT) [] Overview This is a prototype for testing the IMS Global Learning Consortium® CASE™ Specification and proving its us

OpenSALT 39 Dec 14, 2022
The tool converts different error reporting standards for deep compatibility with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc).

JBZoo / CI-Report-Converter Why? Installing Using as GitHub Action Example GitHub Action workflow Available Directions Help description in terminal Co

JBZoo Toolbox 17 Jun 16, 2022