PHP_CodeSniffer_Standards_AbstractVariableSniff
extends PHP_CodeSniffer_Standards_AbstractScopeSniff
in package
A class to find T_VARIABLE tokens.
This class can distinguish between normal T_VARIABLE tokens, and those tokens that represent class members. If a class member is encountered, then the processMemberVar method is called so the extending class can process it. If the token is found to be a normal T_VARIABLE token, then processVariable is called.
Tags
Table of Contents
- $currentFile : PHP_CodeSniffer_File
- The current PHP_CodeSniffer file that we are processing.
- $_endFunction : int
- The end token of the current function that we are in.
- $_functionOpen : bool
- TRUE if a function is currently open.
- $_listenOutside : bool
- True if this test should fire on tokens outside of the scope.
- $_scopeTokens : string
- The type of scope opener tokens that this test wishes to listen to.
- $_tokens : array<string|int, mixed>
- The token types that this test wishes to listen to within the scope.
- __construct() : mixed
- Constructs an AbstractVariableTest.
- process() : void
- Processes the tokens that this test is listening for.
- register() : array<string|int, int>
- The method that is called to register the tokens this test wishes to listen to.
- processMemberVar() : void
- Called to process class member vars.
- processTokenOutsideScope() : void
- Processes the token outside the scope in the file.
- processTokenWithinScope() : void
- Processes the token in the specified PHP_CodeSniffer_File.
- processVariable() : void
- Called to process normal member vars.
- processVariableInString() : void
- Called to process variables found in double quoted strings or heredocs.
Properties
$currentFile
The current PHP_CodeSniffer file that we are processing.
protected
PHP_CodeSniffer_File
$currentFile
=
ull
$_endFunction
The end token of the current function that we are in.
private
int
$_endFunction
= -1
$_functionOpen
TRUE if a function is currently open.
private
bool
$_functionOpen
= alse
$_listenOutside
True if this test should fire on tokens outside of the scope.
private
bool
$_listenOutside
= alse
$_scopeTokens
The type of scope opener tokens that this test wishes to listen to.
private
string
$_scopeTokens
= array()
$_tokens
The token types that this test wishes to listen to within the scope.
private
array<string|int, mixed>
$_tokens
= array()
Methods
__construct()
Constructs an AbstractVariableTest.
public
__construct() : mixed
Return values
mixed —process()
Processes the tokens that this test is listening for.
public
final process(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : void
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
The file where this token was found.
- $stackPtr : int
-
The position in the stack where this token was found.
Tags
Return values
void —register()
The method that is called to register the tokens this test wishes to listen to.
public
final register() : array<string|int, int>
DO NOT OVERRIDE THIS METHOD. Use the constructor of this class to register for the desired tokens and scope.
Tags
Return values
array<string|int, int> —processMemberVar()
Called to process class member vars.
protected
abstract processMemberVar(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : void
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
The PHP_CodeSniffer file where this token was found.
- $stackPtr : int
-
The position where the token was found.
Return values
void —processTokenOutsideScope()
Processes the token outside the scope in the file.
protected
final processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : void
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
The PHP_CodeSniffer file where this token was found.
- $stackPtr : int
-
The position where the token was found.
Return values
void —processTokenWithinScope()
Processes the token in the specified PHP_CodeSniffer_File.
protected
final processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, int $stackPtr, array<string|int, mixed> $currScope) : void
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
The PHP_CodeSniffer file where this token was found.
- $stackPtr : int
-
The position where the token was found.
- $currScope : array<string|int, mixed>
-
The current scope opener token.
Return values
void —processVariable()
Called to process normal member vars.
protected
abstract processVariable(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : void
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
The PHP_CodeSniffer file where this token was found.
- $stackPtr : int
-
The position where the token was found.
Return values
void —processVariableInString()
Called to process variables found in double quoted strings or heredocs.
protected
abstract processVariableInString(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : void
Note that there may be more than one variable in the string, which will result only in one call for the string or one call per line for heredocs.
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
The PHP_CodeSniffer file where this token was found.
- $stackPtr : int
-
The position where the double quoted string was found.