Documentation

ValidVariableNameSniff extends AbstractVariableSniff

FinalYes

Checks the naming of variables and member variables.

Tags
link
https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions
link
https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php
since
0.9.0
since
0.13.0

Class name changed: this class is now namespaced.

since
2.0.0

Now offers name suggestions for variables in violation.

Last synced with base class January 2022 at commit 4b49a952bf0e2c3863d0a113256bae0d7fe63d52.

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
since
0.11.0
since
3.0.0

Renamed from $customPropertiesWhitelist to $allowed_custom_properties.

$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
since
0.10.0
since
0.11.0
  • Name changed from $addedCustomVariables.
  • Changed the format from simple bool to array.

$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
since
0.9.0
since
0.11.0

Changed from public to protected.

since
3.0.0

Renamed from $whitelisted_mixed_case_member_var_names to $allowed_mixed_case_member_var_names.

$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
since
0.11.0

Methods

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
see
processTokenWithinScope()
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
see
__constructor()
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
since
0.10.0
since
2.0.0

Removed unused $phpcs_file parameter.

since
3.0.0

Renamed from mergeWhiteList() to merge_allow_lists().

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.


        
On this page

Search results