ValidVariableNameSniff
extends AbstractVariableSniff
in package
Checks the naming of variables and member variables.
Tags
Table of Contents
Properties
- $allowed_custom_properties : array<string|int, string>
- Custom list of properties which can have mixed case.
- $addedCustomProperties : array<string|int, mixed>
- Cache of previously added custom functions.
- $allowed_mixed_case_member_var_names : array<string|int, mixed>
- List of member variables that can have mixed case.
- $phpReservedVars : array<string|int, mixed>
- List of PHP Reserved variables.
- $wordpress_mixed_case_vars : array<string|int, mixed>
- Mixed-case variables used by WordPress.
Methods
- __construct() : mixed
- Constructs an AbstractVariableTest.
- process() : void|int
- Processes the tokens that this test is listening for.
- register() : array<string|int, int|string>
- The method that is called to register the tokens this test wishes to listen to.
- merge_allow_lists() : void
- Merge a custom allow list provided via a custom ruleset with the predefined allow list, if we haven't already.
- processMemberVar() : void
- Processes class member variables.
- processTokenOutsideScope() : void|int
- Processes the token outside the scope in the file.
- processTokenWithinScope() : void|int
- Processes the token in the specified PHP_CodeSniffer\Files\File.
- processVariable() : void
- Processes this test, when one of its tokens is encountered.
- processVariableInString() : void
- Processes the variables found within a double quoted string.
Properties
$allowed_custom_properties
Custom list of properties which can have mixed case.
public
array<string|int, string>
$allowed_custom_properties
= array()
Tags
$addedCustomProperties
Cache of previously added custom functions.
protected
array<string|int, mixed>
$addedCustomProperties
= array('properties' => null)
Prevents having to do the same merges over and over again.
Tags
$allowed_mixed_case_member_var_names
List of member variables that can have mixed case.
protected
array<string|int, mixed>
$allowed_mixed_case_member_var_names
= array('cat_ID' => true, 'comment_ID' => true, 'comment_author_IP' => true, 'comment_post_ID' => true, 'ID' => true, 'post_ID' => true)
Tags
$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.
$wordpress_mixed_case_vars
Mixed-case variables used by WordPress.
protected
array<string|int, mixed>
$wordpress_mixed_case_vars
= array('EZSQL_ERROR' => true, 'GETID3_ERRORARRAY' => true, 'is_IE' => true, 'is_IIS' => true, 'is_macIE' => true, 'is_NS4' => true, 'is_winIE' => true, 'PHP_SELF' => true, 'post_ID' => true, 'tag_ID' => true, 'user_ID' => true)
Tags
Methods
__construct()
Constructs an AbstractVariableTest.
public
__construct() : 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 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|string>
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|string>merge_allow_lists()
Merge a custom allow list provided via a custom ruleset with the predefined allow list, if we haven't already.
protected
merge_allow_lists() : void
Tags
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.
processTokenOutsideScope()
Processes the token outside the scope in the file.
protected
final processTokenOutsideScope(File $phpcsFile, int $stackPtr) : void|int
Parameters
- $phpcsFile : File
-
The PHP_CodeSniffer file where this token was found.
- $stackPtr : int
-
The position where the 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 $phpcsFile->numTokens to skip
the rest of the file.
processTokenWithinScope()
Processes the token in the specified PHP_CodeSniffer\Files\File.
protected
final processTokenWithinScope(File $phpcsFile, int $stackPtr, int $currScope) : void|int
Parameters
- $phpcsFile : File
-
The PHP_CodeSniffer file where this token was found.
- $stackPtr : int
-
The position where the token was found.
- $currScope : int
-
The current scope opener token.
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 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.
processVariableInString()
Processes the variables 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.