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 | 'bool' => '7.0', |
||
93 | 'int' => '7.0', |
||
94 | 'float' => '7.0', |
||
95 | 'string' => '7.0', |
||
96 | 'null' => '7.0', |
||
97 | 'true' => '7.0', |
||
98 | 'false' => '7.0', |
||
99 | 'resource' => '7.0', |
||
100 | 'object' => '7.0', |
||
101 | 'mixed' => '7.0', |
||
102 | 'numeric' => '7.0' |
||
103 | ); |
||
104 | |||
105 | /** |
||
106 | * A list of keywords that can follow use statements. |
||
107 | * Mentions since which version it's not allowed |
||
108 | * |
||
109 | * @var array(string => string) |
||
110 | */ |
||
111 | protected $validUseNames = array( |
||
112 | 'const', |
||
113 | 'function', |
||
114 | ); |
||
115 | |||
116 | /** |
||
117 | * If true, an error will be thrown; otherwise a warning. |
||
118 | * |
||
119 | * @var bool |
||
120 | */ |
||
121 | protected $error = true; |
||
122 | |||
123 | /** |
||
124 | * targetedTokens |
||
125 | * |
||
126 | * @var array |
||
127 | */ |
||
128 | protected $targetedTokens = array(T_CLASS, T_FUNCTION, T_NAMESPACE, T_STRING, T_CONST, T_USE, T_AS, T_EXTENDS, T_TRAIT); |
||
129 | |||
130 | /** |
||
131 | * Returns an array of tokens this test wants to listen for. |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | public function register() |
||
143 | |||
144 | /** |
||
145 | * Processes this test, when one of its tokens is encountered. |
||
146 | * |
||
147 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
148 | * @param int $stackPtr The position of the current token in the |
||
149 | * stack passed in $tokens. |
||
150 | * |
||
151 | * @return void |
||
152 | */ |
||
153 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
166 | |||
167 | /** |
||
168 | * Processes this test, when one of its tokens is encountered. |
||
169 | * |
||
170 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
171 | * @param int $stackPtr The position of the current token in the |
||
172 | * stack passed in $tokens. |
||
173 | * @param array $tokens The stack of tokens that make up |
||
174 | * the file. |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | public function processNonString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) |
||
202 | |||
203 | /** |
||
204 | * Processes this test, when one of its tokens is encountered. |
||
205 | * |
||
206 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
207 | * @param int $stackPtr The position of the current token in the |
||
208 | * stack passed in $tokens. |
||
209 | * @param array $tokens The stack of tokens that make up |
||
210 | * the file. |
||
211 | * |
||
212 | * @return void |
||
213 | */ |
||
214 | public function processString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) |
||
246 | |||
247 | }//end class |
||
248 |