phpcsstandards/phpcsutils
A suite of utility functions for use with PHP_CodeSniffer
1.2.3
45M downloads/mo
#403 most downloaded on Packagist
PHPCSStandards/PHPCSUtils
What this package is like to depend on
Last release 27 days ago
27 Jul 2026
Release timing varies
gaps range from 4 weeks to 13 months
Nearly every release is documented
notes for 21 of 21 stable releases
Nothing withdrawn
no release was ever pulled
7 years old
26 releases · first in 2020
6 releases in the last 12 months
see the full history below
Release timeline
26 releases · Jan 2020 to Jul 2026Releases
latest 26-
1.2.327 Jul 2026Release notes
Open source →This is a security release and all users are advised to update their install(s) as soon as possible.
Changed
Other
- Various housekeeping.
Fixed
Abstract Sniffs
- SECURITY FIX: Running a sniff which uses the
AbstractArrayDeclarationSniff::getActualArrayKey()method over untrusted PHP code, for example, in a CI pipeline that lints pull requests, or on a developer machine reviewing third-party code, could lead to arbitrary command execution on the scanning host. #774
For more details, see the security advisory.
Thanks go to @rodrigoprimo for responsibly disclosing the vulnerability. - The
AbstractArrayDeclarationSniff::getActualArrayKey()method now handles exceptions seen when evaluating array keys more gracefully. #775
Utils
- The
Arrays::getDoubleArrowPtr()method did not recognize that, while rare, an array key can contain a (nested) array. #771
Release notes
Open source →This is a security release and all users are advised to update their install(s) as soon as possible.
Changed
Other
- Various housekeeping.
Fixed
Abstract Sniffs
- SECURITY FIX: Running a sniff which uses the
AbstractArrayDeclarationSniff::getActualArrayKey()method over untrusted PHP code, for example, in a CI pipeline that lints pull requests, or on a developer machine reviewing third-party code, could lead to arbitrary command execution on the scanning host. #774 For more details, see the security advisory. Thanks go to [@rodrigoprimo] for responsibly disclosing the vulnerability. - The
AbstractArrayDeclarationSniff::getActualArrayKey()method now handles exceptions seen when evaluating array keys more gracefully. #775
Utils
- The
Arrays::getDoubleArrowPtr()method did not recognize that, while rare, an array key can contain a (nested) array. #771
-
1.2.208 Dec 2025Release notes
Open source →Added
PHPCS Backcompat
BCTokens::castTokens(): sync with PHPCS 4.0.2 - added theT_VOID_CASTtoken (when available). #742
Changed
Utils
FunctionDeclarations::getProperties(): more defensive coding against parse errors/live coding. #740
Other
- Various housekeeping.
Release notes
Open source →Added
PHPCS Backcompat
BCTokens::castTokens(): sync with PHPCS 4.0.2 - added theT_VOID_CASTtoken (when available). #742
Changed
Utils
FunctionDeclarations::getProperties(): more defensive coding against parse errors/live coding. #740
Other
- Various housekeeping.
-
1.2.117 Nov 2025Release notes
Open source →Fixed
Abstract Sniffs
- The
AbstractArrayDeclarationSniff::getActualArrayKey()method could cause deprecation notices and even fatal errors, when a PHPCS scan would be run on a different PHP version than the "code under scan" is targeting and the "code under scan" contained deprecated/removed type casts. #733
Release notes
Open source →Fixed
Abstract Sniffs
- The
AbstractArrayDeclarationSniff::getActualArrayKey()method could cause deprecation notices and even fatal errors, when a PHPCS scan would be run on a different PHP version than the "code under scan" is targeting and the "code under scan" contained deprecated/removed type casts. #733
- The
-
1.2.011 Nov 2025Release notes
Open source →Added
Utils
- New
PHPCSUtils\Utils\AttributeBlockclass: Utility functions to examine attribute blocks. #720, #729
For the purposes of these utilities, an "attribute block" is defined as being an attribute opener, an attribute closer and everything between. I.e.#[MyAttribute(1, 2), AnotherAttribute]is one attribute block.
Initial set of available methods:getAttributes()to retrieve information about each attribute being instantiated within a particular attribute block.countAttributes()to retrieve a count of the number of attribute instantiations with a particular attribute block.appliesTo()to find the stack pointer to the language construct an attribute block applies to.
- New
PHPCSUtils\Utils\Constants::getAttributeOpeners(),PHPCSUtils\Utils\FunctionDeclarations::getAttributeOpeners(),PHPCSUtils\Utils\ObjectDeclarations::getAttributeOpeners()andPHPCSUtils\Utils\Variables::getAttributeOpeners()utility methods. #719
These methods will each return an array with the stack pointers to the attribute openers for applicable attribute blocks.
This may be an empty array if no attributes apply to the constant/function/OO structure/property.
Changed
Other
- Dropped support for PHP_CodeSniffer < 3.13.5/4.0.1. #729
Please ensure you runcomposer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Various housekeeping.
Release notes
Open source →Added
Utils
- New [
PHPCSUtils\Utils\AttributeBlock][AttributeBlock] class: Utility functions to examine attribute blocks. #720, #729 For the purposes of these utilities, an "attribute block" is defined as being an attribute opener, an attribute closer and everything between. I.e.#[MyAttribute(1, 2), AnotherAttribute]is one attribute block. Initial set of available methods:getAttributes()to retrieve information about each attribute being instantiated within a particular attribute block.countAttributes()to retrieve a count of the number of attribute instantiations with a particular attribute block.appliesTo()to find the stack pointer to the language construct an attribute block applies to.
- New
PHPCSUtils\Utils\Constants::getAttributeOpeners(),PHPCSUtils\Utils\FunctionDeclarations::getAttributeOpeners(),PHPCSUtils\Utils\ObjectDeclarations::getAttributeOpeners()andPHPCSUtils\Utils\Variables::getAttributeOpeners()utility methods. #719 These methods will each return an array with the stack pointers to the attribute openers for applicable attribute blocks. This may be an empty array if no attributes apply to the constant/function/OO structure/property.
Changed
Other
- Dropped support for [PHP_CodeSniffer] < 3.13.5/4.0.1. #729
Please ensure you run
composer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Various housekeeping.
- New
-
1.1.316 Oct 2025Release notes
Open source →Changed
Other
- Various housekeeping.
Fixed
PHPCS Backcompat
BCFile::getMemberProperties(): sync with PHPCS 3.13.4 - fix PHP 8.5 "Using null as an array offset" deprecation notice. #711
Release notes
Open source →Changed
Other
- Various housekeeping.
Fixed
PHPCS Backcompat
BCFile::getMemberProperties(): sync with PHPCS 3.13.4 - fix PHP 8.5 "Using null as an array offset" deprecation notice. #711
-
1.1.205 Sep 2025Release notes
Open source →Added
PHPCS BackCompat
BCFile::getMemberProperties(): sync with PHPCS 3.13.3 - support for PHP 8.4 abstract properties. #698
Utils
Variables::getMemberProperties(): support for PHP 8.4 abstract properties. #698
Changed
Utils
TypeString::normalizeCase()will now also normalize a fully qualifiedtrue,falseornulltype to unqualified. #702
Other
- Dropped support for PHP_CodeSniffer < 3.13.3. #698
Please ensure you runcomposer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Various housekeeping.
Fixed
Utils
TypeString::isNullable(): a type string with a fully qualifiednullwas not recognized as nullable. #702TypeString::isKeyword(): a fully qualifiedtrue,falseornulltype was not recognized as a keyword type. #702
Note: using fully qualified
true,falseornullin a typestring is not allowed by PHP. Even so, theTypeStringutility will now handle this in a parse error tolerant manner.Release notes
Open source →Added
PHPCS BackCompat
BCFile::getMemberProperties(): sync with PHPCS 3.13.3 - support for PHP 8.4 abstract properties. #698
Utils
Variables::getMemberProperties(): support for PHP 8.4 abstract properties. #698
Changed
Utils
TypeString::normalizeCase()will now also normalize a fully qualifiedtrue,falseornulltype to unqualified. #702
Other
- Dropped support for [PHP_CodeSniffer] < 3.13.3. #698
Please ensure you run
composer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Various housekeeping.
Fixed
Utils
TypeString::isNullable(): a type string with a fully qualifiednullwas not recognized as nullable. #702TypeString::isKeyword(): a fully qualifiedtrue,falseornulltype was not recognized as a keyword type. #702
Note: using fully qualified
true,falseornullin a typestring is not allowed by PHP. Even so, theTypeStringutility will now handle this in a parse error tolerant manner. -
1.1.110 Aug 2025Release notes
Open source →Changed
TestUtils
- The
PHPCSUtils\TestUtils\UtilityMethodTestCasenow uses the PHP_CodeSnifferLocalFileinstead of theDummyFileclass under the hood. #692
Fixed
TestUtils
- Prevent PHP 8.5 deprecation notices for
Reflection*::setAccessible()in thePHPCSUtils\TestUtils\UtilityMethodTestCaseand thePHPCSUtils\TestUtils\ConfigDoubleclasses. #695
Release notes
Open source →Changed
TestUtils
- The [
PHPCSUtils\TestUtils\UtilityMethodTestCase][UtilityMethodTestCase] now uses the PHP_CodeSnifferLocalFileinstead of theDummyFileclass under the hood. #692
Fixed
TestUtils
- Prevent PHP 8.5 deprecation notices for
Reflection*::setAccessible()in the [PHPCSUtils\TestUtils\UtilityMethodTestCase][UtilityMethodTestCase] and the [PHPCSUtils\TestUtils\ConfigDouble][ConfigDouble] classes. #695
- The
-
1.1.012 Jun 2025Release notes
Open source →Added
Compatibility with the new PHP_CodeSniffer
4.xbranch in anticipation of the PHP_CodeSniffer 4.0 release. #674, #679
PHPCSUtils should now be fully compatible with PHP_CodeSniffer 4.0 (again). If you still find an issue, please report it.PHPCS BackCompat
BCFile::findExtendedClassName(): sync with PHPCS 4.0.0 - support for namespace relative names when used as the extended parent class name. #674BCFile::findImplementedInterfaceNames(): sync with PHPCS 4.0.0 - support for namespace relative names when used in implemented interface names. #674BCFile::getMemberProperties(): sync with PHPCS 3.12.0 - support for PHP 8.4 final properties. Thanks @DanielEScherzer! #646BCFile::getMemberProperties(): sync with PHPCS 3.13.1 - support for PHP 8.4 asymmetric visibility. #677BCFile::getMemberProperties(): sync with PHPCS 4.0.0. #674- Add support for PHP 8.4 properties in interfaces.
- Removed parse error warning.
BCFile::getMethodParameters(): sync with PHPCS 3.13.1 - support for PHP 8.4 asymmetric visibility. #677BCFile::findStartOfStatement(): sync with PHPCS 3.12.1 - support forgotoas aswitch-caseterminating statement. #661BCTokens::nameTokens()as introduced in PHPCS 4.0.0. #674
The same token array previously already existed in PHPCSUtils asCollections::nameTokens().BCTokens::functionNameTokens(): sync with PHPCS 4.0.0 - added theT_ANON_CLASStoken. #674BCTokens::parenthesisOpeners(): sync with PHPCS 4.0.0 - added theT_USE,T_ISSET,T_UNSET,T_EMPTY,T_EVALandT_EXITtokens. #674
Note: WhileT_USE,T_ISSET,T_UNSET,T_EMPTY,T_EVALandT_EXITwill be included in the return value for this method,
the associated parentheses will not have the'parenthesis_owner'index set unless PHPCS 4.0.0 is used.
Use theParentheses::getOwner()or theParentheses::hasOwner()methods if you need to check
whether any of these tokens are a parentheses owner. The methods in theParenthesesclass are PHPCS cross-version compatible.
TestUtils
- New
PHPCSUtils\TestUtils\ConfigDoubleclass as a lightweight and more stable alternative to directly using the PHPCS nativeConfigclass in tests. #550, #612
Props to @fredden for helping me find and fix a bug in this feature before it was released. - New
PHPCSUtils\TestUtils\RulesetDoubleclass which allows for creating aRulesetobject without registering any sniffs. #674
This allows for thePHPCSUtils\TestUtils\UtilityMethodTestCaseclass to be cross-version compatible with both PHP_CodeSniffer 3.x as well as 4.x. - New
PHPCSUtils\TestUtils\UtilityMethodTestCase::parseFile()method to allow for on-demand tokenizing of a (secondary) test case file. #591, #610
This method is intended for tests which need to use multiple test case files, like, for example, tests which need to verify that a utility resets a$fileNameproperty on seeing another file. - New
PHPCSUtils\TestUtils\UtilityMethodTestCase::testTestMarkersAreUnique()andPHPCSUtils\TestUtils\UtilityMethodTestCase::assertTestMarkersAreUnique()methods which automatically check that code sample files used with thisTestCasedo not contain duplicate test case markers. #642
If needs be, the test method can be disabled by overloading it (discouraged). If a test uses multiple test case/code sample files, the assertion method can be called directly.
Tokens
- New
Collections::constantTypeTokens()method to support PHP 8.3 typed class constants. #562 - New
Collections::ternaryOperators()method. #549 T_EXITto theCollections::functionCallTokens()andCollections::parameterPassingTokens()in light of the PHP 8.4 "exit as function" change. #618- The PHP 8.4 asymmetric visibility tokens have been added to the
Collections::propertyModifierKeywords()method. #653 T_INTERFACEhas been added to theCollections::ooPropertyScopes()method for PHP 8.4 interface properties support. #674
Utils
- New
PHPCSUtils\Utils\Constantsclass: Utility functions to examine (class) constants. #562
Initially available method:getProperties()to retrieve an array of information about an OO constant declaration. - New
PHPCSUtils\Utils\FileInfoclass: Utility functions to check characteristics of the file under scan. #572
Initial set of available methods:hasByteOrderMark()andhasSheBang(). - New
PHPCSUtils\Utils\FilePathclass: Utility functions for handling and comparing file paths. #593
Initial set of available methods:getName()to retrieve the normalized path for the current file,isStdin(),normalizeAbsolutePath(),normalizeDirectorySeparators(),trailingSlashIt()andstartsWith(). - New
PHPCSUtils\Utils\TypeStringclass: Utility functions for analysing typestrings as retrieved via the various availablegetParameters()/getProperties()methods. #588
Initial set of available methods:getKeywordTypes(),isKeyword(),normalizeCase(),isSingular(),isNullable(),isUnion(),isIntersection(),isDNF(),toArray(),toArrayUnique(),filterKeywordTypes()andfilterOOTypes().
Note: Theis*()methods will not check if the type string provided is valid, as doing so would inhibit what sniffs can flag. Theis*()methods will only look at the form of the type string to determine if it could be valid for a certain type. - New
PHPCSUtils\Utils\ObjectDeclarations::getDeclaredConstants(),PHPCSUtils\Utils\ObjectDeclarations::getDeclaredEnumCases(),PHPCSUtils\Utils\ObjectDeclarations::getDeclaredProperties()andPHPCSUtils\Utils\ObjectDeclarations::getDeclaredMethods()utility methods. #592
These methods will each return an array with the name of the constant/case/property/method as the key and the typical stack pointer needed for further processing.
The retrieval of this information is highly optimized for performance. If a sniff needs to search for a named constant/enum case/property/method in an OO structure, in most cases, these methods should be the recommended way for finding the declaration, instead of the sniff attempting to do this itself.
Mind: the return value of thegetDeclaredProperties()method includes constructor promoted properties. Passing the stack pointer of constructor promoted properties onto a call to theVariables::getMemberProperties()method, however, is currently not supported. FunctionDeclarations::getParameters(): support for PHP 8.4 asymmetric visibility. #677Variables::getMemberProperties(): support for PHP 8.4 final properties. Thanks @DanielEScherzer! #646Variables::getMemberProperties(): support for PHP 8.4 asymmetric visibility. #677
Changed
- The exceptions thrown by PHPCSUtils native utilities have been made more modular and more specific. #598, #599, #600
- Passing a parameter of the wrong type will now result in a
PHPCSUtils\Exceptions\TypeErrorbeing thrown. - Passing a parameter of the correct type, but with an invalid value, like an empty string when only non-empty strings are expected/accepted, will now result in a
PHPCSUtils\Exceptions\ValueErrorbeing thrown. - Passing a (positive) integer stack pointer, which doesn't exist in the token stack of the current file, will now result in a
PHPCSUtils\Exceptions\OutOfBoundsStackPtrbeing thrown. - Passing a stack pointer to a token which is not within the range of token types which is accepted by the method, will now result in a
PHPCSUtils\Exceptions\UnexpectedTokenTypebeing thrown. - Logic errors will now result in a
PHPCSUtils\Exceptions\LogicExceptionbeing thrown.
This can occur, for instance, when a method takes a$startand$endparameter and the$endpointer is before the$startpointer. - Missing, conditionally required, parameters, will now result in a
PHPCSUtils\Exceptions\MissingArgumentErrorbeing thrown. - Generic errors will now result in a
PHPCSUtils\Exceptions\RuntimeExceptionbeing thrown. - Previously the PHPCS native
PHP_CodeSniffer\Exceptions\RuntimeExceptionwas used for all these exceptions.
Catching the PHPCS nativeRuntimeExceptionwill still catch the new exceptions, but it is strongly recommended to be more selective when catching exceptions to prevent accidentally hiding errors in sniffs. - Also note that the PHPCSUtils native utilities now include more and stricter type checking to help surface bugs in sniffs.
- Passing a parameter of the wrong type will now result in a
Abstract Sniffs
- The
AbstractArrayDeclarationSniff::process()method will no longer hide exceptions about a non-integer or non-existent stack pointer being passed. #600 - The
AbstractArrayDeclarationSniff::processArray()method will no longer hide exceptions about non-integer or non-existent stack pointers being passed. #600
PHPCS BackCompat
BCFile::getDeclarationName(): sync with PHPCS 3.12.0 - prevent incorrect result during live coding for unfinished closures. #644BCFile::getDeclarationName(): sync with PHPCS 4.0.0 - no longer accept theT_CLOSUREorT_ANON_CLASStokens. #674
Passing these will now result in an exception.BCFile::getDeclarationName(): sync with PHPCS 4.0.0 - the method will now always return a string. #674
Previously, the method could returnnullwhen the name could not be determined. Now it will return an empty string.
TestUtils
- The
PHPCSUtils\TestUtils\UtilityMethodTestCaseis now officially compatible with PHPUnit 11 and will no longer generate any deprecation notices on PHPUnit 11.
Utils
Parentheses: all methods will now recognize closeruse()as a parentheses owner. #674
Note: PHPCS natively does not recognize closureuseas a parentheses owners until PHP_CodeSniffer 4.0.- All methods in the
PassedParametersclass will now be able to analyze exit/die when used as a function call. #618 - The
Scopes::isOOProperty()method now allows for PHP 8.4 properties in interfaces. #674- This also adds support for properties in interfaces to the
Variables::getMemberProperties()method.
- This also adds support for properties in interfaces to the
- The
UseStatements::splitAndMergeImportUseStatement()method will no longer hide exceptions about a non-integer, non-existent or non-T_USEstack pointer being passed. #600
Other
- Dropped support for PHP_CodeSniffer < 3.13.0. #629, #653
Please ensure you runcomposer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Various housekeeping, including making the test suite compatible with PHPUnit 11.
Deprecated
TestUtils
- The (internal)
PHPCSUtils\TestUtils\UtilityMethodTestCase::setStaticConfigProperty()method. #550
This method has become redundant with the introduction of theConfigDoubleclass.
Removed
PHPCS BackCompat
- The javascript specific
T_ZSR_EQUALtoken from theBCTokens::assignmentTokens()array, as per PHPCS 4.0.0. #674 - The javascript specific
T_OBJECTtoken from theBCTokens::blockOpeners()array, as per PHPCS 4.0.0. #674 - The javascript specific
T_PROPERTYandT_OBJECTtokens from theBCTokens::blockOpeners()array, as per PHPCS 4.0.0. #674
Fixed
Abstract Sniffs
AbstractArrayDeclarationSniff::getActualArrayKey(): will now handle FQNtrue/false/nullcorrectly. #668
Utils
Context::inForeachCondition()could misidentify theaskeyword forforeachwhen the iterable expression contained an array declaration in which theaskeyword was being used. #617- The
Numbers::is*()methods could misidentify strings which look like numeric literals with underscores, but are in actual fact invalid as numeric literals, as valid numbers. #619, #620 UseStatements::getType()will now handle unfinished closureusestatements (parse errors) more consistently and return'closure'for those cases. #667
Release notes
Open source →Added
Compatibility with the new PHP_CodeSniffer
4.xbranch in anticipation of the PHP_CodeSniffer 4.0 release. #674, #679 PHPCSUtils should now be fully compatible with PHP_CodeSniffer 4.0 (again). If you still find an issue, please report it.PHPCS BackCompat
BCFile::findExtendedClassName(): sync with PHPCS 4.0.0 - support for namespace relative names when used as the extended parent class name. #674BCFile::findImplementedInterfaceNames(): sync with PHPCS 4.0.0 - support for namespace relative names when used in implemented interface names. #674BCFile::getMemberProperties(): sync with PHPCS 3.12.0 - support for PHP 8.4 final properties. Thanks [@DanielEScherzer]! #646BCFile::getMemberProperties(): sync with PHPCS 3.13.1 - support for PHP 8.4 asymmetric visibility. #677BCFile::getMemberProperties(): sync with PHPCS 4.0.0. #674- Add support for PHP 8.4 properties in interfaces.
- Removed parse error warning.
BCFile::getMethodParameters(): sync with PHPCS 3.13.1 - support for PHP 8.4 asymmetric visibility. #677BCFile::findStartOfStatement(): sync with PHPCS 3.12.1 - support forgotoas aswitch-caseterminating statement. #661BCTokens::nameTokens()as introduced in PHPCS 4.0.0. #674 The same token array previously already existed in PHPCSUtils asCollections::nameTokens().BCTokens::functionNameTokens(): sync with PHPCS 4.0.0 - added theT_ANON_CLASStoken. #674BCTokens::parenthesisOpeners(): sync with PHPCS 4.0.0 - added theT_USE,T_ISSET,T_UNSET,T_EMPTY,T_EVALandT_EXITtokens. #674 Note: WhileT_USE,T_ISSET,T_UNSET,T_EMPTY,T_EVALandT_EXITwill be included in the return value for this method, the associated parentheses will not have the'parenthesis_owner'index set unless PHPCS 4.0.0 is used. Use the [Parentheses::getOwner()][Parentheses] or the [Parentheses::hasOwner()][Parentheses] methods if you need to check whether any of these tokens are a parentheses owner. The methods in theParenthesesclass are PHPCS cross-version compatible.
TestUtils
- New [
PHPCSUtils\TestUtils\ConfigDouble][ConfigDouble] class as a lightweight and more stable alternative to directly using the PHPCS nativeConfigclass in tests. #550, #612 Props to [@fredden] for helping me find and fix a bug in this feature before it was released. - New [
PHPCSUtils\TestUtils\RulesetDouble][RulesetDouble] class which allows for creating aRulesetobject without registering any sniffs. #674 This allows for the [PHPCSUtils\TestUtils\UtilityMethodTestCase][UtilityMethodTestCase] class to be cross-version compatible with both PHP_CodeSniffer 3.x as well as 4.x. - New [
PHPCSUtils\TestUtils\UtilityMethodTestCase::parseFile()][UtilityMethodTestCase] method to allow for on-demand tokenizing of a (secondary) test case file. #591, #610 This method is intended for tests which need to use multiple test case files, like, for example, tests which need to verify that a utility resets a$fileNameproperty on seeing another file. - New [
PHPCSUtils\TestUtils\UtilityMethodTestCase::testTestMarkersAreUnique()andPHPCSUtils\TestUtils\UtilityMethodTestCase::assertTestMarkersAreUnique()][UtilityMethodTestCase] methods which automatically check that code sample files used with thisTestCasedo not contain duplicate test case markers. #642 If needs be, the test method can be disabled by overloading it (discouraged). If a test uses multiple test case/code sample files, the assertion method can be called directly.
Tokens
- New [
Collections::constantTypeTokens()][Collections] method to support PHP 8.3 typed class constants. #562 - New [
Collections::ternaryOperators()][Collections] method. #549 T_EXITto theCollections::functionCallTokens()andCollections::parameterPassingTokens()in light of the PHP 8.4 "exit as function" change. #618- The PHP 8.4 asymmetric visibility tokens have been added to the [
Collections::propertyModifierKeywords()][Collections] method. #653 T_INTERFACEhas been added to the [Collections::ooPropertyScopes()][Collections] method for PHP 8.4 interface properties support. #674
Utils
- New [
PHPCSUtils\Utils\Constants][Constants] class: Utility functions to examine (class) constants. #562 Initially available method:getProperties()to retrieve an array of information about an OO constant declaration. - New [
PHPCSUtils\Utils\FileInfo][FileInfo] class: Utility functions to check characteristics of the file under scan. #572 Initial set of available methods:hasByteOrderMark()andhasSheBang(). - New [
PHPCSUtils\Utils\FilePath][FilePath] class: Utility functions for handling and comparing file paths. #593 Initial set of available methods:getName()to retrieve the normalized path for the current file,isStdin(),normalizeAbsolutePath(),normalizeDirectorySeparators(),trailingSlashIt()andstartsWith(). - New [
PHPCSUtils\Utils\TypeString][TypeString] class: Utility functions for analysing typestrings as retrieved via the various availablegetParameters()/getProperties()methods. #588 Initial set of available methods:getKeywordTypes(),isKeyword(),normalizeCase(),isSingular(),isNullable(),isUnion(),isIntersection(),isDNF(),toArray(),toArrayUnique(),filterKeywordTypes()andfilterOOTypes(). Note: Theis*()methods will not check if the type string provided is valid, as doing so would inhibit what sniffs can flag. Theis*()methods will only look at the form of the type string to determine if it could be valid for a certain type. - New
PHPCSUtils\Utils\ObjectDeclarations::getDeclaredConstants(),PHPCSUtils\Utils\ObjectDeclarations::getDeclaredEnumCases(),PHPCSUtils\Utils\ObjectDeclarations::getDeclaredProperties()andPHPCSUtils\Utils\ObjectDeclarations::getDeclaredMethods()utility methods. #592 These methods will each return an array with the name of the constant/case/property/method as the key and the typical stack pointer needed for further processing. The retrieval of this information is highly optimized for performance. If a sniff needs to search for a named constant/enum case/property/method in an OO structure, in most cases, these methods should be the recommended way for finding the declaration, instead of the sniff attempting to do this itself. Mind: the return value of thegetDeclaredProperties()method includes constructor promoted properties. Passing the stack pointer of constructor promoted properties onto a call to theVariables::getMemberProperties()method, however, is currently not supported. FunctionDeclarations::getParameters(): support for PHP 8.4 asymmetric visibility. #677Variables::getMemberProperties(): support for PHP 8.4 final properties. Thanks [@DanielEScherzer]! #646Variables::getMemberProperties(): support for PHP 8.4 asymmetric visibility. #677
Changed
- The exceptions thrown by PHPCSUtils native utilities have been made more modular and more specific. #598, #599, #600
- Passing a parameter of the wrong type will now result in a
PHPCSUtils\Exceptions\TypeErrorbeing thrown. - Passing a parameter of the correct type, but with an invalid value, like an empty string when only non-empty strings are expected/accepted, will now result in a
PHPCSUtils\Exceptions\ValueErrorbeing thrown. - Passing a (positive) integer stack pointer, which doesn't exist in the token stack of the current file, will now result in a
PHPCSUtils\Exceptions\OutOfBoundsStackPtrbeing thrown. - Passing a stack pointer to a token which is not within the range of token types which is accepted by the method, will now result in a
PHPCSUtils\Exceptions\UnexpectedTokenTypebeing thrown. - Logic errors will now result in a
PHPCSUtils\Exceptions\LogicExceptionbeing thrown. This can occur, for instance, when a method takes a$startand$endparameter and the$endpointer is before the$startpointer. - Missing, conditionally required, parameters, will now result in a
PHPCSUtils\Exceptions\MissingArgumentErrorbeing thrown. - Generic errors will now result in a
PHPCSUtils\Exceptions\RuntimeExceptionbeing thrown. - Previously the PHPCS native
PHP_CodeSniffer\Exceptions\RuntimeExceptionwas used for all these exceptions. Catching the PHPCS nativeRuntimeExceptionwill still catch the new exceptions, but it is strongly recommended to be more selective when catching exceptions to prevent accidentally hiding errors in sniffs. - Also note that the PHPCSUtils native utilities now include more and stricter type checking to help surface bugs in sniffs.
- Passing a parameter of the wrong type will now result in a
Abstract Sniffs
- The
AbstractArrayDeclarationSniff::process()method will no longer hide exceptions about a non-integer or non-existent stack pointer being passed. #600 - The
AbstractArrayDeclarationSniff::processArray()method will no longer hide exceptions about non-integer or non-existent stack pointers being passed. #600
PHPCS BackCompat
BCFile::getDeclarationName(): sync with PHPCS 3.12.0 - prevent incorrect result during live coding for unfinished closures. #644BCFile::getDeclarationName(): sync with PHPCS 4.0.0 - no longer accept theT_CLOSUREorT_ANON_CLASStokens. #674 Passing these will now result in an exception.BCFile::getDeclarationName(): sync with PHPCS 4.0.0 - the method will now always return a string. #674 Previously, the method could returnnullwhen the name could not be determined. Now it will return an empty string.
TestUtils
- The [
PHPCSUtils\TestUtils\UtilityMethodTestCase][UtilityMethodTestCase] is now officially compatible with PHPUnit 11 and will no longer generate any deprecation notices on PHPUnit 11.
Utils
- [
Parentheses]: all methods will now recognize closeruse()as a parentheses owner. #674 Note: PHPCS natively does not recognize closureuseas a parentheses owners until PHP_CodeSniffer 4.0. - All methods in the [
PassedParameters] class will now be able to analyze exit/die when used as a function call. #618 - The
Scopes::isOOProperty()method now allows for PHP 8.4 properties in interfaces. #674- This also adds support for properties in interfaces to the
Variables::getMemberProperties()method.
- This also adds support for properties in interfaces to the
- The
UseStatements::splitAndMergeImportUseStatement()method will no longer hide exceptions about a non-integer, non-existent or non-T_USEstack pointer being passed. #600
Other
- Dropped support for [PHP_CodeSniffer] < 3.13.0. #629, #653
Please ensure you run
composer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Various housekeeping, including making the test suite compatible with PHPUnit 11.
Deprecated
TestUtils
- The (internal)
PHPCSUtils\TestUtils\UtilityMethodTestCase::setStaticConfigProperty()method. #550 This method has become redundant with the introduction of theConfigDoubleclass.
Removed
PHPCS BackCompat
- The javascript specific
T_ZSR_EQUALtoken from theBCTokens::assignmentTokens()array, as per PHPCS 4.0.0. #674 - The javascript specific
T_OBJECTtoken from theBCTokens::blockOpeners()array, as per PHPCS 4.0.0. #674 - The javascript specific
T_PROPERTYandT_OBJECTtokens from theBCTokens::blockOpeners()array, as per PHPCS 4.0.0. #674
Fixed
Abstract Sniffs
AbstractArrayDeclarationSniff::getActualArrayKey(): will now handle FQNtrue/false/nullcorrectly. #668
Utils
Context::inForeachCondition()could misidentify theaskeyword forforeachwhen the iterable expression contained an array declaration in which theaskeyword was being used. #617- The
Numbers::is*()methods could misidentify strings which look like numeric literals with underscores, but are in actual fact invalid as numeric literals, as valid numbers. #619, #620 UseStatements::getType()will now handle unfinished closureusestatements (parse errors) more consistently and return'closure'for those cases. #667
-
1.0.1220 May 2024Release notes
Open source →Added
PHPCS BackCompat
BCFile::getMemberProperties(): sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. #604BCFile::getMethodProperties(): sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. #604BCFile::getMethodParameters(): sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. #604
Utils
FunctionDeclarations::getParameters(): support for PHP 8.2 DNF types. #604FunctionDeclarations::getProperties(): support for PHP 8.2 DNF types. #604Variables::getMemberProperties(): support for PHP 8.2 DNF types. #604
Changed
Tokens
Collections::parameterTypeTokens(),Collections::propertyTypeTokens()andCollections::returnTypeTokens(): now include the newT_TYPE_OPEN_PARENTHESISandT_TYPE_CLOSE_PARENTHESIStokens for PHP 8.2 DNF type support. #604
Utils
ControlStructures::getCaughtExceptions(): will now silently ignore parse errors in the code under scan which prevent the method from analyzing acatchstatement. #594
The method will now return an empty array instead of throwing aPHP_CodeSniffer\Exceptions\RuntimeException.
Other
- Dropped support for PHP_CodeSniffer < 3.10.0. #603
Please ensure you runcomposer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Various housekeeping and documentation improvements.
Fixed
Utils
UseStatements::splitImportUseStatement(): the values in the return array will now never include a leading backslash. #590
Previously the behaviour around importusestatements declared with a leading backslash was undefined and the backslash would be included in the return value.
Release notes
Open source →Added
PHPCS BackCompat
BCFile::getMemberProperties(): sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. #604BCFile::getMethodProperties(): sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. #604BCFile::getMethodParameters(): sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. #604
Utils
FunctionDeclarations::getParameters(): support for PHP 8.2 DNF types. #604FunctionDeclarations::getProperties(): support for PHP 8.2 DNF types. #604Variables::getMemberProperties(): support for PHP 8.2 DNF types. #604
Changed
Tokens
Collections::parameterTypeTokens(),Collections::propertyTypeTokens()andCollections::returnTypeTokens(): now include the newT_TYPE_OPEN_PARENTHESISandT_TYPE_CLOSE_PARENTHESIStokens for PHP 8.2 DNF type support. #604
Utils
ControlStructures::getCaughtExceptions(): will now silently ignore parse errors in the code under scan which prevent the method from analyzing acatchstatement. #594 The method will now return an empty array instead of throwing aPHP_CodeSniffer\Exceptions\RuntimeException.
Other
- Dropped support for [PHP_CodeSniffer] < 3.10.0. #603
Please ensure you run
composer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Various housekeeping and documentation improvements.
Fixed
Utils
UseStatements::splitImportUseStatement(): the values in the return array will now never include a leading backslash. #590 Previously the behaviour around importusestatements declared with a leading backslash was undefined and the backslash would be included in the return value.
-
1.0.1124 Apr 2024Release notes
Open source →Changed
Other
- Various housekeeping and documentation improvements. Includes a contribution from @fredden.
Fixed
PHPCS BackCompat
BCFile::getMethodProperties(): small performance improvement & more defensive coding, in line with same fix in PHPCS 3.9.2. #573
Utils
FunctionDeclarations::getProperties(): small performance improvement & more defensive coding, in line with same fix in PHPCS 3.9.2. #573
Release notes
Open source →Changed
Other
- Various housekeeping and documentation improvements. Includes a contribution from [@fredden].
Fixed
PHPCS BackCompat
BCFile::getMethodProperties(): small performance improvement & more defensive coding, in line with same fix in PHPCS 3.9.2. #573
Utils
FunctionDeclarations::getProperties(): small performance improvement & more defensive coding, in line with same fix in PHPCS 3.9.2. #573
-
1.0.1017 Mar 2024Release notes
Open source →Changed
Other
- Dropped support for [PHP_CodeSniffer] < 3.9.0. #561
Please ensure you run
composer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Various housekeeping and documentation improvements.
Deprecated
Utils
Fixed
PHPCS BackCompat
- Dropped support for [PHP_CodeSniffer] < 3.9.0. #561
Please ensure you run
-
1.0.908 Dec 2023Release notes
Open source →Added
PHPCS BackCompat
BCFile::getMemberProperties(): sync with PHPCS 3.8.0 - support for PHP 8.2truetype. #524BCFile::getMethodProperties(): sync with PHPCS 3.8.0 - support for PHP 8.2truetype. #524BCFile::getMethodParameters(): sync with PHPCS 3.8.0 - support for PHP 8.2truetype. #524
Changed
TestUtils
- Significant performance improvement for the [
UtilityMethodTestCase]. #525
Other
- Dropped support for [PHP_CodeSniffer] < 3.8.0. #523
Please ensure you run
composer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Small improvements to the documentation website generation. Includes a contribution from [@fredden].
- Various housekeeping and documentation improvements. Includes a contribution from [@fredden].
-
1.0.816 Jul 2023Release notes
Open source →Changed
PHPCS BackCompat
BCFile::getDeclarationName(): sync with PHPCS 3.8.0 - support for functions calledself,parentorstaticwhich return by reference. #494
Other
- Various housekeeping and minor documentation improvements.
Fixed
Fixers
- The [
SpacesFixer] will no longer throw an (incorrect) exception when the second pointer passed is a comment token and this comment token is the last content in a file. #493
-
1.0.710 Jul 2023Release notes
Open source →Changed
Other
- Various housekeeping and maintenance updates, including making the test suite compatible with PHPUnit 10.
Fixed
Utils
- The
Arrays::getDoubleArrowPtr()method could previously get confused over a double arrow in a keyed list used as an array value. #485
-
1.0.627 May 2023Release notes
Open source →Changed
PHPCS BackCompat
BCFile::getClassProperties(): sync with PHPCS 3.8.0 - support for PHP 8.2readonlyclasses. #470BCFile::getMethodParameters(): sync with PHPCS 3.8.0 - support for constructor property promotion withreadonlyproperties without explicit visibility. #472
Utils
- The results of the following methods will now (also) be cached for improved performance when multiple sniffs call these functions for the same token during a PHPCS run. #464, #466
FunctionDeclarations::getProperties()Variables::getMemberProperties()
- Additionally, the results of the
UseStatements::splitImportUseStatement()method will be cached more often and the cache checked earlier. #467 - The return value of the
ControlStructures::getCaughtExceptions()method will no longer contain "empty" entries for catch statements without a named exception. It will return an empty array instead. #474
Other
- Various small housekeeping and maintenance updates.
Fixed
Abstract Sniffs
-
1.0.517 Apr 2023Release notes
Open source →Fixed
Utils
- The
Lists::getAssignments()method could previously get confused over exotic list keys. Fixed now. #459
- The
-
1.0.415 Apr 2023Release notes
Open source →Changed
Other
- Minor documentation improvements.
Fixed
Utils
- The
FunctionDeclarations::getParameters()method will now correctly handle constructor promoted properties withreadonly, but without explicit visibility set. #456
-
1.0.313 Apr 2023Release notes
Open source →Changed
Other
- Various small housekeeping and maintenance updates.
Fixed
Utils
- The
PassedParametersclass now allows for function calls to global functions calledself(),parent()orstatic(). #452
-
1.0.228 Mar 2023Release notes
Open source →Changed
Tokens
- The
Collections::arrayOpenTokensBC(),Collections::arrayTokensBC(),Collections::listOpenTokensBC(),Collections::listTokensBC(),Collections::shortArrayListOpenTokensBC(),Collections::shortArrayTokensBC()andCollections::shortListTokensBC()token arrays will no longer contain theT_OPEN_SQUARE_BRACKETand/or theT_CLOSE_SQUARE_BRACKETtoken constants if PHP_CodeSniffer 3.7.2 or higher is used. #444 An upstream bugfix makes it unnecessary to check those tokens for being a short array or short list. Sniff which use these token arrays is combination with using theArrays/Listsclasses, should experience a performance boost on PHPCS 3.7.2+ due to this change.
Other
- Minor documentation improvements.
- Various small housekeeping and maintenance updates.
Fixed
Utils
- The
Lists::isShortList()method will now correctly recognize a short list nested in a long list as a short list. #446 Note: this is a parse error in PHP, but the method should still handle this correctly.
- The
-
1.0.105 Jan 2023Release notes
Open source →Changed
Other
- Composer: The version requirements for the [Composer PHPCS plugin] have been widened to allow for version 1.0.0. #428
Please ensure you run
composer update phpcsstandards/phpcsutils --with-dependenciesto benefit from this. - Removed the references to pre-1.0.0 QA releases from the docs. #425
- Various small housekeeping and maintenance updates. Thanks [@szepeviktor] for contributing.
- Composer: The version requirements for the [Composer PHPCS plugin] have been widened to allow for version 1.0.0. #428
Please ensure you run
-
1.0.003 Jan 2023Release notes
Open source →For the full list of features, please see the changelogs of the alpha/rc releases:
Changed
Other
- Minor documentation improvements.
- Maintainability improvements.
-
1.0.0-rc127 Dec 2022 pre-releaseRelease notes
Open source →Added
Tokens
- New [
Collections::constantModifierKeywords()][Collections] method. #400 - New [
Collections::listOpenTokensBC()][Collections] method. #405
Changed
Utils
ObjectDeclarations::getClassProperties(): the array return value will now include'abstract_token','final_token', and'readonly_token'indexes identifying the stack pointers to these keyword, where applicable. If the keyword is not used, the value will be set tofalse. #401
Other
- Various housekeeping and CI maintenance.
Removed
Everything which was previously deprecated in the 1.0.0-alpha4 release, has now been removed. #410
This includes:
- The
PHPCS23Utilsstandard. - [
Collections] class: direct access to the properties in the class. - [
Collections] class: theCollections::arrowFunctionTokensBC(),Collections::functionDeclarationTokensBC(),Collections::parameterTypeTokensBC(),Collections::propertyTypeTokensBC()andCollections::returnTypeTokensBC()methods. - The
ControlStructures::getDeclareScopeOpenClose()method. - The
FunctionDeclarations::getArrowFunctionOpenClose()method. - The
FunctionDeclarations::isArrowFunction()method.
See the changelog for the 1.0.0-alpha4 release for details about replacements for the removed functionality.
Fixed
Utils
- New [
-
1.0.0-alpha425 Oct 2022 pre-releaseRelease notes
Open source →Notes:
- While still in alpha, some BC-breaks may be introduced. These are clearly indicated in the changelog with the :warning: symbol.
- Until PHPCS 4.x has been released, PHPCSUtils does not formally support it, though an effort is made to keep up with the changes and anticipate potential compatibility issues. For testing purposes only, the composer configuration allows for PHPCSUtils to be installed with PHPCS 4.x.
Breaking Changes
Support for PHP_CodeSniffer < 3.7.1 has been dropped after consultation with the principle external standards which depend on PHPCSUtils. #347
This was unfortunately necessary as the incessant additions of new syntaxes since PHP 7.4 made it impossible to continue to support PHPCS < 3.7.1, while still providing reliable results for modern PHP code.
Added
Now support for PHPCS < 3.7.1 has been dropped, this edition adds support to all functionality in PHPCSUtils for new syntaxes and features from PHP 8.0 and 8.1 and preliminary support for PHP 8.2.
This means that support for the following syntaxes/features has been added (or existing support verified/improved):
- PHP 7.4
- Array unpacking in array expressions.
- PHP 8.0
- The
mixedtype. #163 - Union types, including supporting the
falseandnulltypes. #168, #225 - Constructor property promotion. #169, #226
- Nullsafe object operators. #176, #183
- Namespaced names as single token (cross-version PHPCS 3.x vs 4.x). #205, #206, #207, #208, #209, #210, #211, #212, #213, #217, #241
- Dereferencing of interpolated text strings.
- Named arguments in function calls. #235, #243, #383
- Match expressions. #247, #335, #356
- Trailing commas in parameter lists and closure
uselists. - Attributes. #357
- The
- PHP 8.1
- PHP 8.2
Please report any bugs/oversights you encounter!
PHPCS Backcompat
BCTokens::magicConstants()as introduced in PHPCS 3.5.6. #172 The same token array previously already existed in PHPCSUtils asCollections::$magicConstants(which has now been deprecated).
TestUtils
- New
UtilityMethodTestCase::usesPhp8NameTokens()method as a helper for tests using token position calculations when testing against both PHPCS 3.x as well as 4.x. #200, #217, #241
Tokens
- New [
PHPCSUtils\Tokens\TokenHelper][TokenHelper] class: Utility functions for working with tokens and token collections. #304 This class initially contains atokenExists()method to work around potential interference from PHP-Parser also backfilling tokens. :point_right: External standards using a function call todefined()to determine whether a token is available should replace those with a function call to theTokenHelper::tokenExists()method. - New [
Collections::arrayOpenTokensBC()][Collections] method. #233, #311 - New [
Collections::functionCallTokens()][Collections] method to retrieve the tokens which can represent function calls and function-call-like language constructs, like class instantiations. #233 - New [
Collections::nameTokens()][Collections] method to retrieve the tokens which can be used for "names", be it namespace, OO, function or constant names. #204, #217 - New [
Collections::namespacedNameTokens()][Collections] method to retrieve the tokens which can be encountered in a fully, partially or unqualified name and in namespace relative names. #202, #217 - New [
Collections::parameterPassingTokens()][Collections] method to retrieve the tokens which can be passed to the methods in the [PassedParameters] class. #233 - New [
Collections::phpOpenTags()][Collections] method. #254 - New [
Collections::shortArrayListOpenTokensBC()][Collections] method. #381
Utils
- New [
PHPCSUtils\Utils\Context][Context] class: Utility functions to determine the context in which an arbitrary token is used. #219. #390 Initial set of available methods:inEmpty(),inIsset(),inUnset(),inAttribute,inForeachCondition()andinForCondition(). - New [
PHPCSUtils\Utils\MessageHelper][MessageHelper] class: Utility functions for creating error/warning messages. #249, #391 Initial set of available methods:addMessage(),addFixableMessage(),stringToErrorcode()andshowEscapeChars(). - New
PHPCSUtils\Utils\PassedParameters::getParameterFromStack()efficiency method to retrieve a potentially named function call parameter from a parameter information stack as previously retrieved viaPassedParameters::getParameters(). #235, #237, #383 - New
PHPCSUtils\Utils\TextStrings::getEndOfCompleteTextString()method. #320 This method allows to retrieve the stack pointer to the last token within a - potentially multi-line - text string. This method compliments theTextStrings::getCompleteTextString()method which will retrieve the contents of the complete text string. - New
PHPCSUtils\Utils\TextStrings::getEmbeds()method to retrieve an array with all variables/expressions as embedded in a text string. #321 - New
PHPCSUtils\Utils\TextStrings::stripEmbeds()method to strip all embedded variables/expressions from a text string. #321 - New
PHPCSUtils\Utils\TextStrings::getStripEmbeds()method. #321 This method ispublicfor those rare cases where both the embeds, as well as the text stripped off embeds, is needed. - New
PHPCSUtils\Utils\UseStatements::mergeImportUseStatements()method. #196
Other
- PHPCSUtils will now cache the results of (potentially) token walking intensive or processing intensive function calls during a run. #332, #377
This should significantly improve performance when multiple sniffs call these functions for the same token during a PHPCS run.
The results of the following functions will now be cached:
Arrays::getDoubleArrowPtr()Arrays::isShortArray()FunctionDeclarations::getParameters()Lists::getAssignments()Lists::isShortList()Namespaces::findNamespacePtr()PassedParameters::getParameters()TextStrings::getEndOfCompleteTextString()TextStrings::getStripEmbeds()UseStatements::splitImportUseStatement()
Changed
PHPCS Backcompat
- All token array methods in the [
BCTokens] class are fully up-to-date with the upstreamPHP_CodeSniffer\Util\Tokensproperties as per PHPCSmasterat the time of this release. #327, #347, #360 - All methods in the [
BCFile] class are fully up-to-date with the upstreamPHP_CodeSniffer\Files\Filemethods as per PHPCSmasterat the time of this release. #347 BCFile::getMethodParameters(): forward compatibility with PHPCS 4.x in which closureusewill be a parenthesis owner. #251- If a non-existent token array is requested from the
BCTokensclass, aPHPCSUtils\Exceptions\InvalidTokenArrayexception will be thrown. #344 ThePHPCSUtils\Exceptions\InvalidTokenArrayexception extends the PHPCS nativePHP_CodeSniffer\Exceptions\RuntimeException. Previously, an empty array would be returned.
TestUtils
UtilityMethodTestCase: all properties contained in the test case class will now always be reset after the tests have run. #325UtilityMethodTestCase::getTargetToken(): when the target token cannot be found, the method will now throw a (catchable)PHPCSUtils\Exceptions\TestTargetNotFoundexception instead of failing the test. #248, #371 If uncaught, this means that the test will be marked as errored instead of failed.UtilityMethodTestCase::getTargetToken(): this method is nowstatic, which allows for it to be used in "set up before class" fixtures. #382. #385
Tokens
Collections::functionCallTokens()andCollections::parameterPassingTokens(): now include theT_PARENTtoken. #328 This accounts for a change in PHPCS 3.7.0 for howparentinnew parentis tokenized.- If a non-existent token array is requested from the
Collectionsclass, aPHPCSUtils\Exceptions\InvalidTokenArrayexception will be thrown. #349 ThePHPCSUtils\Exceptions\InvalidTokenArrayexception extends the PHPCS nativePHP_CodeSniffer\Exceptions\RuntimeException.
Utils
Arrays::isShortArray()/Lists::isShortList(): the underlying logic has been completely refactored for improved accuracy and improved performance. #392FunctionDeclarations::getParameters(): the return array of the method may contain two new keys -property_visibilityandvisibility_token. #169 These keys will only be included if constructor property promotion is detected.FunctionDeclarations::getParameters(): forward compatibility with PHPCS 4.x in which closureusewill be a parenthesis owner. #251- [
GetTokensAsString]: previously thetabReplaced()method was an alias for thenormal()method. This has now been reversed. #297 Operators::isReference(): forward compatibility with PHPCS 4.x in which closureusewill be a parenthesis owner. #195- [
Parentheses]: all methods will now recognizeisset(),unset(),empty(),exit(),die()andeval()as parentheses owners. #215 Note: PHPCS natively does not recognize these constructs as parentheses owners, though this may change in the future. See: PHPCS#3118 - [
PassedParameters]: all methods will now recognize anonymous class instantiations as constructs which can pass parameters. #234 PassedParameters::getParameters(): when a named parameter is encountered in a function call, the returned parameter information array for that parameter will now contain the following additional keys:'name','name_token'and the top-level index for the parameter will be set to the parameter'name'instead of its position. #235, #243, #383 The existing'start','end','raw'and'clean'keys will contain the same content as before: the information about the parameter value (excluding the name part).PassedParameters::getParameters(): new, optional parameter$limitto allow for limiting the number of parameters/array items to be parsed. #261 This allows for higher efficiency when retrieving the parameters/array entries, especially for large arrays if only the first few entries need to be examined. Use with care on function calls, as this can break support for named parameters!PassedParameters::getParameters(): new, optional parameter$isShortArrayto allow for skipping the "is short array" check for predetermined short arrays. #269, #270 Use judiciously and with extreme care!PassedParameters::getParameter(): new semi-optional$paramNamesparameter to allow for retrieving a parameter from a function call using named parameters. #235 :warning: This parameter is required when examining a function call and an exception will be thrown if it was not passed. This new$paramNamesparameter allows for passing either the parameter name as a string or as an array of strings. While a parameter can only have one name, a lot of packages have been, and may still be, reviewing and renaming parameters to more descriptive names to support named parameters in PHP 8.0, so, to allow for supporting multiple versions of packages, different names can be used for the same parameter in a PHP 8.0+ function call and by allowing multiple names to be passed, the method supports this.PassedParameters::getParameter(): efficiency improvement applicable to function calls not using named parameters and arrays. #261, #262PassedParameters::hasParameters(): now allows for theT_PARENTtoken fornew parent()class instantiations. #328 This accounts for a change in PHPCS 3.7.0 regarding howparentinnew parentis tokenized.PassedParameters::hasParameters(): new, optional parameter$isShortArrayto allow for skipping the "is short array" check for predetermined short arrays. #269, #270 Use judiciously and with extreme care!UseStatements::getType(): forward compatibility with PHPCS 4.x in which closureusewill be a parenthesis owner. #251
Other
- The
masterbranch has been renamed tostable. #397 - :warning: All non-
abstractclasses in this package are nowfinal. #376 - The parameter names in various function declarations have been changed to not intersect with reserved keywords. #256 :warning: In the unlikely event an external standard using PHPCSUtils would be using function calls with named parameters, the parameter names will need to be updated to match.
- Composer: The package will now identify itself as a static analysis tool. Thanks [@GaryJones]! #341
- Readme/website homepage: the installation instructions have been updated to include information on installing this library and the included [Composer PHPCS plugin] in combination with Composer >= 2.2. #291, #292
- Various documentation improvements. #216, #309, #394, #395, #396, #398
- Various housekeeping and CI maintenance. Amongst other things, CI is now run via GitHub Actions (#239), the PHPCSUtils native tests now use the PHPUnit Polyfills package (#277) and the tests are now run against PHP 5.4 - 8.2.
Deprecated
:warning: Everything which has currently been deprecated, will be removed before the final
1.0.0version of PHPCSUtils is tagged.Tokens
[
Collections] class: direct access to the properties in the class is now deprecated for forward-compatibility reasons. All properties have a replacement which should be used instead, in most cases this will be a method with the same name as the previously used property,Deprecated Replacement PR Remarks Collections::$alternativeControlStructureSyntaxTokensCollections::alternativeControlStructureSyntaxes()#311 Mind the change in the name! Collections::$alternativeControlStructureSyntaxCloserTokensCollections::alternativeControlStructureSyntaxClosers()#311 Mind the change in the name! Collections::$arrayTokensCollections::arrayTokens()#311 Collections::$arrayTokensBCCollections::arrayTokensBC()#311 Collections::$classModifierKeywordsCollections::classModifierKeywords()#311 Collections::$closedScopesCollections::closedScopes()#311 Collections::$controlStructureTokensCollections::controlStructureTokens()#311 Collections::$incrementDecrementOperatorsCollections::incrementDecrementOperators()#311 Collections::$listTokensCollections::listTokens()#311 Collections::$listTokensBCCollections::listTokensBC()#311 Collections::$magicConstantsPHPCSUtils\BackCompat\BCTokens::magicConstants()orPHP_CodeSniffer\Util\Tokens::$magicConstants#311 Collections::$namespaceDeclarationClosersCollections::namespaceDeclarationClosers()#311 Collections::$objectOperatorsCollections::objectOperators()#176 Collections::$OOCanImplementCollections::ooCanImplement()#311 Mind the case change in the ooprefix!Collections::$OOCanExtendCollections::ooCanExtend()#311 Mind the case change in the ooprefix!Collections::$OOConstantScopesCollections::ooConstantScopes()#311 Mind the case change in the ooprefix!Collections::$OOPropertyScopesCollections::ooPropertyScopes()#311 Mind the case change in the ooprefix!Collections::$OOHierarchyKeywordsCollections::ooHierarchyKeywords()#311 Mind the case change in the ooprefix!Collections::$OONameTokensCollections::namespacedNameTokens()#202 Mind the change name! Collections::$parameterTypeTokensCollections::parameterTypeTokens()#168 Collections::$propertyModifierKeywordsCollections::propertyModifierKeywords()#311 Collections::$propertyTypeTokensCollections::propertyTypeTokens()#168 Collections::$returnTypeTokensCollections::returnTypeTokens()#168 Collections::$shortArrayTokensCollections::shortArrayTokens()#311 Collections::$shortArrayTokensBCCollections::shortArrayTokensBC()#311 Collections::$shortListTokensCollections::shortListTokens()#311 Collections::$shortListTokensBCCollections::shortListTokensBC()#311 Collections::$textStingStartTokensCollections::textStringStartTokens()#311, #319 Mind the fixed typo in the name! Additionally, the following methods in the
Collectionsclass have been deprecated:Deprecated Replacement PR Collections::arrowFunctionTokensBC()Use the T_FNtoken instead.#347 Collections::functionDeclarationTokensBC()Collections::functionDeclarationTokens()#347 Collections::parameterTypeTokensBC()Collections::parameterTypeTokens()#347 Collections::propertyTypeTokensBC()Collections::propertyTypeTokens()#347 Collections::returnTypeTokensBC()Collections::returnTypeTokens()#347 Utils
ControlStructures::getDeclareScopeOpenClose(): this method is no longer needed, check thescope_opener/scope_closeron theT_DECLAREtoken instead. #347FunctionDeclarations::getArrowFunctionOpenClose(): this method is no longer needed, check thescope_opener/scope_closeretc on theT_FNtoken instead. #347FunctionDeclarations::isArrowFunction(): this method is no longer needed, use theT_FNtoken instead. #347
Other
- The
PHPCS23Utilsstandard, which is no longer needed now support for PHPCS < 3.7.1 has been dropped. #347
Removed
- Support for PHPCS < 3.7.1. #347
Utils
- The following constants, which were only intended for internal use, have been removed: #347
PHPCSUtils\Utils\Numbers::REGEX_NUMLIT_STRINGPHPCSUtils\Utils\Numbers::REGEX_HEX_NUMLIT_STRINGPHPCSUtils\Utils\Numbers::UNSUPPORTED_PHPCS_VERSION
Fixed
Abstract Sniffs
AbstractArrayDeclarationSniff::getActualArrayKey(): will now handle escaped vars in heredoc array keys better. #379
Fixers
- [
SpacesFixer]: in a specific new line vs trailing comment situation, the fixer would incorrectly add a stray new line. #229
TestUtils
UtilityMethodTestCase::getTargetToken(): will now throw aPHPCSUtils\Exceptions\TestMarkerNotFoundexception if the provided test marker comment is not found. #273, #372 This prevents the method potentially misidentifying the target token.
Tokens
Collections::parameterTypeTokens(),Collections::propertyTypeTokens()andCollections::returnTypeTokens(): include thenamespacekeyword for namespace relative identifier names. #180
Utils
Arrays::isShortArray()/Lists::isShortList(): fixed a number of bugs which previously resulted in an incorrect short list/short array determination. #392FunctionDeclarations::getParameters(): will now correctly recognize namespace relative names when used in a parameter type. #180FunctionDeclarations::getProperties(): will now correctly recognize namespace relative names when used in the return type. #180ObjectDeclarations::findExtendedClassName(): will now correctly recognize namespace relative names when used as the extended parent class name. #181ObjectDeclarations::findExtendedInterfaceNames(): will now correctly recognize namespace relative names when used in extended interface names. #181ObjectDeclarations::findImplementedInterfaceNames(): will now correctly recognize namespace relative names when used in implemented interface names. #181ObjectDeclarations::getClassProperties(): will now correctly handle classes declared with both thefinalas well as theabstractkeyword. #252Operators::isReference(): if one parameter in a function declaration was passed by reference, then allT_BITWISE_AND(not intersection type&'s) tokens would be regarded as references. #188Operators::isReference(): the&would not be recognized as a reference for arrow function parameters passed by reference. #192Operators::isUnaryPlusMinus(): a precedingexit,break,continueor arrow function=>is now recognized as an indicator that a plus/minus sign is unary. #187, #197Variables::getMemberProperties(): will now correctly recognize namespace relative names when used in a property type. #180
-
1.0.0-alpha328 Jun 2020 pre-releaseRelease notes
Open source →Notes:
- While still in alpha, some BC-breaks may be introduced. These are clearly indicated in the changelog with the :warning: symbol.
- Until PHPCS 4.x has been released, PHPCSUtils does not formally support it, though an effort is made to keep up with the changes and anticipate potential compatibility issues. For testing purposes, the composer configuration allows for PHPCSUtils to be installed with PHPCS 4.x.
- Until PHP 8.0 has been released, PHPCSUtils does not formally support it, though an effort is made to keep up with the changes and anticipate potential compatibility issues. For testing purposes, the composer configuration allows for PHPCSUtils to be installed with PHP 8.
Added
- New [
PHPCSUtils\Utils\NamingConventions][NamingConventions] class: Utility functions for working with identifier names (namespace names, class/trait/interface names, function names, variable and constant names). #119 - New
PHPCSUtils\BackCompat\Helper::getEncoding()method. #118 - New
PHPCSUtils\Utils\ControlStructures::getCaughtExceptions()method. #114, #138 - New
PHPCSUtils\Utils\UseStatements::splitAndMergeImportUseStatement()method. #117
PHPCS BackCompat
BCFile::getMethodProperties(): support for "static" as a return type (PHP 8.0). #134, PHPCS#2952
TestUtils
- [
UtilityMethodTestCase]: new public$phpcsVersionproperty for use in tests. #107 Note: if the PHPCS version is needed within a data provider method for a test,Helper::getVersion()still needs to be used as the data providers are run before thesetUpBeforeClass()-like methods which set the property.
Tokens
- New [
Collections::$incrementDecrementOperators][Collections] property. #130 - New [
Collections::$magicConstants][Collections] property. #106 - New [
Collections::$objectOperators][Collections] property. #130 - New [
Collections::$OOHierarchyKeywords][Collections] property representing the keywords to access properties or methods from inside a class definition, i.eself,parentandstatic. #115 - New [
Collections::$OONameTokens][Collections] property containing tokens which can be part of a partially/fully qualified name when used in inline code. #113 - New [
Collections::functionDeclarationTokens()][Collections] method to retrieve the tokens which represent a keyword starting a function declaration. #133 This method is compatible with PHPCS 3.5.3 and higher. - New [
Collections::functionDeclarationTokensBC()][Collections] method to retrieve the tokens which represent a keyword starting a function declaration (cross-version compatible). #133 This method is compatible with PHPCS 2.6.0 and higher. - New [
Collections::parameterTypeTokensBC()][Collections] method to retrieve the tokens which need to be recognized for parameter types cross-version. #109 Use this method when the implementing standard needs to support PHPCS < 3.3.0. - New [
Collections::propertyTypeTokensBC()][Collections] method to retrieve the tokens which need to be recognized for property types cross-version. #109 Use this method when the implementing standard needs to support PHPCS < 3.3.0. - New [
Collections::returnTypeTokensBC()][Collections] method to retrieve the tokens which need to be recognized for return types cross-version. #109 Use this method when the implementing standard needs to support PHPCS < 3.5.4. Collections::$returnTypeTokens: support for "static" as a return type (PHP 8.0). #134
Utils
FunctionDeclarations::getProperties(): support for "static" as a return type (PHP 8.0). #134
Changed
PHPCS BackCompat
BCFile::getDeclarationName(): has been made compatible with PHPCS 4.x. #110BCFile::getMethodProperties(): has been made compatible with PHPCS 4.x. #109BCFile::getMemberProperties(): has been made compatible with PHPCS 4.x. #109BCTokens: :warning: The visibility of theBCTokens::$phpcsCommentTokensTypes,BCTokens::$ooScopeTokens,BCTokens::$textStringTokensproperties has changed fromprotectedtoprivate. #139Helper::setConfigData(): has been made compatible with PHPCS 4.x. #137 A new$configparameter has been added to the method. This parameter is a required parameter when the method is used with PHPCS 4.x.
TestUtils
- [
UtilityMethodTestCase]: tests for JS/CSS will now automatically be skipped when run in combination with PHPCS 4.x (which drops JS/CSS support). #111 - Confirmed that the currently available test utils are compatible with PHPUnit 9.x. #103
Tokens
Collections::$parameterTypeTokens: has been made compatible with PHPCS 4.x. #109 :warning: This removes support for PHPCS < 3.3.0 from the property. Use the [Collections::parameterTypeTokensBC()][Collections] method instead if PHPCS < 3.3.0 needs to be supported.Collections::$propertyTypeTokens: has been made compatible with PHPCS 4.x. #109 :warning: This removes support for PHPCS < 3.3.0 from the property. Use the [Collections::propertyTypeTokensBC()][Collections] method instead if PHPCS < 3.3.0 needs to be supported.Collections::$returnTypeTokens: has been made compatible with PHPCS 4.x. #109 :warning: This removes support for PHPCS < 3.5.4 from the property. Use the [Collections::returnTypeTokensBC()][Collections] method instead if PHPCS < 3.5.4 needs to be supported.
Utils
FunctionDeclarations::getArrowFunctionOpenClose(): has been made compatible with PHPCS 4.x. #109FunctionDeclarations::getProperties(): has been made compatible with PHPCS 4.x. #109- :warning:
Lists::getAssignments(): the return value of the method has been consolidated to be less fiddly to work with. #129- :warning: The
nested_listindex key in the return value has been renamed tois_nested_list.
- :warning: The
ObjectDeclarations::getName(): has been made compatible with PHPCS 4.x. #110Variables::getMemberProperties(): has been made compatible with PHPCS 4.x. #109
Other
- Composer: PHPCSUtils can now be installed in combination with PHPCS
4.0.x-dev@devfor testing purposes. - Composer: The version requirements for the [Composer PHPCS plugin] have been widened to allow for version 0.7.0 which supports Composer 2.0.0.
- Readme/website homepage: textual improvements. Props [@GaryJones]. #121
- Readme/website homepage: added additional FAQ question & answers. #157
- The website homepage is now generated using the GitHub Pages gem with Jekyll, making maintenance easier. #141
- Significant improvements to the docblock documentation and by extension the generated API documentation. #145, #146, #147, #148, #149, #150, #151, #152, #153, #154, #155, #156
- Various housekeeping.
Fixed
Abstract Sniffs
AbstractArrayDeclarationSniff: improved parse error handling. #99
PHPCS BackCompat
BCFile::findEndOfStatement(): now supports arrow functions when used as a function argument, in line with the same change made in PHPCS 3.5.5. #143BcFile::isReference(): bug fix, the reference operator was not recognized as such for closures declared to return by reference. #160, PHPCS#2977
Utils
FunctionDeclarations::getArrowFunctionOpenClose(): now supports arrow functions when used as a function argument, in line with the same change made in PHPCS 3.5.5. #143FunctionDeclarations::getArrowFunctionOpenClose(): now supports for arrow functions returning heredoc/nowdocs, in line with the same change made in PHPCSmasterand expected to be released in PHPCS 3.5.6. #143FunctionDeclarations::getName(): bug fix for functions declared to return by reference. #131FunctionDeclarations::isMagicFunction(): bug fix for nested functions. #127Operators::isReference(): bug fix, the reference operator was not recognized as such for closures declared to return by reference. #142Namespaces::getType(): improved type detection for when thenamespacekeyword is used as an operator in the global namespace. #132TextStrings::getCompleteTextString(): will now remove the newline at the end of a heredoc/nowdoc. #136 PHP itself does not include the last new line in a heredoc/nowdoc text string when handling it, so the method shouldn't either.
-
1.0.0-alpha216 Feb 2020 pre-releaseRelease notes
Open source →Note:
- While still in alpha, some BC-breaks may be introduced. These are clearly indicated in the changelog with the :warning: symbol.
Added
- New [
PHPCSUtils\Utils\ControlStructures][ControlStructures] class: Utility functions for use when examining control structures. #70 - New
PHPCSUtils\Utils\FunctionDeclarations::isArrowFunction()method. #77, #79 - New
PHPCSUtils\Utils\FunctionDeclarations::getArrowFunctionOpenClose()method. #77, #79
PHPCS BackCompat
BCFile::isReference(): support for arrow functions returning by reference. #77BCFile::getMethodParameters(): support for arrow functions. #77, #79BCFile::getMethodProperties(): support for arrow functions. #77, #79, #89BCFile::getDeclarationName(): allow functions to be called "fn". #77BCFile::findEndOfStatement(): support for arrow functions. #77, #79BCFile::findStartOfStatement(): support for arrow functions. #77
Tokens
- New [
Collections::$alternativeControlStructureSyntaxTokens][Collections] property. #70 - New [
Collections::$alternativeControlStructureSyntaxCloserTokens][Collections] property. #68, #69 - New [
Collections::$controlStructureTokens][Collections] property. #70 - New [
Collections::arrowFunctionTokensBC()][Collections] method. #79
Utils
Arrays::getDoubleArrowPtr(): support for arrow functions. #77, #79, #84FunctionDeclarations::getParameters(): support for arrow functions. #77, #79FunctionDeclarations::getProperties(): support for arrow functions. #77, #79Operators::isReference(): support for arrow functions returning by reference. #77Parentheses::getOwner(): support for arrow functions. #77Parentheses::isOwnerIn(): support for arrow functions. #77, #79
Other
- Documentation website at https://phpcsutils.com/
Changed
PHPCS BackCompat
BCFile::getCondition(): sync with PHPCS 3.5.4 - added support for new$firstparameter. #73
Tokens
- The
Collections::$returnTypeTokensproperty now includesT_ARRAYto allow for supporting arrow functions in PHPCS < 3.5.3. #77
Utils
- :warning:
Conditions::getCondition(): sync with PHPCS 3.5.4 - renamed the existing$reverseparameter to$firstand reversing the meaning of the boolean values, to stay in line with PHPCS itself. #73 - :warning:
Numbers: the$unsupportedPHPCSVersionsproperty has been replaced with anUNSUPPORTED_PHPCS_VERSIONconstant. #88
Other
- Various housekeeping.
-
1.0.0-alpha123 Jan 2020 pre-releaseRelease notes
Open source →Initial alpha release containing:
- A
PHPCS23Utilsstandard which can be used to allow an external PHPCS standard to be compatible with both PHPCS 2.x as well as 3.x. - A
PHPCSUtilsstandard which contains generic utilities which can be used when writing sniffs. This standard does not contain any sniffs! To use these utilities in PHPCS 3.x, all that is needed is for this package to be installed and registered with PHPCS usinginstalled_paths. If the package is requested via Composer, this will automatically be handled by the Composer PHPCS plugin. To use these utilities in PHPCS 2.x, make sure the external standard includes thePHPCS23Utilsstandard in theruleset.xmlfile like so:<rule ref="PHPCS23Utils"/>.
All utilities offered are compatible with PHP_CodeSniffer 2.6.0 up to the latest stable release.
This initial alpha release contains the following utility classes:
Abstract Sniffs
AbstractArrayDeclarationSniff: to examine array declarations.
BackCompat
BCFile: Backport of the latest versions of PHPCS native utility functions from thePHP_CodeSniffer\Files\Fileclass to make them available in older PHPCS versions without the bugs and other quirks that the older versions of the native functions had.BCTokens: Backport of the latest versions of PHPCS native token arrays from thePHP_CodeSniffer\Util\Tokensclass to make them available in older PHPCS versions.Helper: Utility methods to retrieve (configuration) information from PHP_CodeSniffer 2.x as well as 3.x.
Fixers
SpacesFixer: Utility to check and, if necessary, fix the whitespace between two tokens.
TestUtils
UtilityMethodTestCase: Base class for use when testing utility methods for PHP_CodeSniffer. Compatible with both PHPCS 2.x as well as 3.x. Supports PHPUnit 4.x up to 8.x. See the usage instructions in the class docblock.
Tokens
Collections: Collections of related tokens as often used and needed for sniffs. These are additional "token groups" to compliment the ones available through the PHPCS nativePHP_CodeSniffer\Util\Tokensclass.
Utils
Arrays: Utility functions for use when examining arrays.Conditions: Utility functions for use when examining token conditions.FunctionDeclarations: Utility functions for use when examining function declaration statements.GetTokensAsString: Utility functions to retrieve the content of a set of tokens as a string.Lists: Utility functions to retrieve information when working with lists.Namespaces: Utility functions for use when examining T_NAMESPACE tokens and to determine the namespace of arbitrary tokens.Numbers: Utility functions for working with integer/float tokens.ObjectDeclarations: Utility functions for use when examining object declaration statements.Operators: Utility functions for use when working with operators.Orthography: Utility functions for checking the orthography of arbitrary text strings.Parentheses: Utility functions for use when examining parenthesis tokens and arbitrary tokens wrapped in parentheses.PassedParameters: Utility functions to retrieve information about parameters passed to function calls, array declarations, isset and unset constructs.Scopes: Utility functions for use when examining token scopes.TextStrings: Utility functions for working with text string tokens.UseStatements: Utility functions for examining use statements.Variables: Utility functions for use when examining variables.
- A