A suite of utility functions for use with PHP_CodeSniffer.
Latest release: 1.1.0
View Changelog
All notable changes to this project will be documented in this file.
This projects adheres to Keep a CHANGELOG and uses Semantic Versioning.
Compatibility with the new PHP_CodeSniffer 4.x
branch 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.
BCFile::findExtendedClassName()
: sync with PHPCS 4.0.0 - support for namespace relative names when used as the extended parent class name. #674
BCFile::findImplementedInterfaceNames()
: sync with PHPCS 4.0.0 - support for namespace relative names when used in implemented interface names. #674
BCFile::getMemberProperties()
: sync with PHPCS 3.12.0 - support for PHP 8.4 final properties. Thanks @DanielEScherzer! #646
BCFile::getMemberProperties()
: sync with PHPCS 3.13.1 - support for PHP 8.4 asymmetric visibility. #677
BCFile::getMemberProperties()
: sync with PHPCS 4.0.0. #674
BCFile::getMethodParameters()
: sync with PHPCS 3.13.1 - support for PHP 8.4 asymmetric visibility. #677
BCFile::findStartOfStatement()
: sync with PHPCS 3.12.1 - support for goto
as a switch
- case
terminating statement. #661
BCTokens::nameTokens()
as introduced in PHPCS 4.0.0. #674
The same token array previously already existed in PHPCSUtils as Collections::nameTokens()
.BCTokens::functionNameTokens()
: sync with PHPCS 4.0.0 - added the T_ANON_CLASS
token. #674
BCTokens::parenthesisOpeners()
: sync with PHPCS 4.0.0 - added the T_USE
, T_ISSET
, T_UNSET
, T_EMPTY
, T_EVAL
and T_EXIT
tokens. #674
Note: While T_USE
, T_ISSET
, T_UNSET
, T_EMPTY
, T_EVAL
and T_EXIT
will 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()
or the Parentheses::hasOwner()
methods if you need to check
whether any of these tokens are a parentheses owner. The methods in the Parentheses
class are PHPCS cross-version compatible.PHPCSUtils\TestUtils\ConfigDouble
class as a lightweight and more stable alternative to directly using the PHPCS native Config
class in tests. #550, #612
Props to @fredden for helping me find and fix a bug in this feature before it was released.PHPCSUtils\TestUtils\RulesetDouble
class which allows for creating a Ruleset
object without registering any sniffs. #674
This allows for the PHPCSUtils\TestUtils\UtilityMethodTestCase
class to be cross-version compatible with both PHP_CodeSniffer 3.x as well as 4.x.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 $fileName
property on seeing another file.PHPCSUtils\TestUtils\UtilityMethodTestCase::testTestMarkersAreUnique()
and PHPCSUtils\TestUtils\UtilityMethodTestCase::assertTestMarkersAreUnique()
methods which automatically check that code sample files used with this TestCase
do 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.Collections::constantTypeTokens()
method to support PHP 8.3 typed class constants. #562
Collections::ternaryOperators()
method. #549
T_EXIT
to the Collections::functionCallTokens()
and Collections::parameterPassingTokens()
in light of the PHP 8.4 “exit as function” change. #618
Collections::propertyModifierKeywords()
method. #653
T_INTERFACE
has been added to the Collections::ooPropertyScopes()
method for PHP 8.4 interface properties support. #674
PHPCSUtils\Utils\Constants
class: Utility functions to examine (class) constants. #562
Initially available method: getProperties()
to retrieve an array of information about an OO constant declaration.PHPCSUtils\Utils\FileInfo
class: Utility functions to check characteristics of the file under scan. #572
Initial set of available methods: hasByteOrderMark()
and hasSheBang()
.PHPCSUtils\Utils\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()
and startsWith()
.PHPCSUtils\Utils\TypeString
class: Utility functions for analysing typestrings as retrieved via the various available getParameters()
/getProperties()
methods. #588
Initial set of available methods: getKeywordTypes()
, isKeyword()
, normalizeCase()
, isSingular()
, isNullable()
, isUnion()
, isIntersection()
, isDNF()
, toArray()
, toArrayUnique()
, filterKeywordTypes()
and filterOOTypes()
.
Note: The is*()
methods will not check if the type string provided is valid, as doing so would inhibit what sniffs can flag. The is*()
methods will only look at the form of the type string to determine if it could be valid for a certain type.PHPCSUtils\Utils\ObjectDeclarations::getDeclaredConstants()
, PHPCSUtils\Utils\ObjectDeclarations::getDeclaredEnumCases()
, PHPCSUtils\Utils\ObjectDeclarations::getDeclaredProperties()
and PHPCSUtils\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 the getDeclaredProperties()
method includes constructor promoted properties. Passing the stack pointer of constructor promoted properties onto a call to the Variables::getMemberProperties()
method, however, is currently not supported.FunctionDeclarations::getParameters()
: support for PHP 8.4 asymmetric visibility. #677
Variables::getMemberProperties()
: support for PHP 8.4 final properties. Thanks @DanielEScherzer! #646
Variables::getMemberProperties()
: support for PHP 8.4 asymmetric visibility. #677
PHPCSUtils\Exceptions\TypeError
being thrown.PHPCSUtils\Exceptions\ValueError
being thrown.PHPCSUtils\Exceptions\OutOfBoundsStackPtr
being thrown.PHPCSUtils\Exceptions\UnexpectedTokenType
being thrown.PHPCSUtils\Exceptions\LogicException
being thrown.
This can occur, for instance, when a method takes a $start
and $end
parameter and the $end
pointer is before the $start
pointer.PHPCSUtils\Exceptions\MissingArgumentError
being thrown.PHPCSUtils\Exceptions\RuntimeException
being thrown.PHP_CodeSniffer\Exceptions\RuntimeException
was used for all these exceptions.
Catching the PHPCS native RuntimeException
will still catch the new exceptions, but it is strongly recommended to be more selective when catching exceptions to prevent accidentally hiding errors in sniffs.AbstractArrayDeclarationSniff::process()
method will no longer hide exceptions about a non-integer or non-existent stack pointer being passed. #600
AbstractArrayDeclarationSniff::processArray()
method will no longer hide exceptions about non-integer or non-existent stack pointers being passed. #600
BCFile::getDeclarationName()
: sync with PHPCS 3.12.0 - prevent incorrect result during live coding for unfinished closures. #644
BCFile::getDeclarationName()
: sync with PHPCS 4.0.0 - no longer accept the T_CLOSURE
or T_ANON_CLASS
tokens. #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 return null
when the name could not be determined. Now it will return an empty string.PHPCSUtils\TestUtils\UtilityMethodTestCase
is now officially compatible with PHPUnit 11 and will no longer generate any deprecation notices on PHPUnit 11.Parentheses
: all methods will now recognize closer use()
as a parentheses owner. #674
Note: PHPCS natively does not recognize closure use
as a parentheses owners until PHP_CodeSniffer 4.0.PassedParameters
class will now be able to analyze exit/die when used as a function call. #618
Scopes::isOOProperty()
method now allows for PHP 8.4 properties in interfaces. #674
Variables::getMemberProperties()
method.UseStatements::splitAndMergeImportUseStatement()
method will no longer hide exceptions about a non-integer, non-existent or non-T_USE
stack pointer being passed. #600
composer update phpcsstandards/phpcsutils --with-dependencies
to benefit from this.PHPCSUtils\TestUtils\UtilityMethodTestCase::setStaticConfigProperty()
method. #550
This method has become redundant with the introduction of the ConfigDouble
class.T_ZSR_EQUAL
token from the BCTokens::assignmentTokens()
array, as per PHPCS 4.0.0. #674
T_OBJECT
token from the BCTokens::blockOpeners()
array, as per PHPCS 4.0.0. #674
T_PROPERTY
and T_OBJECT
tokens from the BCTokens::blockOpeners()
array, as per PHPCS 4.0.0. #674
AbstractArrayDeclarationSniff::getActualArrayKey()
: will now handle FQN true
/false
/null
correctly. #668
Context::inForeachCondition()
could misidentify the as
keyword for foreach
when the iterable expression contained an array declaration in which the as
keyword was being used. #617
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 closure use
statements (parse errors) more consistently and return 'closure'
for those cases. #667
BCFile::getMemberProperties()
: sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. #604
BCFile::getMethodProperties()
: sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. #604
BCFile::getMethodParameters()
: sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. #604
FunctionDeclarations::getParameters()
: support for PHP 8.2 DNF types. #604
FunctionDeclarations::getProperties()
: support for PHP 8.2 DNF types. #604
Variables::getMemberProperties()
: support for PHP 8.2 DNF types. #604
Collections::parameterTypeTokens()
, Collections::propertyTypeTokens()
and Collections::returnTypeTokens()
: now include the new T_TYPE_OPEN_PARENTHESIS
and T_TYPE_CLOSE_PARENTHESIS
tokens for PHP 8.2 DNF type support. #604
ControlStructures::getCaughtExceptions()
: will now silently ignore parse errors in the code under scan which prevent the method from analyzing a catch
statement. #594
The method will now return an empty array instead of throwing a PHP_CodeSniffer\Exceptions\RuntimeException
.composer update phpcsstandards/phpcsutils --with-dependencies
to benefit from this.UseStatements::splitImportUseStatement()
: the values in the return array will now never include a leading backslash. #590
Previously the behaviour around import use
statements declared with a leading backslash was undefined and the backslash would be included in the return value.BCFile::getMethodProperties()
: small performance improvement & more defensive coding, in line with same fix in PHPCS 3.9.2. #573
FunctionDeclarations::getProperties()
: small performance improvement & more defensive coding, in line with same fix in PHPCS 3.9.2. #573
composer update phpcsstandards/phpcsutils --with-dependencies
to benefit from this.BackCompat\Helper::getEncoding()
: PHP 8.4 deprecation notice. #568
BackCompat\Helper::ignoreAnnotations()
: PHP 8.4 deprecation notice. #568
BCFile::getMemberProperties()
: sync with PHPCS 3.8.0 - support for PHP 8.2 true
type. #524
BCFile::getMethodProperties()
: sync with PHPCS 3.8.0 - support for PHP 8.2 true
type. #524
BCFile::getMethodParameters()
: sync with PHPCS 3.8.0 - support for PHP 8.2 true
type. #524
UtilityMethodTestCase
. #525
composer update phpcsstandards/phpcsutils --with-dependencies
to benefit from this.BCFile::getDeclarationName()
: sync with PHPCS 3.8.0 - support for functions called self
, parent
or static
which return by reference. #494
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
Arrays::getDoubleArrowPtr()
method could previously get confused over a double arrow in a keyed list used as an array value. #485
BCFile::getClassProperties()
: sync with PHPCS 3.8.0 - support for PHP 8.2 readonly
classes. #470
BCFile::getMethodParameters()
: sync with PHPCS 3.8.0 - support for constructor property promotion with readonly
properties without explicit visibility. #472
FunctionDeclarations::getProperties()
Variables::getMemberProperties()
UseStatements::splitImportUseStatement()
method will be cached more often and the cache checked earlier. #467
ControlStructures::getCaughtExceptions()
method will no longer contain “empty” entries for catch statements without a named exception. It will return an empty array instead. #474
AbstractArrayDeclarationSniff
: fixed a potential “Trying to access array offset on value of type bool” PHP notice. #476
AbstractArrayDeclarationSniff
: the abstract will no longer trigger potentially available magic __get()
/__set()
etc methods. #477
Lists::getAssignments()
method could previously get confused over exotic list keys. Fixed now. #459
FunctionDeclarations::getParameters()
method will now correctly handle constructor promoted properties with readonly
, but without explicit visibility set. #456
PassedParameters
class now allows for function calls to global functions called self()
, parent()
or static()
. #452
Collections::arrayOpenTokensBC()
, Collections::arrayTokensBC()
, Collections::listOpenTokensBC()
, Collections::listTokensBC()
, Collections::shortArrayListOpenTokensBC()
, Collections::shortArrayTokensBC()
and Collections::shortListTokensBC()
token arrays will no longer contain the T_OPEN_SQUARE_BRACKET
and/or the T_CLOSE_SQUARE_BRACKET
token 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 the Arrays
/Lists
classes, should experience a performance boost on PHPCS 3.7.2+ due to this change.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.composer update phpcsstandards/phpcsutils --with-dependencies
to benefit from this.For the full list of features, please see the changelogs of the alpha/rc releases:
Collections::constantModifierKeywords()
method. #400
Collections::listOpenTokensBC()
method. #405
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 to false
. #401
Everything which was previously deprecated in the 1.0.0-alpha4 release, has now been removed. #410
This includes:
PHPCS23Utils
standard.Collections
class: direct access to the properties in the class.Collections
class: the Collections::arrowFunctionTokensBC()
, Collections::functionDeclarationTokensBC()
, Collections::parameterTypeTokensBC()
, Collections::propertyTypeTokensBC()
and Collections::returnTypeTokensBC()
methods.ControlStructures::getDeclareScopeOpenClose()
method.FunctionDeclarations::getArrowFunctionOpenClose()
method.FunctionDeclarations::isArrowFunction()
method.See the changelog for the 1.0.0-alpha4 release for details about replacements for the removed functionality.
Arrays::getOpenClose()
: small efficiency fix. #406
ControlStructures::hasBody()
: correctly identify that a control structure does not have a body - 'has_body' = false
-, when the control structure is ended by a PHP close tag. #403
Lists::getOpenClose()
: small efficiency fix. #407
Notes:
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.
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):
mixed
type. #163
false
and null
types. #168, #225
use
lists.Please report any bugs/oversights you encounter!
BCTokens::magicConstants()
as introduced in PHPCS 3.5.6. #172
The same token array previously already existed in PHPCSUtils as Collections::$magicConstants
(which has now been deprecated).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
PHPCSUtils\Tokens\TokenHelper
class: Utility functions for working with tokens and token collections. #304
This class initially contains a tokenExists()
method to work around potential interference from PHP-Parser also backfilling tokens.
defined()
to determine whether a token is available should replace those with a function call to the TokenHelper::tokenExists()
method.Collections::arrayOpenTokensBC()
method. #233, #311
Collections::functionCallTokens()
method to retrieve the tokens which can represent function calls and function-call-like language constructs, like class instantiations. #233
Collections::nameTokens()
method to retrieve the tokens which can be used for “names”, be it namespace, OO, function or constant names. #204, #217
Collections::namespacedNameTokens()
method to retrieve the tokens which can be encountered in a fully, partially or unqualified name and in namespace relative names. #202, #217
Collections::parameterPassingTokens()
method to retrieve the tokens which can be passed to the methods in the PassedParameters
class. #233
Collections::phpOpenTags()
method. #254
Collections::shortArrayListOpenTokensBC()
method. #381
PHPCSUtils\Utils\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()
and inForCondition()
.PHPCSUtils\Utils\MessageHelper
class: Utility functions for creating error/warning messages. #249, #391
Initial set of available methods: addMessage()
, addFixableMessage()
, stringToErrorcode()
and showEscapeChars()
.PHPCSUtils\Utils\PassedParameters::getParameterFromStack()
efficiency method to retrieve a potentially named function call parameter from a parameter information stack as previously retrieved via PassedParameters::getParameters()
. #235, #237, #383
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 the TextStrings::getCompleteTextString()
method which will retrieve the contents of the complete text string.PHPCSUtils\Utils\TextStrings::getEmbeds()
method to retrieve an array with all variables/expressions as embedded in a text string. #321
PHPCSUtils\Utils\TextStrings::stripEmbeds()
method to strip all embedded variables/expressions from a text string. #321
PHPCSUtils\Utils\TextStrings::getStripEmbeds()
method. #321
This method is public
for those rare cases where both the embeds, as well as the text stripped off embeds, is needed.PHPCSUtils\Utils\UseStatements::mergeImportUseStatements()
method. #196
Arrays::getDoubleArrowPtr()
Arrays::isShortArray()
FunctionDeclarations::getParameters()
Lists::getAssignments()
Lists::isShortList()
Namespaces::findNamespacePtr()
PassedParameters::getParameters()
TextStrings::getEndOfCompleteTextString()
TextStrings::getStripEmbeds()
UseStatements::splitImportUseStatement()
BCTokens
class are fully up-to-date with the upstream PHP_CodeSniffer\Util\Tokens
properties as per PHPCS master
at the time of this release. #327, #347, #360
BCFile
class are fully up-to-date with the upstream PHP_CodeSniffer\Files\File
methods as per PHPCS master
at the time of this release. #347
BCFile::getMethodParameters()
: forward compatibility with PHPCS 4.x in which closure use
will be a parenthesis owner. #251
BCTokens
class, a PHPCSUtils\Exceptions\InvalidTokenArray
exception will be thrown. #344
The PHPCSUtils\Exceptions\InvalidTokenArray
exception extends the PHPCS native PHP_CodeSniffer\Exceptions\RuntimeException
.
Previously, an empty array would be returned.UtilityMethodTestCase
: all properties contained in the test case class will now always be reset after the tests have run. #325
UtilityMethodTestCase::getTargetToken()
: when the target token cannot be found, the method will now throw a (catchable) PHPCSUtils\Exceptions\TestTargetNotFound
exception 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 now static
, which allows for it to be used in “set up before class” fixtures. #382. #385
Collections::functionCallTokens()
and Collections::parameterPassingTokens()
: now include the T_PARENT
token. #328
This accounts for a change in PHPCS 3.7.0 for how parent
in new parent
is tokenized.Collections
class, a PHPCSUtils\Exceptions\InvalidTokenArray
exception will be thrown. #349
The PHPCSUtils\Exceptions\InvalidTokenArray
exception extends the PHPCS native PHP_CodeSniffer\Exceptions\RuntimeException
.Arrays::isShortArray()
/Lists::isShortList()
: the underlying logic has been completely refactored for improved accuracy and improved performance. #392
FunctionDeclarations::getParameters()
: the return array of the method may contain two new keys - property_visibility
and visibility_token
. #169
These keys will only be included if constructor property promotion is detected.FunctionDeclarations::getParameters()
: forward compatibility with PHPCS 4.x in which closure use
will be a parenthesis owner. #251
GetTokensAsString
: previously the tabReplaced()
method was an alias for the normal()
method. This has now been reversed. #297
Operators::isReference()
: forward compatibility with PHPCS 4.x in which closure use
will be a parenthesis owner. #195
Parentheses
: all methods will now recognize isset()
, unset()
, empty()
, exit()
, die()
and eval()
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 $limit
to 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 $isShortArray
to 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 $paramNames
parameter to allow for retrieving a parameter from a function call using named parameters. #235
$paramNames
parameter 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, #262
PassedParameters::hasParameters()
: now allows for the T_PARENT
token for new parent()
class instantiations. #328
This accounts for a change in PHPCS 3.7.0 regarding how parent
in new parent
is tokenized.PassedParameters::hasParameters()
: new, optional parameter $isShortArray
to 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 closure use
will be a parenthesis owner. #251
master
branch has been renamed to stable
. #397
abstract
classes in this package are now final
. #376
Everything which has currently been deprecated, will be removed before the final
1.0.0
version of PHPCSUtils is tagged.
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::$alternativeControlStructureSyntaxTokens |
Collections::alternativeControlStructureSyntaxes() |
#311 | Mind the change in the name! |
Collections::$alternativeControlStructureSyntaxCloserTokens |
Collections::alternativeControlStructureSyntaxClosers() |
#311 | Mind the change in the name! |
Collections::$arrayTokens |
Collections::arrayTokens() |
#311 | |
Collections::$arrayTokensBC |
Collections::arrayTokensBC() |
#311 | |
Collections::$classModifierKeywords |
Collections::classModifierKeywords() |
#311 | |
Collections::$closedScopes |
Collections::closedScopes() |
#311 | |
Collections::$controlStructureTokens |
Collections::controlStructureTokens() |
#311 | |
Collections::$incrementDecrementOperators |
Collections::incrementDecrementOperators() |
#311 | |
Collections::$listTokens |
Collections::listTokens() |
#311 | |
Collections::$listTokensBC |
Collections::listTokensBC() |
#311 | |
Collections::$magicConstants |
PHPCSUtils\BackCompat\BCTokens::magicConstants() or PHP_CodeSniffer\Util\Tokens::$magicConstants
|
#311 | |
Collections::$namespaceDeclarationClosers |
Collections::namespaceDeclarationClosers() |
#311 | |
Collections::$objectOperators |
Collections::objectOperators() |
#176 | |
Collections::$OOCanImplement |
Collections::ooCanImplement() |
#311 | Mind the case change in the oo prefix! |
Collections::$OOCanExtend |
Collections::ooCanExtend() |
#311 | Mind the case change in the oo prefix! |
Collections::$OOConstantScopes |
Collections::ooConstantScopes() |
#311 | Mind the case change in the oo prefix! |
Collections::$OOPropertyScopes |
Collections::ooPropertyScopes() |
#311 | Mind the case change in the oo prefix! |
Collections::$OOHierarchyKeywords |
Collections::ooHierarchyKeywords() |
#311 | Mind the case change in the oo prefix! |
Collections::$OONameTokens |
Collections::namespacedNameTokens() |
#202 | Mind the change name! |
Collections::$parameterTypeTokens |
Collections::parameterTypeTokens() |
#168 | |
Collections::$propertyModifierKeywords |
Collections::propertyModifierKeywords() |
#311 | |
Collections::$propertyTypeTokens |
Collections::propertyTypeTokens() |
#168 | |
Collections::$returnTypeTokens |
Collections::returnTypeTokens() |
#168 | |
Collections::$shortArrayTokens |
Collections::shortArrayTokens() |
#311 | |
Collections::$shortArrayTokensBC |
Collections::shortArrayTokensBC() |
#311 | |
Collections::$shortListTokens |
Collections::shortListTokens() |
#311 | |
Collections::$shortListTokensBC |
Collections::shortListTokensBC() |
#311 | |
Collections::$textStingStartTokens |
Collections::textStringStartTokens() |
#311, #319 | Mind the fixed typo in the name! |
Additionally, the following methods in the Collections
class have been deprecated:
Deprecated | Replacement | PR |
---|---|---|
Collections::arrowFunctionTokensBC() |
Use the T_FN token instead. |
#347 |
Collections::functionDeclarationTokensBC() |
Collections::functionDeclarationTokens() |
#347 |
Collections::parameterTypeTokensBC() |
Collections::parameterTypeTokens() |
#347 |
Collections::propertyTypeTokensBC() |
Collections::propertyTypeTokens() |
#347 |
Collections::returnTypeTokensBC() |
Collections::returnTypeTokens() |
#347 |
ControlStructures::getDeclareScopeOpenClose()
: this method is no longer needed, check the scope_opener
/scope_closer
on the T_DECLARE
token instead. #347
FunctionDeclarations::getArrowFunctionOpenClose()
: this method is no longer needed, check the scope_opener
/scope_closer
etc on the T_FN
token instead. #347
FunctionDeclarations::isArrowFunction()
: this method is no longer needed, use the T_FN
token instead. #347
PHPCS23Utils
standard, which is no longer needed now support for PHPCS < 3.7.1 has been dropped. #347
PHPCSUtils\Utils\Numbers::REGEX_NUMLIT_STRING
PHPCSUtils\Utils\Numbers::REGEX_HEX_NUMLIT_STRING
PHPCSUtils\Utils\Numbers::UNSUPPORTED_PHPCS_VERSION
AbstractArrayDeclarationSniff::getActualArrayKey()
: will now handle escaped vars in heredoc array keys better. #379
SpacesFixer
: in a specific new line vs trailing comment situation, the fixer would incorrectly add a stray new line. #229
UtilityMethodTestCase::getTargetToken()
: will now throw a PHPCSUtils\Exceptions\TestMarkerNotFound
exception if the provided test marker comment is not found. #273, #372
This prevents the method potentially misidentifying the target token.Collections::parameterTypeTokens()
, Collections::propertyTypeTokens()
and Collections::returnTypeTokens()
: include the namespace
keyword for namespace relative identifier names. #180
Arrays::isShortArray()
/Lists::isShortList()
: fixed a number of bugs which previously resulted in an incorrect short list/short array determination. #392
FunctionDeclarations::getParameters()
: will now correctly recognize namespace relative names when used in a parameter type. #180
FunctionDeclarations::getProperties()
: will now correctly recognize namespace relative names when used in the return type. #180
ObjectDeclarations::findExtendedClassName()
: will now correctly recognize namespace relative names when used as the extended parent class name. #181
ObjectDeclarations::findExtendedInterfaceNames()
: will now correctly recognize namespace relative names when used in extended interface names. #181
ObjectDeclarations::findImplementedInterfaceNames()
: will now correctly recognize namespace relative names when used in implemented interface names. #181
ObjectDeclarations::getClassProperties()
: will now correctly handle classes declared with both the final
as well as the abstract
keyword. #252
Operators::isReference()
: if one parameter in a function declaration was passed by reference, then all T_BITWISE_AND
(not intersection type &
’s) tokens would be regarded as references. #188
Operators::isReference()
: the &
would not be recognized as a reference for arrow function parameters passed by reference. #192
Operators::isUnaryPlusMinus()
: a preceding exit
, break
, continue
or arrow function =>
is now recognized as an indicator that a plus/minus sign is unary. #187, #197
Variables::getMemberProperties()
: will now correctly recognize namespace relative names when used in a property type. #180
Notes:
PHPCSUtils\Utils\NamingConventions
class: Utility functions for working with identifier names (namespace names, class/trait/interface names, function names, variable and constant names). #119
PHPCSUtils\BackCompat\Helper::getEncoding()
method. #118
PHPCSUtils\Utils\ControlStructures::getCaughtExceptions()
method. #114, #138
PHPCSUtils\Utils\UseStatements::splitAndMergeImportUseStatement()
method. #117
BCFile::getMethodProperties()
: support for “static” as a return type (PHP 8.0). #134, PHPCS#2952
UtilityMethodTestCase
: new public $phpcsVersion
property 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 the setUpBeforeClass()
-like methods which set the property.Collections::$incrementDecrementOperators
property. #130
Collections::$magicConstants
property. #106
Collections::$objectOperators
property. #130
Collections::$OOHierarchyKeywords
property representing the keywords to access properties or methods from inside a class definition, i.e self
, parent
and static
. #115
Collections::$OONameTokens
property containing tokens which can be part of a partially/fully qualified name when used in inline code. #113
Collections::functionDeclarationTokens()
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.Collections::functionDeclarationTokensBC()
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.Collections::parameterTypeTokensBC()
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.Collections::propertyTypeTokensBC()
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.Collections::returnTypeTokensBC()
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
FunctionDeclarations::getProperties()
: support for “static” as a return type (PHP 8.0). #134
BCFile::getDeclarationName()
: has been made compatible with PHPCS 4.x. #110
BCFile::getMethodProperties()
: has been made compatible with PHPCS 4.x. #109
BCFile::getMemberProperties()
: has been made compatible with PHPCS 4.x. #109
BCTokens
: BCTokens::$phpcsCommentTokensTypes
, BCTokens::$ooScopeTokens
, BCTokens::$textStringTokens
properties has changed from protected
to private
. #139
Helper::setConfigData()
: has been made compatible with PHPCS 4.x. #137
A new $config
parameter has been added to the method. This parameter is a required parameter when the method is used with PHPCS 4.x.UtilityMethodTestCase
: tests for JS/CSS will now automatically be skipped when run in combination with PHPCS 4.x (which drops JS/CSS support). #111
Collections::$parameterTypeTokens
: has been made compatible with PHPCS 4.x. #109
Collections::parameterTypeTokensBC()
method instead if PHPCS < 3.3.0 needs to be supported.Collections::$propertyTypeTokens
: has been made compatible with PHPCS 4.x. #109
Collections::propertyTypeTokensBC()
method instead if PHPCS < 3.3.0 needs to be supported.Collections::$returnTypeTokens
: has been made compatible with PHPCS 4.x. #109
Collections::returnTypeTokensBC()
method instead if PHPCS < 3.5.4 needs to be supported.FunctionDeclarations::getArrowFunctionOpenClose()
: has been made compatible with PHPCS 4.x. #109
FunctionDeclarations::getProperties()
: has been made compatible with PHPCS 4.x. #109
Lists::getAssignments()
: the return value of the method has been consolidated to be less fiddly to work with. #129
nested_list
index key in the return value has been renamed to is_nested_list
.ObjectDeclarations::getName()
: has been made compatible with PHPCS 4.x. #110
Variables::getMemberProperties()
: has been made compatible with PHPCS 4.x. #109
4.0.x-dev@dev
for testing purposes.AbstractArrayDeclarationSniff
: improved parse error handling. #99
BCFile::findEndOfStatement()
: now supports arrow functions when used as a function argument, in line with the same change made in PHPCS 3.5.5. #143
BcFile::isReference()
: bug fix, the reference operator was not recognized as such for closures declared to return by reference. #160, PHPCS#2977
FunctionDeclarations::getArrowFunctionOpenClose()
: now supports arrow functions when used as a function argument, in line with the same change made in PHPCS 3.5.5. #143
FunctionDeclarations::getArrowFunctionOpenClose()
: now supports for arrow functions returning heredoc/nowdocs, in line with the same change made in PHPCS master
and expected to be released in PHPCS 3.5.6. #143
FunctionDeclarations::getName()
: bug fix for functions declared to return by reference. #131
FunctionDeclarations::isMagicFunction()
: bug fix for nested functions. #127
Operators::isReference()
: bug fix, the reference operator was not recognized as such for closures declared to return by reference. #142
Namespaces::getType()
: improved type detection for when the namespace
keyword is used as an operator in the global namespace. #132
TextStrings::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.Note:
PHPCSUtils\Utils\ControlStructures
class: Utility functions for use when examining control structures. #70
PHPCSUtils\Utils\FunctionDeclarations::isArrowFunction()
method. #77, #79
PHPCSUtils\Utils\FunctionDeclarations::getArrowFunctionOpenClose()
method. #77, #79
BCFile::isReference()
: support for arrow functions returning by reference. #77
BCFile::getMethodParameters()
: support for arrow functions. #77, #79
BCFile::getMethodProperties()
: support for arrow functions. #77, #79, #89
BCFile::getDeclarationName()
: allow functions to be called “fn”. #77
BCFile::findEndOfStatement()
: support for arrow functions. #77, #79
BCFile::findStartOfStatement()
: support for arrow functions. #77
Collections::$alternativeControlStructureSyntaxTokens
property. #70
Collections::$alternativeControlStructureSyntaxCloserTokens
property. #68, #69
Collections::$controlStructureTokens
property. #70
Collections::arrowFunctionTokensBC()
method. #79
Arrays::getDoubleArrowPtr()
: support for arrow functions. #77, #79, #84
FunctionDeclarations::getParameters()
: support for arrow functions. #77, #79
FunctionDeclarations::getProperties()
: support for arrow functions. #77, #79
Operators::isReference()
: support for arrow functions returning by reference. #77
Parentheses::getOwner()
: support for arrow functions. #77
Parentheses::isOwnerIn()
: support for arrow functions. #77, #79
BCFile::getCondition()
: sync with PHPCS 3.5.4 - added support for new $first
parameter. #73
Collections::$returnTypeTokens
property now includes T_ARRAY
to allow for supporting arrow functions in PHPCS < 3.5.3. #77
Conditions::getCondition()
: sync with PHPCS 3.5.4 - renamed the existing $reverse
parameter to $first
and reversing the meaning of the boolean values, to stay in line with PHPCS itself. #73
Numbers
: the $unsupportedPHPCSVersions
property has been replaced with an UNSUPPORTED_PHPCS_VERSION
constant. #88
Initial alpha release containing:
PHPCS23Utils
standard which can be used to allow an external PHPCS standard to be compatible with both PHPCS 2.x as well as 3.x.PHPCSUtils
standard 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 using installed_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 the PHPCS23Utils
standard in the ruleset.xml
file 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:
AbstractArrayDeclarationSniff
: to examine array declarations.BCFile
: Backport of the latest versions of PHPCS native utility functions from the PHP_CodeSniffer\Files\File
class 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 the PHP_CodeSniffer\Util\Tokens
class 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.SpacesFixer
: Utility to check and, if necessary, fix the whitespace between two tokens.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.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 native PHP_CodeSniffer\Util\Tokens
class.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.