AbstractArrayDeclarationSniff implements Sniff
Abstract sniff to easily examine all parts of an array declaration.
Table of Contents
| $stackPtr | The stack pointer to the array keyword or the short array open token. | int |
|---|---|---|
| $tokens | The token stack for the current file being examined. | array |
| $arrayOpener | The stack pointer to the array opener. | int |
| $arrayCloser | The stack pointer to the array closer. | int |
| $arrayItems | A multi-dimentional array with information on each array item. | array |
| $itemCount | How many items are in the array. | int |
| $singleLine | Whether or not the array is single line. | bool |
| $acceptedTokens | List of tokens which can safely be used with an eval() expression. | array |
| __construct() | Set up this class. | void |
| register() | Returns an array of tokens this test wants to listen for. | array |
| process() | Processes this test when one of its tokens is encountered. | void |
| processArray() | Process every part of the array declaration. | void |
| processOpenClose() | Process the array opener and closer. | bool|void |
| processKey() | Process the tokens in an array key. | bool|void |
| processNoKey() | Process an array item without an array key. | bool|void |
| processArrow() | Process the double arrow. | bool|void |
| processValue() | Process the tokens in an array value. | bool|void |
| processComma() | Process the comma after an array item. | bool|void |
| getActualArrayKey() | Determine what the actual array key would be. | string|int|void |
Properties
$stackPtr
The stack pointer to the array keyword or the short array open token.
protected
int
$stackPtr
$tokens
The token stack for the current file being examined.
protected
array
$tokens
$arrayOpener
The stack pointer to the array opener.
protected
int
$arrayOpener
$arrayCloser
The stack pointer to the array closer.
protected
int
$arrayCloser
$arrayItems
A multi-dimentional array with information on each array item.
protected
array
$arrayItems
$itemCount
How many items are in the array.
protected
int
$itemCount
= ""
$singleLine
Whether or not the array is single line.
protected
bool
$singleLine
$acceptedTokens
List of tokens which can safely be used with an eval() expression.
private
array
$acceptedTokens
= [\T_NULL => \T_NULL, \T_TRUE => \T_TRUE, \T_FALSE => \T_FALSE, \T_LNUMBER => \T_LNUMBER, \T_DNUMBER => \T_DNUMBER, \T_CONSTANT_ENCAPSED_STRING => \T_CONSTANT_ENCAPSED_STRING, \T_STRING_CONCAT => \T_STRING_CONCAT, \T_INLINE_THEN => \T_INLINE_THEN, \T_INLINE_ELSE => \T_INLINE_ELSE, \T_BOOLEAN_NOT => \T_BOOLEAN_NOT]
Methods
__construct()
Set up this class.
public
final __construct(
)
: void
Tags
register()
Returns an array of tokens this test wants to listen for.
public
register(
)
: array
Tags
Return values
arrayprocess()
Processes this test when one of its tokens is encountered.
public
final process(
$phpcsFile :
File
, $stackPtr :
int
)
: void
This method fills the properties with relevant information for examining the array
and then passes off to the processArray() method.
Parameters
- $phpcsFile : File
The PHP_CodeSniffer file where the token was found.
- $stackPtr : int
The position in the PHP_CodeSniffer file's token stack where the token was found.
Tags
processArray()
Process every part of the array declaration.
public
processArray(
$phpcsFile :
File
)
: void
This contains the default logic for the sniff, but can be overloaded in a concrete child class if needed.
Parameters
- $phpcsFile : File
The PHP_CodeSniffer file where the token was found.
Tags
processOpenClose()
Process the array opener and closer.
public
processOpenClose(
$phpcsFile :
File
, $openPtr :
int
, $closePtr :
int
)
: bool|void
Optional method to be implemented in concrete child classes.
Parameters
- $phpcsFile : File
The PHP_CodeSniffer file where the token was found.
- $openPtr : int
The position of the array opener token in the token stack.
- $closePtr : int
The position of the array closer token in the token stack.
Tags
Return values
bool|void —Returning true will short-circuit the sniff and stop processing.
processKey()
Process the tokens in an array key.
public
processKey(
$phpcsFile :
File
, $startPtr :
int
, $endPtr :
int
, $itemNr :
int
)
: bool|void
Optional method to be implemented in concrete child classes.
The $startPtr and $endPtr do not discount whitespace or comments, but are all inclusive to allow examining all tokens in an array key.
Parameters
- $phpcsFile : File
The PHP_CodeSniffer file where the token was found.
- $startPtr : int
The stack pointer to the first token in the "key" part of an array item.
- $endPtr : int
The stack pointer to the last token in the "key" part of an array item.
- $itemNr : int
Which item in the array is being handled. 1-based, i.e. the first item is item 1, the second 2 etc.
Tags
Return values
bool|void —Returning true will short-circuit the array item loop and stop processing.
processNoKey()
Process an array item without an array key.
public
processNoKey(
$phpcsFile :
File
, $startPtr :
int
, $itemNr :
int
)
: bool|void
Optional method to be implemented in concrete child classes.
Parameters
- $phpcsFile : File
The PHP_CodeSniffer file where the token was found.
- $startPtr : int
The stack pointer to the first token in the array item, which in this case will be the first token of the array value part of the array item.
- $itemNr : int
Which item in the array is being handled. 1-based, i.e. the first item is item 1, the second 2 etc.
Tags
Return values
bool|void —Returning true will short-circuit the array item loop and stop processing.
processArrow()
Process the double arrow.
public
processArrow(
$phpcsFile :
File
, $arrowPtr :
int
, $itemNr :
int
)
: bool|void
Optional method to be implemented in concrete child classes.
Parameters
- $phpcsFile : File
The PHP_CodeSniffer file where the token was found.
- $arrowPtr : int
The stack pointer to the double arrow for the array item.
- $itemNr : int
Which item in the array is being handled. 1-based, i.e. the first item is item 1, the second 2 etc.
Tags
Return values
bool|void —Returning true will short-circuit the array item loop and stop processing.
processValue()
Process the tokens in an array value.
public
processValue(
$phpcsFile :
File
, $startPtr :
int
, $endPtr :
int
, $itemNr :
int
)
: bool|void
Optional method to be implemented in concrete child classes.
The $startPtr and $endPtr do not discount whitespace or comments, but are all inclusive to allow examining all tokens in an array value.
Parameters
- $phpcsFile : File
The PHP_CodeSniffer file where the token was found.
- $startPtr : int
The stack pointer to the first token in the "value" part of an array item.
- $endPtr : int
The stack pointer to the last token in the "value" part of an array item.
- $itemNr : int
Which item in the array is being handled. 1-based, i.e. the first item is item 1, the second 2 etc.
Tags
Return values
bool|void —Returning true will short-circuit the array item loop and stop processing.
processComma()
Process the comma after an array item.
public
processComma(
$phpcsFile :
File
, $commaPtr :
int
, $itemNr :
int
)
: bool|void
Optional method to be implemented in concrete child classes.
Parameters
- $phpcsFile : File
The PHP_CodeSniffer file where the token was found.
- $commaPtr : int
The stack pointer to the comma.
- $itemNr : int
Which item in the array is being handled. 1-based, i.e. the first item is item 1, the second 2 etc.
Tags
Return values
bool|void —Returning true will short-circuit the array item loop and stop processing.
getActualArrayKey()
Determine what the actual array key would be.
public
getActualArrayKey(
$phpcsFile :
File
, $startPtr :
int
, $endPtr :
int
)
: string|int|void
Optional helper function for processsing array keys in the processKey() function.
Parameters
- $phpcsFile : File
The PHP_CodeSniffer file where the token was found.
- $startPtr : int
The stack pointer to the first token in the "key" part of an array item.
- $endPtr : int
The stack pointer to the last token in the "key" part of an array item.
Tags
Return values
string|int|void —The string or integer array key or void if the array key could not reliably be determined.