-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathGenericNamesSniff.php
59 lines (51 loc) · 1.43 KB
/
GenericNamesSniff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* GenericNamesSniff
*
* Based on code from {@link https://github.com/WordPress/WordPress-Coding-Standards}
* which is licensed under {@link https://opensource.org/licenses/MIT}.
*
* @package PluginCheck
*/
namespace PluginCheckCS\PluginCheck\Sniffs\CodeAnalysis;
use PHP_CodeSniffer\Exceptions\RuntimeException;
use PHP_CodeSniffer\Util\Tokens;
use PHPCSUtils\Tokens\Collections;
use PHPCSUtils\Utils\TextStrings;
use WordPressCS\WordPress\Sniff;
/**
* Gets all function/class/define/namespace/option names and checks them to be not generic.
*
* @link https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/
*
* @since 1.3.0
*/
final class GenericNamesSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register() {
$targets = Collections::textStringStartTokens();
$targets[] = \T_FUNCTION;
$targets[] = \T_CLASS;
return $targets;
}
/**
* Processes this test, when one of its tokens is encountered.
*
* @param int $stackPtr The position of the current token in the stack.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
*/
public function process_token( $stackPtr ) {
$end_ptr = $stackPtr;
$content = $this->tokens[ $stackPtr ]['content'];
if ( empty( trim( $content ) ) ) {
return;
}
return ( $end_ptr + 1 );
}
}