ValidVariableNameSniff
extends AbstractVariableSniff
in package
Table of Contents
- $phpReservedVars : array<string|int, mixed>
- List of PHP Reserved variables.
- $ignore : array<string|int, mixed>
- Tokens to ignore so that we can find a DOUBLE_COLON.
- $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 a new AbstractScopeTest.
- process() : void|int
- 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
- Processes class member variables.
- processTokenOutsideScope() : void|int
- Processes a token that is found outside the scope that this test is listening to.
- processTokenWithinScope() : void|int
- Processes a token that is found within the scope that this test is listening to.
- processVariable() : void
- Processes this test, when one of its tokens is encountered.
- processVariableInString() : void
- Processes the variable found within a double quoted string.
Properties
$phpReservedVars
List of PHP Reserved variables.
protected
array<string|int, mixed>
$phpReservedVars
= ['_SERVER' => true, '_GET' => true, '_POST' => true, '_REQUEST' => true, '_SESSION' => true, '_ENV' => true, '_COOKIE' => true, '_FILES' => true, 'GLOBALS' => true, 'http_response_header' => true, 'HTTP_RAW_POST_DATA' => true, 'php_errormsg' => true]
Used by various naming convention sniffs.
$ignore
Tokens to ignore so that we can find a DOUBLE_COLON.
private
array<string|int, mixed>
$ignore
= [T_WHITESPACE, T_COMMENT]
$listenOutside
True if this test should fire on tokens outside of the scope.
private
bool
$listenOutside
= false
$scopeTokens
The type of scope opener tokens that this test wishes to listen to.
private
string
$scopeTokens
= []
$tokens
The token types that this test wishes to listen to within the scope.
private
array<string|int, mixed>
$tokens
= []
Methods
__construct()
Constructs a new AbstractScopeTest.
public
__construct(array<string|int, mixed> $scopeTokens, array<string|int, mixed> $tokens[, bool $listenOutside = false ]) : mixed
Parameters
- $scopeTokens : array<string|int, mixed>
-
The type of scope the test wishes to listen to.
- $tokens : array<string|int, mixed>
-
The tokens that the test wishes to listen to within the scope.
- $listenOutside : bool = false
-
If true this test will also alert the extending class when a token is found outside the scope, by calling the processTokenOutsideScope method.
Tags
Return values
mixed —process()
Processes the tokens that this test is listening for.
public
final process(File $phpcsFile, int $stackPtr) : void|int
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $stackPtr : int
-
The position in the stack where this token was found.
Tags
Return values
void|int —Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return ($phpcsFile->numTokens + 1) to skip the rest of the file.
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()
Processes class member variables.
protected
processMemberVar(File $phpcsFile, int $stackPtr) : void
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the current token in the stack passed in $tokens.
Return values
void —processTokenOutsideScope()
Processes a token that is found outside the scope that this test is listening to.
protected
abstract processTokenOutsideScope(File $phpcsFile, int $stackPtr) : void|int
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $stackPtr : int
-
The position in the stack where this token was found.
Return values
void|int —Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
processTokenWithinScope()
Processes a token that is found within the scope that this test is listening to.
protected
abstract processTokenWithinScope(File $phpcsFile, int $stackPtr, int $currScope) : void|int
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $stackPtr : int
-
The position in the stack where this token was found.
- $currScope : int
-
The position in the tokens array that opened the scope that this test is listening for.
Return values
void|int —Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return ($phpcsFile->numTokens + 1) to skip the rest of the file.
processVariable()
Processes this test, when one of its tokens is encountered.
protected
processVariable(File $phpcsFile, int $stackPtr) : void
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the current token in the stack passed in $tokens.
Return values
void —processVariableInString()
Processes the variable found within a double quoted string.
protected
processVariableInString(File $phpcsFile, int $stackPtr) : void
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the double quoted string.