✨ New PHPCSUtils\Utils\AttributeBlock
class
#720
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
... to contain utility methods for analysing attribute blocks, where 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.Initially, the class comes with the following methods:
getAttributes(File $phpcsFile, $stackPtr): array
to retrieve an array of information about each attribute referenced in an attribute block. The returned array will contain the following information on each attribute in the block:name
(string
): the complete name of the attribute as found in the attribute block.name_token
(int
): stack pointer to the last token in the name (which can be passed to the methods in thePassedParameters
class to retrieve any passed arguments).start
(int
): the stack pointer to the first token in the attribute instantiation. Mind: this may be a whitespace (or comment token), like forAnotherAttribute
in the example above.end
(int
): the stack pointer to the last token in the attribute instantiation. Again, mind: this may be a whitespace/comment token.comma_token
(int|false
): the stack pointer to the comma after the attribute instantiation orfalse
if this is the last attribute and there is no comma.countAttributes(File $phpcsFile, $stackPtr): int
: convenience method to count the number of attribute instantiations in an attribute block.These methods expect to be passed a
T_ATTRIBUTE
(attribute block opener) token as the$stackPtr
.Includes extensive unit tests.
Related to #616