1 | <?php |
||
25 | class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_Sniff |
||
|
|||
26 | { |
||
27 | |||
28 | /** |
||
29 | * A list of keywords that can not be used as function, class and namespace name or constant name. |
||
30 | * Mentions since which version it's not allowed. |
||
31 | * |
||
32 | * @var array(string => string) |
||
33 | */ |
||
34 | protected $invalidNames = array( |
||
35 | 'abstract' => '5.0', |
||
36 | 'and' => 'all', |
||
37 | 'array' => 'all', |
||
38 | 'as' => 'all', |
||
39 | 'break' => 'all', |
||
40 | 'callable' => '5.4', |
||
41 | 'case' => 'all', |
||
42 | 'catch' => '5.0', |
||
43 | 'class' => 'all', |
||
44 | 'clone' => '5.0', |
||
45 | 'const' => 'all', |
||
46 | 'continue' => 'all', |
||
47 | 'declare' => 'all', |
||
48 | 'default' => 'all', |
||
49 | 'do' => 'all', |
||
50 | 'else' => 'all', |
||
51 | 'elseif' => 'all', |
||
52 | 'enddeclare' => 'all', |
||
53 | 'endfor' => 'all', |
||
54 | 'endforeach' => 'all', |
||
55 | 'endif' => 'all', |
||
56 | 'endswitch' => 'all', |
||
57 | 'endwhile' => 'all', |
||
58 | 'extends' => 'all', |
||
59 | 'final' => '5.0', |
||
60 | 'finally' => '5.5', |
||
61 | 'for' => 'all', |
||
62 | 'foreach' => 'all', |
||
63 | 'function' => 'all', |
||
64 | 'global' => 'all', |
||
65 | 'goto' => '5.3', |
||
66 | 'if' => 'all', |
||
67 | 'implements' => '5.0', |
||
68 | 'interface' => '5.0', |
||
69 | 'instanceof' => '5.0', |
||
70 | 'insteadof' => '5.4', |
||
71 | 'namespace' => '5.3', |
||
72 | 'new' => 'all', |
||
73 | 'or' => 'all', |
||
74 | 'private' => '5.0', |
||
75 | 'protected' => '5.0', |
||
76 | 'public' => '5.0', |
||
77 | 'static' => 'all', |
||
78 | 'switch' => 'all', |
||
79 | 'throw' => '5.0', |
||
80 | 'trait' => '5.4', |
||
81 | 'try' => '5.0', |
||
82 | 'use' => 'all', |
||
83 | 'var' => 'all', |
||
84 | 'while' => 'all', |
||
85 | 'xor' => 'all', |
||
86 | '__class__' => 'all', |
||
87 | '__dir__' => '5.3', |
||
88 | '__file__' => 'all', |
||
89 | '__function__' => 'all', |
||
90 | '__method__' => 'all', |
||
91 | '__namespace__' => '5.3', |
||
92 | ); |
||
93 | |||
94 | /** |
||
95 | * A list of keywords that can follow use statements. |
||
96 | * |
||
97 | * @var array(string => string) |
||
98 | */ |
||
99 | protected $validUseNames = array( |
||
100 | 'const' => true, |
||
101 | 'function' => true, |
||
102 | ); |
||
103 | |||
104 | /** |
||
105 | * Whether PHPCS 1.x is used or not. |
||
106 | * |
||
107 | * @var bool |
||
108 | */ |
||
109 | protected $isLowPHPCS = false; |
||
110 | |||
111 | /** |
||
112 | * Scope modifiers and other keywords allowed in trait use statements. |
||
113 | * |
||
114 | * @var array |
||
115 | */ |
||
116 | private $allowed_modifiers = array(); |
||
117 | |||
118 | /** |
||
119 | * targetedTokens |
||
120 | * |
||
121 | * @var array |
||
122 | */ |
||
123 | protected $targetedTokens = array( |
||
124 | T_CLASS, |
||
125 | T_FUNCTION, |
||
126 | T_NAMESPACE, |
||
127 | T_STRING, |
||
128 | T_CONST, |
||
129 | T_USE, |
||
130 | T_AS, |
||
131 | T_EXTENDS, |
||
132 | T_TRAIT, |
||
133 | T_INTERFACE, |
||
134 | ); |
||
135 | |||
136 | /** |
||
137 | * Returns an array of tokens this test wants to listen for. |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | public function register() |
||
156 | |||
157 | /** |
||
158 | * Processes this test, when one of its tokens is encountered. |
||
159 | * |
||
160 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
161 | * @param int $stackPtr The position of the current token in the |
||
162 | * stack passed in $tokens. |
||
163 | * |
||
164 | * @return void |
||
165 | */ |
||
166 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
179 | |||
180 | /** |
||
181 | * Processes this test, when one of its tokens is encountered. |
||
182 | * |
||
183 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
184 | * @param int $stackPtr The position of the current token in the |
||
185 | * stack passed in $tokens. |
||
186 | * @param array $tokens The stack of tokens that make up |
||
187 | * the file. |
||
188 | * |
||
189 | * @return void |
||
190 | */ |
||
191 | public function processNonString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) |
||
272 | |||
273 | /** |
||
274 | * Processes this test, when one of its tokens is encountered. |
||
275 | * |
||
276 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
277 | * @param int $stackPtr The position of the current token in the |
||
278 | * stack passed in $tokens. |
||
279 | * @param array $tokens The stack of tokens that make up |
||
280 | * the file. |
||
281 | * |
||
282 | * @return void |
||
283 | */ |
||
284 | public function processString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) |
||
323 | |||
324 | |||
325 | /** |
||
326 | * Add the error message. |
||
327 | * |
||
328 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
329 | * @param int $stackPtr The position of the current token in the |
||
330 | * stack passed in $tokens. |
||
331 | * @param string $content The token content found. |
||
332 | * @param array $data The data to pass into the error message. |
||
333 | * |
||
334 | * @return void |
||
335 | */ |
||
336 | protected function addError($phpcsFile, $stackPtr, $content, $data) |
||
342 | |||
343 | |||
344 | /** |
||
345 | * Check if the current token code is for a token which can be considered |
||
346 | * the end of a (partial) use statement. |
||
347 | * |
||
348 | * @param int $token The current token information. |
||
349 | * |
||
350 | * @return bool |
||
351 | */ |
||
352 | protected function isEndOfUseStatement($token) |
||
356 | }//end class |
||
357 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.