CapitalPDangitSniff
extends Sniff
in package
Capital P Dangit!
Verify the correct spelling of WordPress in text strings, comments and OO and namespace names.
Tags
Table of Contents
Constants
- WP_CLASSNAME_REGEX = '`(?:^|_)(Word[_]*Pres+)(?:_|$)`i'
- Regex to match a large number or spelling variations of WordPress in class names.
- WP_REGEX = '#(?<![\\\\/\$@`-])\b(Word[ _-]*Pres+)\b(?![@/`-]|\.(?:org|com|net|test|tv)|[^\s<>\'"()]*?\.(?:php|js|css|png|j[e]?pg|gif|pot))#i'
- Regex to match a large number or spelling variations of WordPress in text strings.
Properties
- $phpcsFile : File
- The current file being sniffed.
- $tokens : array<string|int, mixed>
- The list of tokens in the current file being sniffed.
- $comment_text_tokens : array<string|int, mixed>
- Comment tokens we want to listen for as they contain text strings.
- $text_and_comment_tokens : array<string|int, mixed>
- Combined text string and comment tokens array.
Methods
- process() : int|void
- Set sniff properties and hand off to child class for processing of the token.
- process_token() : int|void
- Processes this test, when one of its tokens is encountered.
- register() : array<string|int, mixed>
- Returns an array of tokens this test wants to listen for.
- retrieve_misspellings() : array<string|int, mixed>
- Retrieve a list of misspellings based on an array of matched variations on the target word.
Constants
WP_CLASSNAME_REGEX
Regex to match a large number or spelling variations of WordPress in class names.
public
string
WP_CLASSNAME_REGEX
= '`(?:^|_)(Word[_]*Pres+)(?:_|$)`i'
WP_REGEX
Regex to match a large number or spelling variations of WordPress in text strings.
public
string
WP_REGEX
= '#(?<![\\\\/\$@`-])\b(Word[ _-]*Pres+)\b(?![@/`-]|\.(?:org|com|net|test|tv)|[^\s<>\'"()]*?\.(?:php|js|css|png|j[e]?pg|gif|pot))#i'
Prevents matches on:
- URLs for wordpress.org/com/net/test/tv.
@...usernames starting withwordpress- email addresses with a domain starting with
wordpress - email addresses with a user name ending with
wordpress - (most) variable names.
- directory paths containing a folder starting or ending with
wordpress. - file names containing
wordpressfor a limited set of extensions. wordpressprefixed or suffixed with dashes as those are indicators that the term is probably used as part of a CSS class, such asfa-wordpressor filename/path likeclass-wordpress-importer.php.- back-tick quoted
wordpress.
Properties
$phpcsFile
The current file being sniffed.
protected
File
$phpcsFile
Tags
$tokens
The list of tokens in the current file being sniffed.
protected
array<string|int, mixed>
$tokens
Tags
$comment_text_tokens
Comment tokens we want to listen for as they contain text strings.
private
array<string|int, mixed>
$comment_text_tokens
= array(\T_DOC_COMMENT => \T_DOC_COMMENT, \T_DOC_COMMENT_STRING => \T_DOC_COMMENT_STRING, \T_COMMENT => \T_COMMENT)
$text_and_comment_tokens
Combined text string and comment tokens array.
private
array<string|int, mixed>
$text_and_comment_tokens
= array()
This property is set in the register() method and used for lookups.
Methods
process()
Set sniff properties and hand off to child class for processing of the token.
public
process(File $phpcsFile, int $stackPtr) : int|void
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the current token in the stack passed in $tokens.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
process_token()
Processes this test, when one of its tokens is encountered.
public
process_token(int $stackPtr) : int|void
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
register()
Returns an array of tokens this test wants to listen for.
public
register() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>retrieve_misspellings()
Retrieve a list of misspellings based on an array of matched variations on the target word.
protected
retrieve_misspellings(array<string|int, mixed> $match_stack) : array<string|int, mixed>
Parameters
- $match_stack : array<string|int, mixed>
-
Array of matched variations of the target word.
Return values
array<string|int, mixed> —Array containing only the misspelled variants.