PHPCSUtils 1.2.0

AttributeBlock
in package

FinalYes

Utility functions to retrieve information related to attributes.

Tags
since
1.2.0

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
since
1.2.0
throws
TypeError

If the $stackPtr parameter is not an integer.

throws
OutOfBoundsStackPtr

If the token passed does not exist in the $phpcsFile.

throws
UnexpectedTokenType

If the token passed is not an attribute token and not within an attribute.

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
since
1.2.0
throws
TypeError

If the $stackPtr parameter is not an integer.

throws
OutOfBoundsStackPtr

If the token passed does not exist in the $phpcsFile.

throws
UnexpectedTokenType

If the token passed is not a T_ATTRIBUTE token.

Return values
int

getAttributes()

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
since
1.2.0
throws
TypeError

If the $stackPtr parameter is not an integer.

throws
OutOfBoundsStackPtr

If the token passed does not exist in the $phpcsFile.

throws
UnexpectedTokenType

If the token passed is not a T_ATTRIBUTE token.

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.


        
On this page

Search results