Documentation

CapitalPDangitSniff extends Sniff

FinalYes

Capital P Dangit!

Verify the correct spelling of WordPress in text strings, comments and OO and namespace names.

Tags
since
0.12.0
since
0.13.0

Class name changed: this class is now namespaced.

since
3.0.0

Now also checks namespace names.

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 with wordpress
  • 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 wordpress for a limited set of extensions.
  • wordpress prefixed or suffixed with dashes as those are indicators that the term is probably used as part of a CSS class, such as fa-wordpress or filename/path like class-wordpress-importer.php.
  • back-tick quoted wordpress.

Properties

$phpcsFile

The current file being sniffed.

protected File $phpcsFile
Tags
since
0.4.0

$tokens

The list of tokens in the current file being sniffed.

protected array<string|int, mixed> $tokens
Tags
since
0.4.0

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


        
On this page

Search results