Releases: PHPCSStandards/PHP_CodeSniffer
3.9.0 - 2024-02-16
Added
- Tokenizer support for PHP 8.3 typed class constants. #321
- Additionally, the following sniffs have been updated to support typed class constants:
- Thanks to Juliette Reinders Folmer for the patches
- Tokenizer support for PHP 8.3 readonly anonymous classes. #309
- Additionally, the following sniffs have been updated to support readonly anonymous classes:
- PSR12.Classes.ClassInstantiation #324
- Thanks to Juliette Reinders Folmer for the patches
- Additionally, the following sniffs have been updated to support readonly anonymous classes:
- New
PHP_CodeSniffer\Sniffs\DeprecatedSniff
interface to allow for marking a sniff as deprecated. #281- If a ruleset uses deprecated sniffs, deprecation notices will be shown to the end-user before the scan starts.
When running in-q
(quiet) mode, the deprecation notices will be hidden. - Deprecated sniffs will still run and using them will have no impact on the exit code for a scan.
- In ruleset "explain"-mode (
-e
) an asterix*
will show next to deprecated sniffs. - Sniff maintainers are advised to read through the PR description for full details on how to use this feature for their own (deprecated) sniffs.
- Thanks to Juliette Reinders Folmer for the patch
- If a ruleset uses deprecated sniffs, deprecation notices will be shown to the end-user before the scan starts.
- New
Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence
sniff. #197- Forbid mixing different binary boolean operators within a single expression without making precedence clear using parentheses
- Thanks to Tim Düsterhus for the contribution
- Squiz.PHP.EmbeddedPhp : the sniff will now also examine the formatting of embedded PHP statements using short open echo tags. #27
- Includes a new
ShortOpenEchoNoSemicolon
errorcode to allow for selectively ignoring missing semicolons in single line embedded PHP snippets within short open echo tags. - The other error codes are the same and do not distinguish between what type of open tag was used.
- Thanks to Juliette Reinders Folmer for the patch
- Includes a new
- Documentation for the following sniffs:
- Generic.WhiteSpace.IncrementDecrementSpacing
- PSR12.ControlStructures.ControlStructureSpacing
- PSR12.Files.ImportStatement
- PSR12.Functions.ReturnTypeDeclaration
- PSR12.Properties.ConstantVisibility
- Thanks to Denis Žoljom and Rodrigo Primo for the patches
Changed
- The Performance report can now also be used for a
phpcbf
run. #308- Thanks to Juliette Reinders Folmer for the patch
- Sniff tests which extend the PHPCS native
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- The warning is only displayed on PHPUnit 7.3.0 and higher.
- The warning will be elevated to a test failure in PHPCS 4.0.
- Thanks to Dan Wallis for the patch
- The following sniffs have received performance related improvements:
- Squiz.PHP.EmbeddedPhp
- Thanks to Juliette Reinders Folmer for the patch
- Various housekeeping, including improvements to the tests and documentation
- Thanks to Dan Wallis, Joachim Noreiko, Remi Collet, Rodrigo Primo and Juliette Reinders Folmer for their contributions
Deprecated
- Support for scanning JavaScript and CSS files. See #2448.
- This also means that all sniffs which are only aimed at JavaScript or CSS files are now deprecated.
- The Javascript and CSS Tokenizers, all Javascript and CSS specific sniffs, and support for JS and CSS in select sniffs which support multiple file types, will be removed in version 4.0.0.
- The abstract
PHP_CodeSniffer\Filters\ExactMatch::getBlacklist()
andPHP_CodeSniffer\Filters\ExactMatch::getWhitelist()
methods are deprecated and will be removed in the 4.0 release. See #198.- In version 4.0, these methods will be replaced with abstract
ExactMatch::getDisallowedFiles()
andExactMatch::getAllowedFiles()
methods - To make Filters extending
ExactMatch
cross-version compatible with both PHP_CodeSniffer 3.9.0+ as well as 4.0+, implement the newgetDisallowedFiles()
andgetAllowedFiles()
methods.- When both the
getDisallowedFiles()
andgetAllowedFiles()
methods as well as thegetBlacklist()
andgetWhitelist()
are available, the new methods will take precedence over the old methods.
- When both the
- Thanks to Juliette Reinders Folmer for the patch
- In version 4.0, these methods will be replaced with abstract
- The MySource standard and all sniffs in it. See #2471.
- The MySource standard and all sniffs in it will be removed in version 4.0.0.
- The
Zend.Debug.CodeAnalyzer
sniff. See #277.- This sniff will be removed in version 4.0.0.
- Thanks to Juliette Reinders Folmer for the patch
Fixed
- Fixed bug #127 : Squiz.Commenting.FunctionComment : The
MissingParamType
error code will now be used instead ofMissingParamName
when a parameter name is provided, but not its type. Additionally, invalid type hint suggestions will no longer be provided in these cases.- Thanks to Dan Wallis for the patch
- Fixed bug #196 : Squiz.PHP.EmbeddedPhp : fixer will no longer leave behind trailing whitespace when moving code to another line.
- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #196 : Squiz.PHP.EmbeddedPhp : will now determine the needed indent with higher precision in multiple situations.
- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #196 : Squiz.PHP.EmbeddedPhp : fixer will no longer insert a stray new line when the closer of a multi-line embedded PHP block and the opener of the next multi-line embedded PHP block would be on the same line.
- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #235 : Generic.CodeAnalysis.ForLoopWithTestFunctionCall : prevent a potential PHP 8.3 deprecation notice during live coding
- Thanks to Rodrigo Primo for the patch
- Fixed bug #288 : Generic.WhiteSpace.IncrementDecrementSpacing : error message for post-in/decrement will now correctly inform about new lines found before the operator.
- Thanks to Rodrigo Primo for the patch
- Fixed bug #296 : Generic.WhiteSpace.ArbitraryParenthesesSpacing : false positive for non-arbitrary parentheses when these follow the scope closer of a
switch
case
.- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #307 : PSR2.Classes.ClassDeclaration : space between a modifier keyword and the
class
keyword was not checked when the space included a new line or comment.- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #325 : Squiz.Operators.IncrementDecrementUsage : the sniff was underreporting when there was (no) whitespace and/or comments in unexpected places.
- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #335 : PSR12.Files.DeclareStatement : bow out in a certain parse error situation to prevent incorrect auto-fixes from being made.
- Thanks to Dan Wallis for the patch
- Fixed bug #340 : Squiz.Commenting.ClosingDeclarationComment : no longer adds a stray newline when adding a missing comment.
- Thanks to Dan Wallis for the patch
Other
- A "Community cc list" has been introduced to ping maintainers of external standards and integrators for input regarding change proposals for PHP_CodeSniffer which may impact them. #227
- For anyone who missed the discussion about this and is interested to be on this list, please feel invited to submit a PR to add yourself.
The list is located in the.github
folder.
- For anyone who missed the discussion about this and is interested to be on this list, please feel invited to submit a PR to add yourself.
New Contributors
The PHP_CodeSniffer project is happy to welcome the following new contributors:
@joachim-n, @remicollet, @TimWolla
Statistics
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!
3.8.1 - 2024-01-11
Added
- Documentation has been added for the following sniffs:
- Generic.CodeAnalysis.EmptyPHPStatement
- Generic.Formatting.SpaceBeforeCast
- Generic.PHP.Syntax
- Generic.WhiteSpace.LanguageConstructSpacing
- PSR12.Classes.ClosingBrace
- PSR12.Classes.OpeningBraceSpace
- PSR12.ControlStructures.BooleanOperatorPlacement
- PSR12.Files.OpenTag
- Thanks to Rodrigo Primo and Denis Žoljom for the patches
Changed
- GitHub releases will now always only contain unversioned versions of the release assets (PHARS + asc files). See #205 for context.
- Thanks to Shivam Mathur for opening a discussion about this
- Various housekeeping, includes improvements to the tests and documentation
- Thanks to Dan Wallis, Lucas Hoffmann, Rodrigo Primo and Juliette Reinders Folmer for their contributions
Fixed
- Fixed bug #124 : Report Full : avoid unnecessarily wrapping lines when
-s
is used- Thanks to Brad Jorsch for the patch
- Fixed bug #124 : Report Full : fix incorrect bolding of pipes when
-s
is used and messages wraps- Thanks to Brad Jorsch for the patch
- Fixed bug #150 : Squiz.WhiteSpace.KeywordSpacing : prevent a PHP notice when run during live coding
- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #154 : Report Full : delimiter line calculation could go wonky on wide screens when a report contains multi-line messages
- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #178 : Squiz.Commenting.VariableComment : docblocks were incorrectly being flagged as missing when a property declaration used PHP native union/intersection type declarations
- Thanks to Ferdinand Kuhl for the patch
- Fixed bug #211 : Squiz.Commenting.VariableComment : docblocks were incorrectly being flagged as missing when a property declaration used PHP 8.2+ stand-alone
true
/false
/null
type declarations- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #211 : Squiz.Commenting.VariableComment : docblocks were incorrectly being flagged as missing when a property declaration used PHP native
parent
,self
or a namespace relative class name type declaration- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #226 : Generic.CodeAnalysis.ForLoopShouldBeWhileLoop : prevent a potential PHP 8.3 deprecation notice during live coding
- Thanks to Rodrigo Primo for the patch
New Contributors
The PHP_CodeSniffer project is happy to welcome the following new contributors:
@anomiex, @dingo-d, @fcool, @lucc, @rodrigoprimo
Statistics
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!
3.8.0 - 2023-12-08
Squizlabs/PHP_CodeSniffer is dead. Long live PHPCSStandards/PHP_CodeSniffer!
Breaking Changes
- The
squizlabs/PHP_CodeSniffer
repository has been abandoned. ThePHPCSStandards/PHP_CodeSniffer
repository will serve as the continuation of the project. For more information about this change, please read the announcement.- Installation of PHP_CodeSniffer via PEAR is no longer supported.
- Users will need to switch to another installation method.
- Note: this does not affect the PEAR sniffs.
- For Composer users, nothing changes.
- In contrast to earlier information, the
squizlabs/php_codesniffer
package now points to the new repository and everything will continue to work as before.
- In contrast to earlier information, the
- PHIVE users may need to clear the PHIVE URL cache.
- PHIVE users who don't use the package alias, but refer to the package URL, will need to update the URL from
https://squizlabs.github.io/PHP_CodeSniffer/phars/
tohttps://phars.phpcodesniffer.com/phars/
.
- PHIVE users who don't use the package alias, but refer to the package URL, will need to update the URL from
- Users who download the PHAR files using curl or wget, will need to update the download URL from
https://squizlabs.github.io/PHP_CodeSniffer/[phpcs|phpcbf].phar
orhttps://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/[phpcs|phpcbf].phar
tohttps://phars.phpcodesniffer.com/[phpcs|phpcbf].phar
. - For users who install PHP_CodeSniffer via the setup-php action runner for GitHub Actions, nothing changes.
- Users using a git clone will need to update the clone address from
[email protected]:squizlabs/PHP_CodeSniffer.git
to[email protected]:PHPCSStandards/PHP_CodeSniffer.git
.- Contributors will need to fork the new repo and add both the new fork as well as the new repo as remotes to their local git copy of PHP_CodeSniffer.
- Users who have (valid) open issues or pull requests in the
squizlabs/PHP_CodeSniffer
repository are invited to resubmit these to thePHPCSStandards/PHP_CodeSniffer
repository.
- Installation of PHP_CodeSniffer via PEAR is no longer supported.
Added
- Runtime support for PHP 8.3. All known PHP 8.3 deprecation notices have been fixed
- Syntax support for new PHP 8.3 features will follow in a future release
- If you find any PHP 8.3 deprecation notices which were missed, please report them
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patches
- Added support for PHP 8.2 readonly classes to File::getClassProperties() through a new is_readonly array index in the return value
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Added support for PHP 8.2 readonly classes to a number of sniffs
- Generic.CodeAnalysis.UnnecessaryFinalModifier
- PEAR.Commenting.ClassComment
- PEAR.Commenting.FileComment
- PSR1.Files.SideEffects
- PSR2.Classes.ClassDeclaration
- PSR12.Files.FileHeader
- Squiz.Classes.ClassDeclaration
- Squiz.Classes.LowercaseClassKeywords
- Squiz.Commenting.ClassComment
- Squiz.Commenting.DocCommentAlignment
- Squiz.Commenting.FileComment
- Squiz.Commenting.InlineComment
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Added support for PHP 8.2
true
as a stand-alone type declaration- The
File::getMethodProperties()
,File::getMethodParameters()
andFile::getMemberProperties()
methods now all support thetrue
type - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- The
- Added support for PHP 8.2
true
as a stand-alone type to a number of sniffs- Generic.PHP.LowerCaseType
- PSr12.Functions.NullableTypeDeclaration
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Added a Performance report to allow for finding "slow" sniffs
- To run this report, run PHPCS with --report=Performance.
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Generic.PHP.RequireStrictTypes : new warning for when there is a declare statement, but the strict_types directive is set to 0
- The warning can be turned off by excluding the
Generic.PHP.RequireStrictTypes.Disabled
error code - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- The warning can be turned off by excluding the
- Squiz.Commenting.FunctionComment : new
ParamNameUnexpectedAmpersandPrefix
error for parameters annotated as passed by reference while the parameter is not passed by reference- Thanks to Dan Wallis (@fredden) for the patch
- Documentation has been added for the following sniffs:
- PSR2.Files.ClosingTag
- PSR2.Methods.FunctionCallSignature
- PSR2.Methods.FunctionClosingBrace
- Thanks to Atsushi Okui (@blue32a) for the patch
- Support for PHPUnit 8 and 9 to the test suite
- Test suites for external standards which run via the PHPCS native test suite can now run on PHPUnit 4-9 (was 4-7)
- If any of these tests use the PHPUnit
setUp()
/tearDown()
methods or overload thesetUp()
in theAbstractSniffUnitTest
test case, they will need to be adjusted. See the PR details for further information - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
Changed
- Changes have been made to the way PHPCS handles invalid sniff properties being set in a custom ruleset
- Fixes PHP 8.2 deprecation notices for properties set in a (custom) ruleset for complete standards/complete sniff categories
- Invalid sniff properties set for individual sniffs will now result in an error and halt the execution of PHPCS
- A descriptive error message is provided to allow users to fix their ruleset
- Sniff properties set for complete standards/complete sniff categories will now only be set on sniffs which explicitly support the property
- The property will be silently ignored for those sniffs which do not support the property
- Invalid sniff properties set for sniffs via inline annotations will result in an informative
Internal.PropertyDoesNotExist
errror on line 1 of the scanned file, but will not halt the execution of PHPCS - For sniff developers, it is strongly recommended for sniffs to explicitly declare any user-adjustable public properties
- If dynamic properties need to be supported for a sniff, either declare the magic __set()/__get()/__isset()/__unset() methods on the sniff or let the sniff extend stdClass
- Note: The #[\AllowDynamicProperties] attribute will have no effect for properties which are being set in rulesets
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- The third parameter for the Ruleset::setSniffProperty() method has been changed to expect an array
- Sniff developers/integrators of PHPCS may need to make some small adjustments to allow for this change
- Existing code will continue to work but will throw a deprecation error
- The backwards compatiblity layer will be removed in PHPCS 4.0
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- When using
auto
report width (the default) a value of 80 columns will be used if the width cannot be determined- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Sniff error messages are now more informative to help bugs get reported to the correct project
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Generic.CodeAnalysis.UnusedFunctionParameter will now ignore magic methods for which the signature is defined by PHP
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Generic.Functions.OpeningFunctionBraceBsdAllman will now check the brace indent before the opening brace for empty functions
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Generic.Functions.OpeningFunctionBraceKernighanRitchie will now check the spacing before the opening brace for empty functions
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Generic.WhiteSpace.IncrementDecrementSpacing now detects more spacing issues
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- PSR2.Classes.PropertyDeclaration now enforces that the readonly modifier comes after the visibility modifier
- PSR2 and PSR12 do not have documented rules for this as they pre-date the readonly modifier
- PSR-PER has been used to confirm the order of this keyword so it can be applied to PSR2 and PSR12 correctly
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- PEAR.Commenting.FunctionComment + Squiz.Commenting.FunctionComment: the SpacingAfter error can now be auto-fixed
- Thanks to Dan Wallis (@fredden) for the patch
- Squiz.PHP.InnerFunctions sniff no longer reports on OO methods for OO structures declared within a function or closure
- Thanks to @Daimona for the patch
- Squiz.PHP.NonExecutableCode will now also flag redundant return statements just before a closure close brace
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Runtime performance improvement for PHPCS CLI users. The improvement should be most noticeable for users on Windows.
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- The following sniffs have received performance related improvements:
- Generic.PHP.LowerCaseConstant
- Generic.PHP.LowerCaseType
- PSR12.Files.OpenTag
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patches
- The -e (explain) command will now list sniffs in natural order
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Tests using the PHPCS native test framework with multiple test case files will now run the test case files in numeric order.
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- The following sniffs have received minor message readability improvements:
- Generic.Arrays.ArrayIndent
...
- Generic.Arrays.ArrayIndent
3.7.2 - 2023-02-23
- Newer versions of Composer will now suggest installing PHPCS using require-dev instead of require
- Thanks to Gary Jones (@GaryJones) for the patch
- A custom Out Of Memory error will now be shown if PHPCS or PHPCBF run out of memory during a run
- Error message provides actionable information about how to fix the problem and ensures the error is not silent
- Thanks to Juliette Reinders Folmer (@jrfnl) and Alain Schlesser (@schlessera) for the patch
- Generic.PHP.LowerCaseType sniff now correctly examines types inside arrow functions
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Squiz.Formatting.OperatorBracket no longer reports false positives in match() structures
- Fixed bug #3616 : Squiz.PHP.DisallowComparisonAssignment false positive for PHP 8 match expression
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3618 : Generic.WhiteSpace.ArbitraryParenthesesSpacing false positive for return new parent()
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3632 : Short list not tokenized correctly in control structures without braces
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3639 : Tokenizer not applying tab replacement to heredoc/nowdoc closers
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3640 : Generic.WhiteSpace.DisallowTabIndent not reporting errors for PHP 7.3 flexible heredoc/nowdoc syntax
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3645 : PHPCS can show 0 exit code when running in parallel even if child process has fatal error
- Thanks to Alex Panshin (@enl) for the patch
- Fixed bug #3653 : False positives for match() in OperatorSpacingSniff
- Thanks to Jaroslav Hanslík (@kukulich) for the patch
- Fixed bug #3666 : PEAR.Functions.FunctionCallSignature incorrect indent fix when checking mixed HTML/PHP files
- Fixed bug #3668 : PSR12.Classes.ClassInstantiation.MissingParentheses false positive when instantiating parent classes
- Similar issues also fixed in Generic.Functions.FunctionCallArgumentSpacing and Squiz.Formatting.OperatorBracket
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3672 : Incorrect ScopeIndent.IncorrectExact report for match inside array literal
- Fixed bug #3694 : Generic.WhiteSpace.SpreadOperatorSpacingAfter does not ignore spread operator in PHP 8.1 first class callables
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
3.7.1 - 2022-06-18
3.7.0 - 2022-06-13
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
- 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
- Includes a new
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
- When constructor property promotion is used, a new
- 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
andGeneric.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
- These sniffs now only report errors for
Generic.PHP.LowerCaseType
now supports the PHP 8.1never
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
3.6.2 - 2021-12-12
- 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
- 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
- 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
3.6.1 - 2021-10-11
- 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 following sniffs were affected:
- 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
andT_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
- The PHP 8.1 tokens
File::getMethodParameters()
no longer incorrectly returns argument attributes in the type hint array index- A new
has_attributes
array index is available and set toTRUE
if the argument has attributes defined - Thanks to Juliette Reinders Folmer for the patch
- A new
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
3.6.0 - 2021-04-09
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()
, andgetMemberProperties()
will now return union types- Thanks to Juliette Reinders Folmer for the patch
- A new
- 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
- A new
- 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
andattribute_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
- The PHP-supplied
- 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
- Sniffs can listen for the
- 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
- Match expressions are now tokenised with parenthesis and scope openers and closers
- 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
- This will have no impact on custom sniffs unless they are specifically looking at the value of the
File::findStartOfStatement()
now works correctly when passed the last token in a statementFile::getMethodParameters()
now supports PHP 8.0 constructor property promotion- Returned method params now include a
property_visibility
andvisibility_token
index if property promotion is detected - Thanks to Juliette Reinders Folmer for the patch
- Returned method params now include a
File::getMethodProperties()
now includes areturn_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
- Previously, checks using include patterns were excluded when processing STDIN when no file path was provided via
- 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 tofalse
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
andSquiz.Commenting.FunctionComment
sniffs can now ignore private and protected methods- Set the
minimumVisibility
sniff property toprotected
to ignore private methods - Set the
minimumVisibility
sniff property topublic
to ignore both private and protected methods - The default remains at
private
, so all methods are checked - Thanks to Vincent Langlet for the patch
- Set the
PEAR.Commenting.FunctionComment
andSquiz.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
- Previously, only
PSR2.ControlStructures.SwitchDeclaration
now supports nested switch statements where every branch terminates- Previously, if a
CASE
only contained aSWITCH
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
- Previously, if a
- 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 totrue
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
- Set the
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
- This works around a long-standing PHP bug with
- 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 [#299...
3.5.8 - 2020-10-23
- Reverted a change to the way include/exclude patterns are processed for STDIN content
- This change is not backwards compatible and will be re-introduced in version 3.6.0