NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
Packagist, #185 most downloaded on Packagist
PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
Latest stable
4.0.4
Last release 3 months ago
06 Aug 2026
Ships unpredictably
gaps range from 8 days to 9 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
14 years old
109 releases · first in 2012
Drag across the ruler to compare, or tap a release to open it.
_The 4.0.2 release, the 4.0.3 and the 4.0.4 release are 100% the same (aside from the version number), there was just a slight snafu in the release pu
The 4.0.2 release, the 4.0.3 and the 4.0.4 release are 100% the same (aside from the version number), there was just a slight snafu in the release publication on GitHub (missing PHAR assets). Sorry for the confusion.
This is a security release and all users are advised to update their install(s) as soon as possible. The security issue only affects users of the Gitb…
This is a security release and all users are advised to update their install(s) as soon as possible.
The security issue only affects users of the Gitblame, Hgblame or Svnblame report(s).
(void) cast. #1325
The T_VOID_CAST token has been added to the Tokens::CAST_TOKENS array.suggest section to the composer.json file to inform users about the recommended iconv and pcntl PHP extensions. #1388
libxml is a required PHP extension. #1409$this in static closures. #1377WrongOpener*) has been made more informative. #1358. Fixes #1322.
PEAR.Functions.FunctionDeclaration #1445
CloseBracketLine error message now exposes 1 data value (previously 0).EmptyLine error message now exposes 1 data value (previously 0).Indent error message now exposes 3 data values (previously 2).PSR12.Classes.AnonClassDeclaration and Squiz.Functions.MultiLineFunctionDeclaration sniffs.PSR2.Classes.ClassDeclaration #1446
ExtendsLine and ImplementsLine error messages now expose 3 data values (previously 1).SpaceBeforeExtends and SpaceBeforeImplements error messages now expose 2 data values (previously 1).PSR12.Classes.AnonClassDeclaration and Squiz.Classes.ClassDeclaration sniffs.PSR2.ControlStructures.SwitchDeclaration #1447
defaultNotLower and caseNotLower error messages now expose 3 data values (previously 2).SpaceBeforeColonDEFAULT and SpaceBeforeColonCASE error messages now expose 1 data value (previously 0).BodyOnNextLineDEFAULT and BodyOnNextLineCASE error messages now expose 1 data value (previously 0).WrongOpenerdefault and WrongOpenercase error messages now expose 1 data value (previously 0).Squiz.ControlStructures.SwitchDeclaration #1449
CaseNotLower and DefaultNotLower error messages now expose 3 data values (previously 2).CaseIndent and DefaultIndent error messages now expose 2 data values (previously 0).SpaceBeforeColonCase and SpaceBeforeColonDefault error messages now expose 1 data value (previously 0).BreakIndent error message now exposes 1 data value (previously 0).SpacingAfterCase and SpacingAfterDefault error messages now expose 1 data value (previously 0).Squiz.Functions.FunctionDeclarationArgumentSpacing #1452
SpaceBeforeEquals error message now exposes 3 data values (previously 2).SpaceAfterEquals error message now exposes 3 data values (previously 2).Squiz.Functions.MultiLineFunctionDeclaration #1453
FirstParamSpacing and UseFirstParamSpacing error messages now expose 1 data value (previously 0).OneParamPerLine and UseOneParamPerLine error messages now expose 1 data value (previously 0).PSR12.Classes.AnonClassDeclaration sniff.Gitblame, Hgblame or Svnblame report(s) would process a file whose name contains shell metacharacters. #1473
Full report, or any of the other non-*blame reports, are not affected.$this in non-static closures nested in OO methods.phpcbf.
Squiz.Functions.MultiLineFunctionDeclaration sniff.The PHP_CodeSniffer project is happy to welcome the following new contributors: @bigdevlarry, @Faze-up, @jrchamp, @lazerg, @morozov, @ntdiary, @SAY-5
Closed: 10 issues Merged: 33 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Your coding agent can read these notes before it upgrades. Set up the MCP server →
Runtime support for PHP 8.5. All known PHP 8.5 deprecation notices have been fixed.
This release includes all improvements and bugfixes from PHP_CodeSniffer 3.13.5.
phpcs:ignore comma-separated rule reference lists.
phpcs:disable/phpcs:enable ignore annotations.switch.
case/default and "case breaking" statements.switch case condition or after a default keyword, was not regarded as a "scope_opener" for the case/default body.WrongOpener error is now also auto-fixable if the wrong opener is a PHP close tag.The PHP_CodeSniffer project is happy to welcome the following new contributors: @andrewnicols, @Soh1121
Closed: 2 issues Merged: 8 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
This release contains breaking changes.
This release contains breaking changes.
Upgrade guides for both ruleset maintainers/end-users, as well as for sniff developers and integrators, have been published to the Wiki.
You are strongly encouraged to read the upgrade guide applicable to your situation before upgrading.
This release includes all improvements and bugfixes from PHP_CodeSniffer 4.0.0-beta1, 4.0.0-RC1, 3.13.3 and 3.13.4.
exit/die/true/false/null will be tokenized as the keyword token and the token 'content' will include the leading backslash. #1201^8.4.0 || ^9.3.4 || ^10.5.32 || 11.3.3 - 11.5.28 || ^11.5.31. #1247
phpcbf on code provided via STDIN.
// phpcs:set for inline array properties did not handle a single item array with the value true, false or null correctly.phpcbf in parallel mode.master branch has been renamed to 3.x and the default branch has changed to the 4.x branch.
Closed: 5 issues Merged: 35 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
This release includes all improvements and bugfixes from PHP_CodeSniffer 4.0.0-beta1, 3.13.1 and 3.13.2.
This release includes all improvements and bugfixes from PHP_CodeSniffer 4.0.0-beta1, 3.13.1 and 3.13.2.
Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterVisbility has been changed to Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterVisibility. #1136phpcs:enable could sometimes override a later selective phpcs:ignore.
Calling all testers!
Please help by testing the RC release and reporting any issues you run into. Upgrade guides for both ruleset maintainers/end-users, as well as for sniff developers and integrators, have been published to the Wiki to help smooth the transition.
Closed: 2 issues Merged: 4 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
This is a security release and all users are advised to update their install(s) as soon as possible.
This is a security release and all users are advised to update their install(s) as soon as possible.
Gitblame, Hgblame or Svnblame report(s) would process a file whose name contains shell metacharacters. #1473
Full report, or any of the other non-*blame reports, are not affected.Closed: 0 issues Merged: 46 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Runtime support for PHP 8.5. All known PHP 8.5 deprecation notices have been fixed.
master branch has been renamed to 3.x and the default branch has changed to the 4.x branch.
The PHP_CodeSniffer project is happy to welcome the following new contributors: @andrewnicols
Closed: 2 issues Merged: 36 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Fixed bug #1215: PHP 8.5 "Using null as an array offset" deprecation notices.
Closed: 0 issues Merged: 3 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Tokenizer support for PHP 8.4 dereferencing of new expressions without wrapping parentheses. #1160
abstract properties. #1183
File::getMemberProperties() method now also supports abstract properties through a new is_abstract array index in the return value. #1184abstract properties:
exit/die is used as a fully qualified "function call", it will now be tokenized as T_NS_SEPARATOR + T_EXIT.true/false/null will now be tokenized as T_NS_SEPARATOR + T_TRUE/T_FALSE/T_NULL. #1201
T_NS_SEPARATOR + T_STRING.WrongOpener* error code is now auto-fixable if the identified "wrong opener" is a semi-colon. #1161
AbstractAfterVisibility error code.--parallel option fails if PHP_CodeSniffer is invoked via bash and the invokation creates a non-PHPCS-managed process.
--parallel scanning was enabled.The PHP_CodeSniffer project is happy to welcome the following new contributors: @benno5020, @NanoSector
Closed: 11 issues Merged: 40 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
The documentation for the following sniffs has been improved:
SpacingAfterSetVis[i]bility.
Closed: 0 issues Merged: 6 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Added support for PHP 8.4 properties with asymmetric visibility to File::getMemberProperties() through a new set_scope array index in the return value
set_scope array index in the return value. #1116
set_visibility and set_visibility_token array indexes in the return value. #1116
AvizKeywordOrder error code.SpacingAfterSetVisibility error code.AsymReadMissing. #1122
https://schema.phpcodesniffer.com/#.#/phpcs.xsd.Closed: 3 issues Merged: 24 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Nearly everything which was soft deprecated before is now hard deprecated and will show deprecation notices:
final properties to the following sniffs:
goto language construct keyword. #917
final modifier keyword is placed before a visibility keyword. #950
FinalAfterVisibility error code.--reports CLI flag. #1078
PHP_CodeSniffer\Sniffs\Sniff interface. #891-q (=quiet) CLI flag.Calling all testers!
The first beta release for PHP_CodeSniffer 4.0 has been tagged. Please help by testing the beta release and reporting any issues you run into. Upgrade guides for both ruleset maintainers/end-users, as well as for sniff developers and integrators, have been published to the Wiki to help smooth the transition.
Closed: 3 issues Merged: 29 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Added support for PHP 8.4 final properties to the following sniffs:
final properties to the following sniffs:
short_open_tag setting.@param tags.
final classes.
Diff + the Code reports are requested and caching is on.
The PHP_CodeSniffer project is happy to welcome the following new contributors: @devfrey
Closed: 1 issues Merged: 36 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Documentation for the following sniffs:
Generic.Functions.CallTimePassByReference sniff. See #921.
InvalidArgumentExceptions when displaying verbose information.
? in nullable types for readonly properties.
goto was not recognized as a terminating statement for a case/default in a switch control structure.
The PHP_CodeSniffer project is happy to welcome the following new contributors: @costdev
Closed: 0 issues Merged: 24 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
All deprecation are slated for removal in PHP_CodeSniffer 4.0.
is_final array index in the return value. #834
-h (Help) option now contains a more extensive list of "config" options which can be set. #809
--sniffs or --exclude command line arguments. #344
--generator command line argument. #709, #771
title attribute is missing, the documentation generation will now fall back to the sniff name as the title. #820
SpacingBeforePropertyModifier or NoSpaceBeforePropertyModifier error codes. #792
SpacingBeforeHint or NoSpaceBeforeHint error code, which was misleading.final and abstract modifier keywords. #604
Internal.PropertyDoesNotExist error code.All deprecation are slated for removal in PHP_CodeSniffer 4.0.
Sniff interface. See #694.
PHP_CodeSniffer\Generators\Text::printTitle() in favour of PHP_CodeSniffer\Generators\Text::getFormattedTitle()PHP_CodeSniffer\Generators\Text::printTextBlock() in favour of PHP_CodeSniffer\Generators\Text::getFormattedTextBlock()PHP_CodeSniffer\Generators\Text::printCodeComparisonBlock() in favour of PHP_CodeSniffer\Generators\Text::getFormattedCodeComparisonBlock()PHP_CodeSniffer\Generators\Markdown::printHeader() in favour of PHP_CodeSniffer\Generators\Markdown::getFormattedHeader()PHP_CodeSniffer\Generators\Markdown::printFooter() in favour of PHP_CodeSniffer\Generators\Markdown::getFormattedFooter()PHP_CodeSniffer\Generators\Markdown::printTextBlock() in favour of PHP_CodeSniffer\Generators\Markdown::getFormattedTextBlock()PHP_CodeSniffer\Generators\Markdown::printCodeComparisonBlock() in favour of PHP_CodeSniffer\Generators\Markdown::getFormattedCodeComparisonBlock()PHP_CodeSniffer\Generators\HTML::printHeader() in favour of PHP_CodeSniffer\Generators\HTML::getFormattedHeader()PHP_CodeSniffer\Generators\HTML::printToc() in favour of PHP_CodeSniffer\Generators\HTML::getFormattedToc()PHP_CodeSniffer\Generators\HTML::printFooter() in favour of PHP_CodeSniffer\Generators\HTML::getFormattedFooter()PHP_CodeSniffer\Generators\HTML::printTextBlock() in favour of PHP_CodeSniffer\Generators\HTML::getFormattedTextBlock()PHP_CodeSniffer\Generators\HTML::printCodeComparisonBlock() in favour of PHP_CodeSniffer\Generators\HTML::getFormattedCodeComparisonBlock()readonly properties.
[0 => ''].The PHP_CodeSniffer project is happy to welcome the following new contributors: @asispts, @braindawg, @DanielEScherzer, @peterwilsoncc
Closed: 5 issues Merged: 74 pull requests
Follow @phpcs on Mastodon or @PHP_CodeSniffer on X to stay informed.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Generic.ControlStructures.InlineControlStructure no longer unnecessarily listens for T_SWITCH tokens. #595
SpaceBeforeComma error. #783
equalsSpacing was set to 0.
equalsSpacing was set to 1.
Closed: 0 issues Merged: 14 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Generators/HTML + Markdown: the output will now be empty (no page header/footer) when there are no docs to display. #687
<standard> blocks. #723
<standard> blocks. #737
define().
DEFINE is encountered.
define.
define.
Closed: 2 issues Merged: 52 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Output from the --generator=... feature will respect the OS-expected EOL char in more places. #671
--generator=... feature will respect the OS-expected EOL char in more places. #671
The PHP_CodeSniffer project is happy to welcome the following new contributors: @MatmaRex
Closed: 1 issue Merged: 11 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Runtime support for PHP 8.4. All known PHP 8.4 deprecation notices have been fixed.
Generic.WhiteSpace.HereNowdocIdentifierSpacing sniff. #586, #637
<<< and the identifier string in heredoc/nowdoc start tokens.Generic.Strings.UnnecessaryHeredoc sniff. #633
$sniffClass is passed. #524, #625
--generator=... feature will now always be presented in natural order based on the sniff name(s). #668
AnnotationFound. #560, #627
SpacingAfterOpen error code has been replaced by the SpaceAfterOpen error code. The latter is a pre-existing code. The former appears to have been a typo. #582
Closed: 4 issues Merged: 42 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Various housekeeping, including improvements to the tests and documentation.
gh attestation verify [phpcs|phpcbf].phar -o PHPCSStandards. #574
The PHP_CodeSniffer project is happy to welcome the following new contributors: @maryo
Closed: 4 issues Merged: 19 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
The following sniff(s) have received efficiency improvements:
Reports::generateFileReport() method is now documented in the Reports interface. #523
TabsUsedHeredocCloser - to allow for selectively excluding the indentation check for heredoc/nowdoc closers.SpacesUsedHeredocCloser.The PHP_CodeSniffer project is happy to welcome the following new contributor: @biinari (with a whopping 9 merged PRs!)
We also welcome @klausi back to the project.
Furthermore, the project is happy to welcome @jetbrains as a corporate funder for the project, joining @automattic, @humanmade and @godaddy.
Closed: 2 issues Merged: 30 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
Documentation for the following sniffs:
File::findStartOfStatement(): the start of statement/expression determination for tokens in parentheses/short array brackets/others scopes, nested within match expressions, was incorrect in most cases.
The trickle down effect of the bug fixes made to the File::findStartOfStatement() method, is that the Generic.WhiteSpace.ScopeIndent and the PEAR.WhiteSpace.ScopeIndent sniffs should now be able to correctly determine and fix the indent for match expressions containing nested expressions.
These fixes also fix an issue with the Squiz.Arrays.ArrayDeclaration sniff and possibly other, unreported bugs.
Closed: 5 issues Merged: 7 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
Full Changelog: https://github.com/PHPCSStandards/PHP_CodeSniffer/compare/3.10.0...3.10.1
Tokenizer support for PHP 8.2 Disjunctive Normal Form (DNF) types. #3731, #387, #461
T_TYPE_OPEN_PARENTHESIS and T_TYPE_CLOSE_PARENTHESIS tokens to represent the parentheses in DNF types.parenthesis_opener and parenthesis_closer token array indexes set and the tokens between them will have the nested_parenthesis index.File::getMethodProperties(), File::getMethodParameters() and File::getMemberProperties() methods now all support DNF types. #471, #472, #473else and if correctly.
The PHP_CodeSniffer project is happy to welcome the following new contributors: @przemekhernik
Closed: 2 issues Merged: 26 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
Please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Full Changelog: https://github.com/PHPCSStandards/PHP_CodeSniffer/compare/3.9.2...3.10.0
ESLint 9.0 has been released and changes the supported configuration file format. The (deprecated) Generic.Debug.ESLint sniff only supports the "old"…
true or false; or contained true or false as part of a union type.
Generic.Debug.ESLint sniff only supports the "old" configuration file formats and when using the sniff to run ESLint, the ESLINT_USE_FLAT_CONFIG=false environment variable will need to be set when using ESLint >= 9.0.
For more information, see #436.Closed: 0 issues Merged: 22 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
If you like what you see, please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Fixed bug #404 : Test framework : fixed PHP 8.4 deprecation notice.
The PHP_CodeSniffer project is happy to welcome the following new contributors: @jaymcp @jpoliveira08
Closed: 2 issues Merged: 52 pull requests
If you like to stay informed about releases and more, follow @phpcs on Mastodon or @PHP_CodeSniffer on X.
New PHP_CodeSniffer\Sniffs\DeprecatedSniff interface to allow for marking a sniff as deprecated. #281
PHP_CodeSniffer\Sniffs\DeprecatedSniff interface to allow for marking a sniff as deprecated. #281
-q (quiet) mode, the deprecation notices will be hidden.-e) an asterix * will show next to deprecated sniffs.Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence sniff. #197
ShortOpenEchoNoSemicolon errorcode to allow for selectively ignoring missing semicolons in single line embedded PHP snippets within short open echo tags.phpcbf run. #308
AbstractSniffUnitTest class will now show a (non-build-breaking) warning when test case files contain fixable errors/warnings, but there is no corresponding .fixed file available in the test suite to verify the fixes against. #336
PHP_CodeSniffer\Filters\ExactMatch::getBlacklist() and PHP_CodeSniffer\Filters\ExactMatch::getWhitelist() methods are deprecated and will be removed in the 4.0 release. See #198.
ExactMatch::getDisallowedFiles() and ExactMatch::getAllowedFiles() methodsExactMatch cross-version compatible with both PHP_CodeSniffer 3.9.0+ as well as 4.0+, implement the new getDisallowedFiles() and getAllowedFiles() methods.
getDisallowedFiles() and getAllowedFiles() methods as well as the getBlacklist() and getWhitelist() are available, the new methods will take precedence over the old methods.Zend.Debug.CodeAnalyzer sniff. See #277.
MissingParamType error code will now be used instead of MissingParamName when a parameter name is provided, but not its type. Additionally, invalid type hint suggestions will no longer be provided in these cases.
switch case.
class keyword was not checked when the space included a new line or comment.
.github folder.The PHP_CodeSniffer project is happy to welcome the following new contributors: @joachim-n, @remicollet, @TimWolla
Closed: 8 issues Merged: 77 pull requests
💸 If you like what you see, please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Fixed bug [#226] : Generic.CodeAnalysis.ForLoopShouldBeWhileLoop : prevent a potential PHP 8.3 deprecation notice during live coding
-s is used
-s is used and messages wraps
true/false/null type declarations
parent, self or a namespace relative class name type declaration
The PHP_CodeSniffer project is happy to welcome the following new contributors: @anomiex, @dingo-d, @fcool, @lucc, @rodrigoprimo
Closed: 4 issues Merged: 63 pull requests
If you like what you see, please consider funding the PHP_CodeSniffer project. If you already do so: thank you!
Runtime support for PHP 8.3. All known PHP 8.3 deprecation notices have been fixed
Squizlabs/PHP_CodeSniffer is dead. Long live PHPCSStandards/PHP_CodeSniffer!
squizlabs/PHP_CodeSniffer repository has been abandoned. The PHPCSStandards/PHP_CodeSniffer repository will serve as the continuation of the project. For more information about this change, please read the announcement.
squizlabs/php_codesniffer package now points to the new repository and everything will continue to work as before.https://squizlabs.github.io/PHP_CodeSniffer/phars/ to https://phars.phpcodesniffer.com/phars/.https://squizlabs.github.io/PHP_CodeSniffer/[phpcs|phpcbf].phar or https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/[phpcs|phpcbf].phar to https://phars.phpcodesniffer.com/[phpcs|phpcbf].phar.git@github.com:squizlabs/PHP_CodeSniffer.git to git@github.com:PHPCSStandards/PHP_CodeSniffer.git.
squizlabs/PHP_CodeSniffer repository are invited to resubmit these to the PHPCSStandards/PHP_CodeSniffer repository.true as a stand-alone type declaration
File::getMethodProperties(), File::getMethodParameters() and File::getMemberProperties() methods now all support the true typetrue as a stand-alone type to a number of sniffs
Generic.PHP.RequireStrictTypes.Disabled error codeParamNameUnexpectedAmpersandPrefix error for parameters annotated as passed by reference while the parameter is not passed by reference
setUp()/tearDown() methods or overload the setUp() in the AbstractSniffUnitTest test case, they will need to be adjusted. See the PR details for further informationInternal.PropertyDoesNotExist errror on line 1 of the scanned file, but will not halt the execution of PHPCSauto report width (the default) a value of 80 columns will be used if the width cannot be determined
InvalidNoReturn when type is never
match inside of it
--basepath and running from project subdirectory
use keyword
use keyword for multi-line trait use statements
$unknown property
Thanks go to Dan Wallis (@fredden) and Danny van der Sluijs (@DannyvdSluijs) for reviewing quite a few of the PRs for this release. Additionally, thanks to Alexander Turek (@derrabus) for consulting on the repo change over.
Newer versions of Composer will now suggest installing PHPCS using require-dev instead of require
Fixed bug #3609: Methods/constants with name empty/isset/unset are always reported as error
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.
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:
never typeNote: 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.
T_ENUM_CASE token to represent the case statements inside an enumT_TYPE_INTERSECTION token to represent the ampersand character inside intersection typesFile::getMethodParameters now supports the new PHP 8.1 readonly token
property_readonly array index is included in the return value
readonly_token array index is included in the return value
Generic.PHP.LowerCaseKeywordPSR2.Classes.PropertyDeclarationSquiz.Commenting.BlockCommentSquiz.Commenting.DocCommentAlignmentSquiz.Commenting.VariableCommentSquiz.WhiteSpace.ScopeKeywordSpacingGeneric.PHP.UpperCaseConstant and Generic.PHP.LowerCaseConstant now ignore type declarations
true/false/null when used as valuesGeneric.PHP.LowerCaseType now supports the PHP 8.1 never type
@throwT_GOTO_LABEL
${
Fixed bug #3448 : PHP 8.1 deprecation notice while generating running time value
Generic.NamingConventions.ConstructorName no longer throws deprecation notices on PHP 8.1
Generic.Files.ExecutableFileGeneric.Files.LowercasedFilenameGeneric.Files.LineEndingsGeneric.Files.EndFileNewlineGeneric.Files.EndFileNoNewlineGeneric.PHP.ClosingPHPTagGeneric.PHP.SyntaxGeneric.VersionControl.GitMergeConflictGeneric.WhiteSpace.DisallowSpaceIndentGeneric.WhiteSpace.DisallowTabIndentT_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG and T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG are unsuedT_BITWISE_AND for all PHP versionsFile::getMethodParameters() no longer incorrectly returns argument attributes in the type hint array index
has_attributes array index is available and set to TRUE if the argument has attributes definedGeneric.NamingConventions.ConstructorName no longer throws deprecation notices on PHP 8.1
Squiz.Commenting.BlockComment now correctly applies rules for block comments after a short echo tag
PEAR.Commenting.FunctionCommentSquiz.Commenting.InlineCommentSquiz.Commenting.BlockCommentSquiz.Commenting.VariableCommentSquiz.WhiteSpace.MemberVarSpacingPHP_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 f
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:
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.
T_TYPE_UNION token is available to represent the pipe characterFile::getMethodParameters(), getMethodProperties(), and getMemberProperties() will now return union typesT_PARAM_NAME token is available to represent the label with the name of the function argument in itT_ATTRIBUTE token marks the start of an attributeT_ATTRIBUTE_END token is available to mark the end of an attributeattribute_owner and attribute_closer indexes are available in the tokens array for all tokens inside an attributePEAR.Commenting.ClassCommentPEAR.Commenting.FileCommentPSR1.Files.SideEffectsPSR12.Files.FileHeaderSquiz.Commenting.ClassCommentSquiz.Commenting.FileCommentSquiz.WhiteSpace.FunctionSpacing
T_MATCH token to process match expressionsT_MATCH_ARROW token is available to represent the arrows in match expressionsT_MATCH_DEFAULT token is available to represent the default keyword in match expressionsGeneric.CodeAnalysis.AssignmentInConditionGeneric.CodeAnalysis.EmptyPHPStatement
Generic.CodeAnalysis.EmptyStatementGeneric.PHP.LowerCaseKeywordPEAR.ControlStructures.ControlSignaturePSR12.ControlStructures.BooleanOperatorPlacementSquiz.Commenting.LongConditionClosingCommentSquiz.Commenting.PostStatementCommentSquiz.ControlStructures.LowercaseDeclarationSquiz.ControlStructures.ControlSignatureSquiz.Formatting.OperatorBracketSquiz.PHP.DisallowMultipleAssignmentsSquiz.Objects.ObjectInstantiationSquiz.WhiteSpace.ControlStructureSpacingT_FN_ARROW token has changed from "T_FN_ARROW" to "PHPCS_T_FN_ARROW" to avoid package conflicts
T_FN_ARROW constantFile::findStartOfStatement() now works correctly when passed the last token in a statementFile::getMethodParameters() now supports PHP 8.0 constructor property promotion
property_visibility and visibility_token index if property promotion is detectedFile::getMethodProperties() now includes a return_type_end_token index in the return value
--stdin-path--stdin-path to set the file pathGeneric.NamingConventions.AbstractClassNamePrefix to enforce that class names are prefixed with "Abstract"
Generic.NamingConventions.InterfaceNameSuffix to enforce that interface names are suffixed with "Interface"
Generic.NamingConventions.TraitNameSuffix to enforce that trait names are suffixed with "Trait"
Generic.CodeAnalysis.UnusedFunctionParameter can now be configured to ignore variable usage for specific type hints
ignoreTypeHints array property to a list of type hints to ignoreGeneric.Formatting.MultipleStatementAlignment can now align statements at the start of the assignment token
alignAtEnd sniff property to false to align the assignment tokenstrue, so the assigned values are alignedGeneric.PHP.LowerCaseType now supports checking of typed properties
Generic.PHP.LowerCaseType now supports checking of union types
PEAR.Commenting.FunctionComment and Squiz.Commenting.FunctionComment sniffs can now ignore private and protected methods
minimumVisibility sniff property to protected to ignore private methodsminimumVisibility sniff property to public to ignore both private and protected methodsprivate, so all methods are checkedPEAR.Commenting.FunctionComment and Squiz.Commenting.FunctionComment sniffs can now ignore return tags in any method
__construct and __destruct were ignoredspecialMethods sniff property__construct and __destruct onlyPSR2.ControlStructures.SwitchDeclaration now supports nested switch statements where every branch terminates
CASE only contained a SWITCH and no direct terminating statement, a fall-through error was displayedSWITCH has a terminating statementPSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket error message is now reported on the closing parenthesis token
Squiz.Commenting.FunctionComment is now able to ignore function comments that are only inheritdoc statements
skipIfInheritdoc sniff property to true to skip checking function comments if the content is only {@inhertidoc}false, so these comments will continue to report errorsSquiz.Commenting.FunctionComment now supports the PHP 8 mixed type
Squiz.PHP.NonExecutableCode now has improved handling of syntax errors
Squiz.WhiteSpace.ScopeKeywordSpacing now checks spacing when using PHP 8.0 constructor property promotion
is_readable()Squiz.PHP.DisallowMultipleAssignments sniff
Reverted a change to the way include/exclude patterns are processed for STDIN content
The PHP 8.0 T_NULLSAFE_OBJECT_OPERATOR token has been made available for older versions
T_NULLSAFE_OBJECT_OPERATOR token has been made available for older versions
T_OBJECT_OPERATOR have been modified to apply the same rules for the nullsafe object operatorPSR12.ControlStructures.BooleanOperatorPlacement.FoundMixed error message is now more accurate when using the allowOnly setting
PSR12.Functions.NullableTypeDeclaration now supports the PHP8 static return type
Squiz.Formatting.OperatorBracket false positive when exiting with a negative numberSquiz.PHP.DisallowComparisonAssignment false positive for methods called on an objectAdded support for PHP 8.0 magic constant dereferencing
File::getMethodProperties() now detects the PHP 8.0 static return type
Generic.NamingConventions.CamelCapsFunctionName no longer reports __serialize and __unserialize as invalid names
PEAR.NamingConventions.ValidFunctionName no longer reports __serialize and __unserialize as invalid names
Squiz.Scope.StaticThisUsage now detects usage of $this inside closures and arrow functions
The T_FN backfill now works more reliably so T_FN tokens only ever represent real arrow functions
T_FN backfill now works more reliably so T_FN tokens only ever represent real arrow functions
Generic.CodeAnalysis.EmptyPHPStatement now detects empty statements at the start of control structuresPEAR.Functions.FunctionCallSignature now always uses "parenthesis" instead of sometimes using "bracket"
The PHP 7.4 numeric separator backfill now works correctly for more float formats
File::getCondition() now accepts a 3rd argument that allows for the closest matching token to be returned
Generic.PHP.DisallowRequestSuperglobal to ban the use of the $_REQUEST superglobal
Generic.ControlStructures.InlineControlStructure no longer shows errors for while and for statements without a body
PSR12.ControlStructures.BooleanOperatorPlacement can now be configured to enforce a specific operator position
allowOnly property to first to enforce all boolean operators to be at the start of a lineallowOnly property to last to enforce all boolean operators to be at the end of a linePSR12.Files.ImportStatement now auto-fixes import statements by removing the leading slash
Squiz.ControlStructures.ForLoopDeclaration now has a setting to ignore newline characters
FALSE, so newlines are not allowed within for definitionsignoreNewlines setting in a ruleset.xml file to changeSquiz.PHP.InnerFunctions now handles multiple nested anon classes correctlyThe PHP 7.4 T_FN token has been made available for older versions
T_FN token has been made available for older versions
T_FN represents the fn string used for arrow functionsT_FN_ARROW token typefn will have a T_FN token for the function name, but have no scope information1_000 would tokenize as T_LNUMBER (1), T_STRING (_000)T_LNUMBER (1_000)File::getMethodParameters() now supports arrow functionsFile::getMethodProperties() now supports arrow functionsFixer::changeCodeBlockIndent() to change the indent of a code block while auto-fixing
Generic.Files.ExecutableFile sniff
Generic.CodeAnalysis.EmptyPhpStatement now reports unnecessary semicolons after control structure closing braces
Generic.PHP.LowerCaseKeyword now enforces that the fn keyword is lowercase
Generic.WhiteSpace.ScopeIndent now supports static arrow functionsPEAR.Functions.FunctionCallSignature now adjusts the indent of function argument contents during auto-fixing
PSR2.Methods.FunctionCallSignaturePSR2.ControlStructures.ControlStructureSpacing now checks whitespace before the closing parenthesis of multi-line control structures
PSR12.Functions.ReturnTypeDeclaration now checks the return type of arrow functions
PSR12.Traits.UseDeclaration now ensures all trait import statements are grouped together
Squiz.Functions.LowercaseFunctionKeywords now enforces that the fn keyword is lowercase
Generic.ControlStructures.DisallowYodaConditions now returns less false positives
Very very verbose diff report output has slightly changed to improve readability
--report=diff and -vvv command line argumentsPEAR.Functions.FunctionCallSignature.FirstArgumentPositionPSR2.Methods.FunctionCallSignature.FirstArgumentPositionPSR12.ControlStructures.BooleanOperatorPlacement no longer complains when multiple expressions appear on the same line
PSR12.Files.FileHeader no longer ignores comments preceding a use, namespace, or declare statementPSR12.Files.FileHeader now allows a hashbang line at the top of the file@var annotations as file docblocksFixed bug #2558 : PHP 7.4 throwing offset syntax with curly braces is deprecated message
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
T_NULLABLE inside property types, as it is elsewhereFile::getMemberProperties() method, which now contains a type array index
?type_token array indextype_end_token array indexnullable_type array index will also be set to TRUE--filter=gitstaged to check these filesphpcs.xsd schema now validates phpcs-only and phpcbf-only attributes correctly
File class now throw RuntimeException instead of TokenizerException
RuntimeExpection but now correctly throw TokenizerExceptionFile::getMethodParameters() method now returns more information, and supports closure USE groups
type_hint_end_token array indexdefault_token array indexdefault_equal_token array indexcomma_token array indexreference_token array indexvariadic_token array indexT_LIST token and it's opening and closing parentheses now contain references to each other in the tokens array
T_ANON_CLASS token and it's opening and closing parentheses now contain references to each other in the tokens array
T_BAD_CHARACTER token has been made available for older versions
Squiz.WhiteSpace.FunctionSpacing
info report to see blank lines before/after functionsSquiz.WhiteSpace.MemberVarSpacing
info report to see blank lines before member varsGeneric.ControlStructures.DisallowYodaConditions sniff
Generic.PHP.RequireStrictTypes sniff
Generic.WhiteSpace.SpreadOperatorSpacingAfter sniff
PSR12.Classes.AnonClassDeclaration sniff
PSR12.Classes.ClosingBrace sniff
PSR12.ControlStructures.BooleanOperatorPlacement sniff
PSR12.ControlStructures.ControlStructureSpacing sniff
PSR12.Files.DeclareStatement sniff
PSR12.Files.FileHeader sniff
PSR12.Files.ImportStatement sniff
PSR12.Files.OpenTag sniff
PSR12.Functions.ReturnTypeDeclaration sniff
PSR12.Properties.ConstantVisibility sniff
PSR12.Traits.UseDeclaration sniff
Generic.Files.LineLength ignoreComments property now ignores comments at the end of a line
Generic.Files.LineLength now only ignores unwrappable comments when the comment is on a line by itself
Generic.Functions.FunctionCallArgumentSpacing no longer checks spacing around assignment operators inside function calls
Squiz.WhiteSpace.OperatorSpacing sniff to enforce spacing around assignment operators
Generic.Functions.FunctionCallArgumentSpacing.NoSpaceBeforeEquals error has been removed
Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore insteadGeneric.Functions.FunctionCallArgumentSpacing.NoSpaceAfterEquals error has been removed
Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter insteadGeneric.WhiteSpace.ScopeIndent no longer performs exact indents checking for chained method calls
PEAR.WhiteSpace.ObjectOperatorIndent now supports multi-level chained statements
multilevel setting to TRUE in a ruleset.xml file to enable this behaviourPSR2.ControlStructures.ControlStructureSpacing now allows whitespace after the opening parenthesis if followed by a comment
PSR2.Classes.PropertyDeclaration now enforces a single space after a property type keyword
Squiz.Commenting.BlockComment no longer requires blank line before comment if it's the first content after the PHP open tag
Squiz.Functions.FunctionDeclarationArgumentSpacing now has more accurate error messages
SpaceAfterDefault error code to SpaceAfterEquals, which reflects the real errorSquiz.Functions.FunctionDeclarationArgumentSpacing now checks for no space after a reference operator
SpacingAfterReference error message in a ruleset.xml fileSquiz.Functions.FunctionDeclarationArgumentSpacing now checks for no space after a variadic operator
SpacingAfterVariadic error message in a ruleset.xml fileSquiz.Functions.MultiLineFunctionDeclaration now has improved fixing for the FirstParamSpacing and UseFirstParamSpacing errorsSquiz.Operators.IncrementDecrementUsage now suggests pre-increment of variables instead of post-increment
Squiz.PHP.DisallowMultipleAssignments now has a second error code for when assignments are found inside control structure conditions
Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructureSquiz.PHP.DisallowMultipleAssignments.FoundSquiz.WhiteSpace.FunctionSpacing now applies beforeFirst and afterLast spacing rules to nested functions
Squiz.WhiteSpace.OperatorSpacing now has improved handling of parse errors
Squiz.WhiteSpace.OperatorSpacing now checks spacing around the instanceof operator
Squiz.WhiteSpace.OperatorSpacing can now enforce a single space before assignment operators
ignoreSpacingBeforeAssignments sniff property to FALSE to enable checkingTRUE, so spacing before assignments is not checked by defaultSquiz.Arrays.ArrayDeclaration now has improved handling of syntax errors
Squiz.Arrays.ArrayDeclaration now has improved handling of syntax errorsThe PEAR installable version of PHPCS was missing some files, which have been re-included in this release. The result of these omissions were:
The PEAR installable version of PHPCS was missing some files, which have been re-included in this release. The result of these omissions were:
code report was not previously available for PEAR installsGeneric.Formatting.SpaceBeforeCast sniff was not previously available for PEAR installsGeneric.WhiteSpace.LanguageConstructSpacing sniff was not previously available for PEAR installsThanks to Juliette Reinders Folmer for the patch
T_PHPCS_SET tokens now contain sniffCode, sniffProperty, and sniffPropertyValue indexes
Generic.Commenting.DocComment error messages now contain the name of the comment tag that caused the error
Generic.ControlStructures.InlineControlStructure now handles syntax errors correctly
Generic.Debug.JSHint now longer requires rhino and can be run directly from the npm install
Generic.Files.LineEndings no longer adds superfluous new line at the end of JS and CSS files
Generic.Formatting.DisallowMultipleStatements no longer tries fix lines containing phpcs:ignore statements
Generic.Functions.FunctionCallArgumentSpacing now has improved performance and anonymous class support
Generic.WhiteSpace.ScopeIndent now respects changes to the exact property using phpcs:set mid-way through a file
exact rule for only some parts of a fileGeneric.WhiteSpace.ScopeIndent now disables exact indent checking inside all arrays
PEAR.Classes.ClassDeclaration now has improved handling of PHPCS annotations and tab indentsPSR12.Classes.ClassInstantiation has changed it's error code from MissingParenthesis to MissingParenthesesPSR12.Keywords.ShortFormTypeKeywords now ignores all spacing inside type casts during both checking and fixing
Squiz.Classes.LowercaseClassKeywords now examines the class keyword for anonymous classes
Squiz.ControlStructures.ControlSignature now has improved handling of parse errors
Squiz.Commenting.PostStatementComment fixer no longer adds a blank line at the start of a JS file that begins with a comment
Squiz.WhiteSpace.SuperfluousWhitespace sniffSquiz.Commenting.PostStatementComment now ignores comments inside control structure conditions, such as FOR loops
Squiz.ControlStructures.ForLoopDeclaration sniffSquiz.Commenting.FunctionCommentThrowTag now has improved support for unknown exception types and namespaces
Squiz.ControlStructures.ForLoopDeclaration has improved whitespace, closure, and empty expression support
SpacingAfterSecondNoThird error code has been removed as part of these fixesSquiz.CSS.ClassDefinitionOpeningBraceSpace now handles comments and indentation correctly
Squiz.CSS.ClassDefinitionClosingBrace now handles comments, indentation, and multiple statements on the same line correctly
Squiz.CSS.Opacity now handles comments correctly
Squiz.CSS.SemicolonSpacing now handles comments and syntax errors correctly
Squiz.NamingConventions.ValidVariableName now supports variables inside anonymous classes correctly
Squiz.PHP.LowercasePHPFunctions now handles use statements, namespaces, and comments correctly
Squiz.WhiteSpace.FunctionSpacing now fixes function spacing correctly when a function is the first content in a file
Squiz.WhiteSpace.SuperfluousWhitespace no longer throws errors for spacing between functions and properties in anon classes
Zend.Files.ClosingTag no longer adds a semi-colon during fixing of a file that only contains a comment
Zend.NamingConventions.ValidVariableName now supports variables inside anonymous classes correctly
The Generic.Formatting.NoSpaceAfterCast sniff has been deprecated and will be removed in version 4.
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.
T_BITWISE_NOT added for the bitwise not operator
T_NONET_NONE tokens with a tilde as the contents must now also look for T_BITWISE_NOTT_NONE as well as T_BITWISE_NOT to support older PHP_CodeSniffer versionsT_BINARY_CAST
b in b"some string with $var" would be a T_BINARY_CAST, but only when the string contained a varb is always tokenized as T_BINARY_CAST(binary) from T_STRING_CAST to T_BINARY_CASTextend="true" to the property tag
<property name="forbiddenFunctionNames" type="array" extend="true">$XDG_CACHE_HOME is set and points to a valid directory, it will be used for caching instead of the system temp directoryFile:: getMethodProperties() method now includes a has_body array index in the return value
File::getTokensAsString() method now throws an exception if the $start param is invalid
$length param is invalid, an empty string will be returnedGeneric.CodeAnalysis.EmptyPHPStatement sniff
Generic.Formatting.SpaceBeforeCast sniff
Generic.VersionControl.GitMergeConflict sniff
Generic.WhiteSpace.IncrementDecrementSpacing sniff
PSR12.Functions.NullableTypeDeclaration sniff
Generic.NamingConventions.CamelCapsFunctionNamePEAR.NamingConventions.ValidFunctionNamePSR1.Methods.CamelCapsMethodNamePSR2.Methods.MethodDeclarationSquiz.Scope.MethodScopeSquiz.Scope.StaticThisUsageGeneric.CodeAnalysis.UnusedFunctionParameter now only skips functions with empty bodies when the class implements an interface
Generic.CodeAnalysis.UnusedFunctionParameter now has additional error codes to indicate where unused params were found
FoundInExtendedClass: when the class extends anotherFoundInImplementedInterface: when the class implements an interfaceFound: used in all other cases, including closuresBeforeLastUsed: the unused param was positioned before the last used param in the function signatureAfterLastUsed: the unused param was positioned after the last used param in the function signatureFoundFoundBeforeLastUsedFoundAfterLastUsedFoundInExtendedClassFoundInExtendedClassBeforeLastUsedFoundInExtendedClassAfterLastUsedFoundInImplementedInterfaceFoundInImplementedInterfaceBeforeLastUsedFoundInImplementedInterfaceAfterLastUsedGeneric.Classes.DuplicateClassName now inspects traits for duplicate names as well as classes and interfaces
Generic.Files.InlineHTML now ignores a BOM at the start of the file
Generic.PHP.CharacterBeforePHPOpeningTag now ignores a BOM at the start of the file
Generic.Formatting.SpaceAfterCast now has a setting to specify how many spaces are required after a type cast
spacing setting in a ruleset.xml file to changeGeneric.Formatting.SpaceAfterCast now has a setting to ignore newline characters after a type cast
ignoreNewlines setting in a ruleset.xml file to changeGeneric.Formatting.SpaceAfterNot now has a setting to specify how many spaces are required after a NOT operator
spacing setting in a ruleset.xml file to changeGeneric.Formatting.SpaceAfterNot now has a setting to ignore newline characters after the NOT operator
ignoreNewlines setting in a ruleset.xml file to changePEAR.Functions.FunctionDeclaration now checks spacing before the opening parenthesis of functions with no body
PEAR.Functions.FunctionDeclaration now enforces no space before the semicolon in functions with no body
PSR2.Classes.PropertyDeclaration now checks the order of property modifier keywords
PSR2.Methods.MethodDeclaration now checks method declarations inside traits
Squiz.Commenting.InlineComment now has better detection of comment block boundariesSquiz.Classes.ClassFileName now checks that a trait name matches the filename
Squiz.Classes.SelfMemberReference now supports scoped declarations and anonymous classes
Squiz.Classes.SelfMemberReference now fixes multiple errors at once, increasing fixer performance
Squiz.Functions.LowercaseFunctionKeywords now checks abstract and final prefixes, and auto-fixes errors
Squiz.Objects.ObjectMemberComma.Missing has been renamed to Squiz.Objects.ObjectMemberComma.Found
Squiz.WhiteSpace.ObjectOperatorSpacing is now more tolerant of parse errorsSquiz.WhiteSpace.ObjectOperatorSpacing now fixes errors more efficiently
Fixed a problem where the report cache was not being cleared when the sniffs inside a standard were updated
--report=info) now has improved formatting for metrics that span multiple lines
.bak files when looking for test cases
Generic.PHP.NoSilencedErrors error messages now contain a code snippet to show the context of the error
Squiz.Arrays.ArrayDeclaration no longer reports errors for a comma on a line new after a here/nowdoc
SpaceBeforeComma error message has been changed to only have one data value instead of twoSquiz.Commenting.FunctionComment no longer errors when trying to fix indents of multi-line param commentsSquiz.Formatting.OperatorBracket now correctly fixes statements that contain stringsSquiz.PHP.CommentedOutCode now ignores more @-style annotations and includes better comment block detection
@var line contains a commentSupport 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
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.
full report (the default report) now has improved word wrapping for multi-line messages and sniff codes
summary report now sorts files based on their directory location instead of just a basic string sort
source report now orders error codes by name when they have the same number of errors
junit report no longer generates validation errors with the Jenkins xUnit plugin
Generic.Commenting.DocComment no longer generates the SpacingBeforeTags error if tags are the first content in the docblock
MissingShort error if there is no short commentMissingShort error to be suppressed in a ruleset to make short descriptions optionalGeneric.Functions.FunctionCallArgumentSpacing now properly fixes multi-line function calls with leading commas
Generic.PHP.Syntax will now use PHP_BINARY instead of trying to discover the executable path
php_path config var will still override this value as normalPSR2.Namespaces.UseDeclaration now supports commas at the end of group use declarations
Squiz.Arrays.ArrayDeclaration no longer removes the array opening brace while fixing
KeyNotAligned error message being incorrectly reported in these casesSquiz.Arrays.ArrayDeclaration no longer tries to change multi-line arrays to single line when they contain comments
Squiz.Classes.ClassDeclaration no longer enforces spacing rules when a class is followed by a function
Squiz.WhiteSpace.FunctionSpacing sniffSquiz.Classes.ValidClassName.NotCamelCaps message now references PascalCase instead of CamelCase
CamelCase class name metric produced by the sniff has been changed to PascalCase class nameSquiz.Commenting.InlineComment no longer enforces spacing rules when an inline comment is followed by a docblock
Squiz.WhiteSpace.FunctionSpacing sniffSquiz.WhiteSpace.OperatorSpacing no longer tries to fix operator spacing if the next content is a comment on a new line
Squiz.Commenting.PostStatementComment sniffSquiz.WhiteSpace.FunctionSpacing no longer checks spacing of functions at the top of an embedded PHP block
Squiz.PHP.EmbeddedPHP sniffSquiz.WhiteSpace.MemberVarSpacing no longer checks spacing before member vars that come directly after methods
Squiz.WhiteSpace.FunctionSpacing sniffSquiz.WhiteSpace.SuperfluousWhitespace now recognizes unicode whitespace at the start and end of a file
The Squiz.WhiteSpace.LanguageConstructSpacing sniff has been deprecated and will be removed in version 4.
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.
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.
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.
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.
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
@param tag group
@param group to contain other tagsThe new phpcs: comment syntax can now be prefixed with an at symbol ( @phpcs: )
phpcs: comment syntax can now be prefixed with an at symbol ( @phpcs: )
Tokens::$phpcsCommentTokens array is now available for sniff developers to detect phpcs: comment syntax
Generic.CodeAnalysis.EmptyStatement are no longer all-uppercase
Generic.CodeAnalysis.EmptyStatement.DetectedCATCH becomes Generic.CodeAnalysis.EmptyStatement.DetectedCatchPEAR.Commenting.FunctionComment.Missing error message now includes the name of the function
PEAR.Commenting.ClassComment.Missing and Squiz.Commenting.ClassComment.Missing error messages now include the name of the class
PEAR.Functions.FunctionCallSignature now only forces alignment at a specific tab stop while fixing
Generic.Files.LineLength now ignores lines that only contain phpcs: annotation comments
Generic.Formatting.MultipleStatementAlignment now skips over arrays containing comments
Generic.PHP.Syntax now forces display_errors to ON when linting
PSR2.Namespaces.UseDeclaration has improved syntax error handling and closure detection
Squiz.PHP.CommentedOutCode now has improved comment block detection for improved accuracy
Squiz.PHP.NonExecutableCode could fatal error while fixing file with syntax errorSquiz.PHP.NonExecutableCode now detects unreachable code after a goto statement
Squiz.WhiteSpace.LanguageConstructSpacing has improved syntax error handling while fixing
phpcs: annotation syntax handling for a number of sniffs
Disabled STDIN detection on Windows
Fixed problems with some scripts and plugins waiting for STDIN
Generic.Functions.OpeningFunctionBraceKernighanRitchie no longer complains when the open brace is followed by a close tag
This release deprecates the @codingStandards comment syntax used for sending commands to PHP_CodeSniffer. The existing syntax will continue to work in…
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:setThe 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_FILEphpcs:disable has the token T_PHPCS_DISABLEphpcs:enable has the token T_PHPCS_ENABLEphpcs:ignore has the token T_PHPCS_IGNOREphpcs:set has the token T_PHPCS_SETphpcs:disable and phpcs:ignore comments can now selectively ignore specific sniffs (request #604)
// phpcs:disable Generic.Commenting.Todo.Found for a specific message// phpcs:disable Generic.Commenting.Todo for a whole sniff// phpcs:disable Generic.Commenting for a whole category of sniffs// phpcs:disable Generic for a whole standard// phpcs:disable Generic.Commenting.Todo,PSR1.Files@codingStandardsIgnoreLine comments now only ignore the following line if they are on a line by themselves
PSR1.Files.SideEffects now respects the new phpcs:disable comment syntax
phpcs:disable and phpcs:enable commentsphpcs:ignore; you must wrap code structures with disable/enable commentsphpcs.xsd to allow validation of ruleset XML files
--stdin-path can now point to fake file locations (request #1488)
--basepath=) on the CLI will now clear a basepath set directly in a ruleset
AbstractVariableSniff abstract sniff now supports anonymous classes and nested functions
Squiz.Scope.MemberVarScope where member vars of anonymous classes were not being checkedAbstractArraySniff to make it easier to create sniffs that check array formatting
Generic.Arrays.ArrayIndent to enforce a single tab stop indent for array keys in multi-line arrays
indent property of the sniffGeneric.PHP.DiscourageGoto to warn about the use of the GOTO language construct
Generic.Debug.ClosureLinter was not running the gjslint command
Generic.WhiteSpace.DisallowSpaceIndent now fixes space indents in multi-line block comments
Generic.WhiteSpace.DisallowSpaceIndent now fixes mixed space/tab indents more accurately
Generic.WhiteSpace.DisallowTabIndent now fixes tab indents in multi-line block comments
PEAR.Functions.FunctionDeclaration no longer errors when a function declaration is the first content in a JS file
PEAR.Functions.FunctionCallSignature now requires the function name to be indented to an exact tab stop
PEAR.Functions.FunctionCallSignature.OpeningIndent for this errorSquiz.Functions.FunctionDeclarationArgumentSpacing is no longer confused about comments in function declarations
Squiz.PHP.NonExecutableCode error messages now indicate which line the code block ending is on
Squiz.Commenting.FunctionComment now supports nullable type hintsSquiz.Commenting.FunctionCommentThrowTag no longer assigns throw tags inside anon classes to the enclosing functionSquiz.WhiteSpace.SemicolonSpacing now ignores semicolons used for empty statements inside FOR conditions
Squiz.ControlStructures.ControlSignature now allows configuring the number of spaces before the colon in alternative syntax
requiredSpacesBeforeColon setting in a ruleset.xml file to change1Restored preference of non-dist files over dist files for phpcs.xml and phpcs.xml.dist
phpcs.xml and phpcs.xml.dist
.phpcs.xml, phpcs.xml, .phpcs.xml.dist, phpcs.xml.distSquiz.Commenting.InlineComment incorrectly identified comment blocks in some cases, muting some errors
This release includes a change to support newer versions of PHPUnit (versions 4, 5, and 6 are now supported)
phpunit --bootstrap=/path/to/phpcs/tests/bootstrap.phpphpcs.xml or phpcs.xml.dist file now takes precedence over the default_standard config setting
phpcs.xml and phpcs.xml.dist files can now be prefixed with a dot (request #1566)
.phpcs.xml, .phpcs.xml.dist, phpcs.xml, phpcs.xml.distOR logic instead of AND logic
--config-show, --config-set, and --config-delete now includes the path to the loaded config file/** are now always tokenized as docblocks
T_YIELD and T_YIELD_FROM tokens have been replicated for older PHP versions
Generic.CodeAnalysis.AssignmentInCondition sniff to warn about variable assignments inside conditions
Generic.Files.OneObjectStructurePerFile sniff to ensure there is a single class/interface/trait per file
Generic.Functions.FunctionCallArgumentSpacing, PEAR.Functions.FunctionCallSignature, and PSR2.Methods.FunctionCallSignatureGeneric.Files.LineLength can now be configured to ignore all comment lines, no matter their length
ignoreComments property to TRUE (default is FALSE) in your ruleset.xml file to enable thisGeneric.PHP.LowerCaseKeyword now checks self, parent, yield, yield from, and closure (function) keywords
PEAR.Functions.FunctionDeclaration now removes a blank line if it creates one by moving the curly brace during fixingSquiz.Commenting.FunctionCommentThrowTag now supports PHP 7.1 multi catch exceptionsSquiz.Formatting.OperatorBracket no longer throws errors for PHP 7.1 multi catch exceptionsSquiz.Commenting.LongConditionClosingComment now supports finally statementsSquiz.Formatting.OperatorBracket now correctly fixes pipe separated flagsSquiz.Formatting.OperatorBracket now correctly fixes statements containing short array syntaxSquiz.PHP.EmbeddedPhp now properly fixes cases where the only content in an embedded PHP block is a comment
Squiz.WhiteSpace.ControlStructureSpacing now ignores comments when checking blank lines at the top of control structuresSquiz.WhiteSpace.ObjectOperatorSpacing now detects and fixes spaces around double colons
Squiz.WhiteSpace.MemberVarSpacing can now be configured to check any number of blank lines between member vars
spacing property (default is 1) in your ruleset.xml file to set the spacingSquiz.WhiteSpace.MemberVarSpacing can now be configured to check a different number of blank lines before the first member var
spacingBeforeFirst property (default is 1) in your ruleset.xml file to set the spacingPHP_CodeSniffer\Util\Tokens::$ooScopeTokens static member var for quickly checking object scope
T_CLASS, T_ANON_CLASS, T_INTERFACE, and T_TRAITPHP_CodeSniffer\Files\File::findExtendedClassName() now supports extended interfaces
Fixed a problem where the source report was not printing the correct number of errors found
--cache=/path/to/cachefile CLI argument was not workingRunner::runPHPCS() or Runner::runPHPCBF() directly, you will get back the full range of exit codesDeepExitException to get the error message ($e->getMessage()) and exit code ($e->getCode())--suffix argument
// comment before PHP close tag
This release contains a fix for a security advisory related to the improper handling of a shell command
--filter=gitmodified command line option--stdin-path CLI option to --help--file-list and --bootstrap CLI options to --helpRunner::runPHPCS() and Runner::runPHPCBF() now return an exit code instead of exiting directly (request #1484)class_alias()\Sniffs\)MyProject\CS\Standard\Sniffs\Category set the namespace to MyProject\CS\Standard<ruleset name="My Coding Standard" namespace="MyProject\CS\Standard">$config->unknownThe intention is to limit 2.9.x releases to serious bug and security fixes only.
This is the first stable release of the 3.0 branch, and is a large refactoring of the code base. It breaks backwards compatibility for all custom sniffs and custom reports. An upgrade guide for sniff and report developers is available here: https://github.com/PHPCSStandards/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 the 3.0.0 version.
There are no future planned releases for the 2.x branch, but there may still be additional 2.9.x versions released for a time due to the number of changes required to upgrade custom sniffs for 3.0. The intention is to limit 2.9.x releases to serious bug and security fixes only.
@codingStandards annotations in code comments (request #811)
For a full list of changes from the 2.x version, please review the following changelogs: https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.0.0a1 https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.0.0RC1 https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.0.0RC2 https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.0.0RC3 https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.0.0RC4
PHPCS should now run under PHP 7.3 without deprecation warnings
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/PHPCSStandards/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.
Fixed bug #1442 : T_NULLABLE detection not working for nullable parameters and return type hints in some cases
One column per quarter.