AttributeBlock
in package
Utility functions to retrieve information related to attributes.
Tags
Table of Contents
Methods
- appliesTo() : int|false
- Given an attribute opener, find the relevant construct token the attribute applies to.
- countAttributes() : int
- Count the number of attributes being instantiated in an attribute block.
- getAttributes() : array<string|int, array<string, int|string|false>>
- Retrieve information on each attribute instantiation within an attribute block.
Methods
appliesTo()
Given an attribute opener, find the relevant construct token the attribute applies to.
public
static appliesTo(File $phpcsFile, int $stackPtr) : int|false
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the T_ATTRIBUTE (attribute opener) token.
Tags
Return values
int|false —The stackPtr to the OO, function, closure, fn, constant, or variable token the attribute block applies to; or FALSE if the attribute target could not be determined.
countAttributes()
Count the number of attributes being instantiated in an attribute block.
public
static countAttributes(File $phpcsFile, int $stackPtr) : int
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the T_ATTRIBUTE (attribute opener) token.
Tags
Return values
intgetAttributes()
Retrieve information on each attribute instantiation within an attribute block.
public
static getAttributes(File $phpcsFile, int $stackPtr) : array<string|int, array<string, int|string|false>>
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the T_ATTRIBUTE (attribute opener) token.
Tags
Return values
array<string|int, array<string, int|string|false>> —A multi-dimentional array with information on each attribute instantiation in the block. The information gathered about each attribute instantiation is in the following format:
array(
'name' => string, // The full name of the attribute being instantiated.
// This will be name as passed without namespace resolution.
'name_token' => int, // The stack pointer to the last token in the attribute name.
// Pro-tip: this token can be passed on to the methods in the
// <a href="classes/PHPCSUtils-Utils-PassedParameters.html"><abbr title="\PHPCSUtils\Utils\PassedParameters">PassedParameters</abbr></a> class to retrieve the
// parameters passed to the attribute constructor.
'start' => int, // The stack pointer to the first token in the attribute instantiation.
// Note: this may be a leading whitespace/comment token.
'end' => int, // The stack pointer to the last token in the attribute instantiation.
// Note: this may be a trailing whitespace/comment token.
'comma_token' => int|false, // The stack pointer to the comma after the attribute instantiation
// or FALSE if this is the last attribute and there is no comma.
)
If no attributes are found, an empty array will be returned.