1<?php
2/**
3 * The Tokens class contains weightings for tokens based on their
4 * probability of occurrence in a file.
5 *
6 * PHP version 5
7 *
8 * @category  PHP
9 * @package   PHP_CodeSniffer
10 * @author    Greg Sherwood <gsherwood@squiz.net>
11 * @author    Marc McIntyre <mmcintyre@squiz.net>
12 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
13 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
14 * @link      http://pear.php.net/package/PHP_CodeSniffer
15 */
16
17define('T_NONE', 'PHPCS_T_NONE');
18define('T_OPEN_CURLY_BRACKET', 'PHPCS_T_OPEN_CURLY_BRACKET');
19define('T_CLOSE_CURLY_BRACKET', 'PHPCS_T_CLOSE_CURLY_BRACKET');
20define('T_OPEN_SQUARE_BRACKET', 'PHPCS_T_OPEN_SQUARE_BRACKET');
21define('T_CLOSE_SQUARE_BRACKET', 'PHPCS_T_CLOSE_SQUARE_BRACKET');
22define('T_OPEN_PARENTHESIS', 'PHPCS_T_OPEN_PARENTHESIS');
23define('T_CLOSE_PARENTHESIS', 'PHPCS_T_CLOSE_PARENTHESIS');
24define('T_COLON', 'PHPCS_T_COLON');
25define('T_NULLABLE', 'PHPCS_T_NULLABLE');
26define('T_STRING_CONCAT', 'PHPCS_T_STRING_CONCAT');
27define('T_INLINE_THEN', 'PHPCS_T_INLINE_THEN');
28define('T_INLINE_ELSE', 'PHPCS_T_INLINE_ELSE');
29define('T_NULL', 'PHPCS_T_NULL');
30define('T_FALSE', 'PHPCS_T_FALSE');
31define('T_TRUE', 'PHPCS_T_TRUE');
32define('T_SEMICOLON', 'PHPCS_T_SEMICOLON');
33define('T_EQUAL', 'PHPCS_T_EQUAL');
34define('T_MULTIPLY', 'PHPCS_T_MULTIPLY');
35define('T_DIVIDE', 'PHPCS_T_DIVIDE');
36define('T_PLUS', 'PHPCS_T_PLUS');
37define('T_MINUS', 'PHPCS_T_MINUS');
38define('T_MODULUS', 'PHPCS_T_MODULUS');
39define('T_BITWISE_AND', 'PHPCS_T_BITWISE_AND');
40define('T_BITWISE_OR', 'PHPCS_T_BITWISE_OR');
41define('T_BITWISE_XOR', 'PHPCS_T_BITWISE_XOR');
42define('T_ARRAY_HINT', 'PHPCS_T_ARRAY_HINT');
43define('T_GREATER_THAN', 'PHPCS_T_GREATER_THAN');
44define('T_LESS_THAN', 'PHPCS_T_LESS_THAN');
45define('T_BOOLEAN_NOT', 'PHPCS_T_BOOLEAN_NOT');
46define('T_SELF', 'PHPCS_T_SELF');
47define('T_PARENT', 'PHPCS_T_PARENT');
48define('T_DOUBLE_QUOTED_STRING', 'PHPCS_T_DOUBLE_QUOTED_STRING');
49define('T_COMMA', 'PHPCS_T_COMMA');
50define('T_HEREDOC', 'PHPCS_T_HEREDOC');
51define('T_PROTOTYPE', 'PHPCS_T_PROTOTYPE');
52define('T_THIS', 'PHPCS_T_THIS');
53define('T_REGULAR_EXPRESSION', 'PHPCS_T_REGULAR_EXPRESSION');
54define('T_PROPERTY', 'PHPCS_T_PROPERTY');
55define('T_LABEL', 'PHPCS_T_LABEL');
56define('T_OBJECT', 'PHPCS_T_OBJECT');
57define('T_CLOSE_OBJECT', 'PHPCS_T_CLOSE_OBJECT');
58define('T_COLOUR', 'PHPCS_T_COLOUR');
59define('T_HASH', 'PHPCS_T_HASH');
60define('T_URL', 'PHPCS_T_URL');
61define('T_STYLE', 'PHPCS_T_STYLE');
62define('T_ASPERAND', 'PHPCS_T_ASPERAND');
63define('T_DOLLAR', 'PHPCS_T_DOLLAR');
64define('T_TYPEOF', 'PHPCS_T_TYPEOF');
65define('T_CLOSURE', 'PHPCS_T_CLOSURE');
66define('T_ANON_CLASS', 'PHPCS_T_ANON_CLASS');
67define('T_BACKTICK', 'PHPCS_T_BACKTICK');
68define('T_START_NOWDOC', 'PHPCS_T_START_NOWDOC');
69define('T_NOWDOC', 'PHPCS_T_NOWDOC');
70define('T_END_NOWDOC', 'PHPCS_T_END_NOWDOC');
71define('T_OPEN_SHORT_ARRAY', 'PHPCS_T_OPEN_SHORT_ARRAY');
72define('T_CLOSE_SHORT_ARRAY', 'PHPCS_T_CLOSE_SHORT_ARRAY');
73define('T_GOTO_LABEL', 'PHPCS_T_GOTO_LABEL');
74define('T_BINARY_CAST', 'PHPCS_T_BINARY_CAST');
75define('T_EMBEDDED_PHP', 'PHPCS_T_EMBEDDED_PHP');
76define('T_RETURN_TYPE', 'PHPCS_T_RETURN_TYPE');
77define('T_OPEN_USE_GROUP', 'PHPCS_T_OPEN_USE_GROUP');
78define('T_CLOSE_USE_GROUP', 'PHPCS_T_CLOSE_USE_GROUP');
79define('T_ZSR', 'PHPCS_T_ZSR');
80define('T_ZSR_EQUAL', 'PHPCS_T_ZSR_EQUAL');
81
82// Some PHP 5.3 tokens, replicated for lower versions.
83if (defined('T_NAMESPACE') === false) {
84    define('T_NAMESPACE', 'PHPCS_T_NAMESPACE');
85}
86
87if (defined('T_NS_C') === false) {
88    define('T_NS_C', 'PHPCS_T_NS_C');
89}
90
91if (defined('T_NS_SEPARATOR') === false) {
92    define('T_NS_SEPARATOR', 'PHPCS_T_NS_SEPARATOR');
93}
94
95if (defined('T_GOTO') === false) {
96    define('T_GOTO', 'PHPCS_T_GOTO');
97}
98
99if (defined('T_DIR') === false) {
100    define('T_DIR', 'PHPCS_T_DIR');
101}
102
103// Some PHP 5.4 tokens, replicated for lower versions.
104if (defined('T_TRAIT') === false) {
105    define('T_TRAIT', 'PHPCS_T_TRAIT');
106}
107
108if (defined('T_TRAIT_C') === false) {
109    define('T_TRAIT_C', 'PHPCS_T_TRAIT_C');
110}
111
112if (defined('T_INSTEADOF') === false) {
113    define('T_INSTEADOF', 'PHPCS_T_INSTEADOF');
114}
115
116if (defined('T_CALLABLE') === false) {
117    define('T_CALLABLE', 'PHPCS_T_CALLABLE');
118}
119
120// Some PHP 5.5 tokens, replicated for lower versions.
121if (defined('T_FINALLY') === false) {
122    define('T_FINALLY', 'PHPCS_T_FINALLY');
123}
124
125if (defined('T_YIELD') === false) {
126    define('T_YIELD', 'PHPCS_T_YIELD');
127}
128
129// Some PHP 5.6 tokens, replicated for lower versions.
130if (defined('T_ELLIPSIS') === false) {
131    define('T_ELLIPSIS', 'PHPCS_T_ELLIPSIS');
132}
133
134if (defined('T_POW') === false) {
135    define('T_POW', 'PHPCS_T_POW');
136}
137
138if (defined('T_POW_EQUAL') === false) {
139    define('T_POW_EQUAL', 'PHPCS_T_POW_EQUAL');
140}
141
142// Some PHP 7 tokens, replicated for lower versions.
143if (defined('T_SPACESHIP') === false) {
144    define('T_SPACESHIP', 'PHPCS_T_SPACESHIP');
145}
146
147if (defined('T_COALESCE') === false) {
148    define('T_COALESCE', 'PHPCS_T_COALESCE');
149}
150
151if (defined('T_COALESCE_EQUAL') === false) {
152    define('T_COALESCE_EQUAL', 'PHPCS_T_COALESCE_EQUAL');
153}
154
155if (defined('T_YIELD_FROM') === false) {
156    define('T_YIELD_FROM', 'PHPCS_T_YIELD_FROM');
157}
158
159// Tokens used for parsing doc blocks.
160define('T_DOC_COMMENT_STAR', 'PHPCS_T_DOC_COMMENT_STAR');
161define('T_DOC_COMMENT_WHITESPACE', 'PHPCS_T_DOC_COMMENT_WHITESPACE');
162define('T_DOC_COMMENT_TAG', 'PHPCS_T_DOC_COMMENT_TAG');
163define('T_DOC_COMMENT_OPEN_TAG', 'PHPCS_T_DOC_COMMENT_OPEN_TAG');
164define('T_DOC_COMMENT_CLOSE_TAG', 'PHPCS_T_DOC_COMMENT_CLOSE_TAG');
165define('T_DOC_COMMENT_STRING', 'PHPCS_T_DOC_COMMENT_STRING');
166
167/**
168 * The Tokens class contains weightings for tokens based on their
169 * probability of occurrence in a file.
170 *
171 * The less the chance of a high occurrence of an arbitrary token, the higher
172 * the weighting.
173 *
174 * @category  PHP
175 * @package   PHP_CodeSniffer
176 * @author    Greg Sherwood <gsherwood@squiz.net>
177 * @author    Marc McIntyre <mmcintyre@squiz.net>
178 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
179 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
180 * @version   Release: @package_version@
181 * @link      http://pear.php.net/package/PHP_CodeSniffer
182 */
183final class PHP_CodeSniffer_Tokens
184{
185
186    /**
187     * The token weightings.
188     *
189     * @var array(int => int)
190     */
191    public static $weightings = array(
192                                 T_CLASS               => 1000,
193                                 T_INTERFACE           => 1000,
194                                 T_TRAIT               => 1000,
195                                 T_NAMESPACE           => 1000,
196                                 T_FUNCTION            => 100,
197                                 T_CLOSURE             => 100,
198
199                                 /*
200                                     Conditions.
201                                 */
202
203                                 T_WHILE               => 50,
204                                 T_FOR                 => 50,
205                                 T_FOREACH             => 50,
206                                 T_IF                  => 50,
207                                 T_ELSE                => 50,
208                                 T_ELSEIF              => 50,
209                                 T_DO                  => 50,
210                                 T_TRY                 => 50,
211                                 T_CATCH               => 50,
212                                 T_FINALLY             => 50,
213                                 T_SWITCH              => 50,
214
215                                 T_SELF                => 25,
216                                 T_PARENT              => 25,
217
218                                 /*
219                                     Operators and arithmetic.
220                                 */
221
222                                 T_BITWISE_AND         => 8,
223                                 T_BITWISE_OR          => 8,
224                                 T_BITWISE_XOR         => 8,
225
226                                 T_MULTIPLY            => 5,
227                                 T_DIVIDE              => 5,
228                                 T_PLUS                => 5,
229                                 T_MINUS               => 5,
230                                 T_MODULUS             => 5,
231                                 T_POW                 => 5,
232                                 T_SPACESHIP           => 5,
233                                 T_COALESCE            => 5,
234                                 T_COALESCE_EQUAL      => 5,
235
236                                 T_SL                  => 5,
237                                 T_SR                  => 5,
238                                 T_SL_EQUAL            => 5,
239                                 T_SR_EQUAL            => 5,
240
241                                 T_EQUAL               => 5,
242                                 T_AND_EQUAL           => 5,
243                                 T_CONCAT_EQUAL        => 5,
244                                 T_DIV_EQUAL           => 5,
245                                 T_MINUS_EQUAL         => 5,
246                                 T_MOD_EQUAL           => 5,
247                                 T_MUL_EQUAL           => 5,
248                                 T_OR_EQUAL            => 5,
249                                 T_PLUS_EQUAL          => 5,
250                                 T_XOR_EQUAL           => 5,
251
252                                 T_BOOLEAN_AND         => 5,
253                                 T_BOOLEAN_OR          => 5,
254
255                                 /*
256                                     Equality.
257                                 */
258
259                                 T_IS_EQUAL            => 5,
260                                 T_IS_NOT_EQUAL        => 5,
261                                 T_IS_IDENTICAL        => 5,
262                                 T_IS_NOT_IDENTICAL    => 5,
263                                 T_IS_SMALLER_OR_EQUAL => 5,
264                                 T_IS_GREATER_OR_EQUAL => 5,
265                                );
266
267    /**
268     * The token weightings.
269     *
270     * @var array(int => int)
271     */
272    public static $knownLengths = array(
273                                   T_ABSTRACT                 => 8,
274                                   T_AND_EQUAL                => 2,
275                                   T_ARRAY                    => 5,
276                                   T_AS                       => 2,
277                                   T_BOOLEAN_AND              => 2,
278                                   T_BOOLEAN_OR               => 2,
279                                   T_BREAK                    => 5,
280                                   T_CALLABLE                 => 8,
281                                   T_CASE                     => 4,
282                                   T_CATCH                    => 5,
283                                   T_CLASS                    => 5,
284                                   T_CLASS_C                  => 9,
285                                   T_CLONE                    => 5,
286                                   T_CONCAT_EQUAL             => 2,
287                                   T_CONST                    => 5,
288                                   T_CONTINUE                 => 8,
289                                   T_CURLY_OPEN               => 2,
290                                   T_DEC                      => 2,
291                                   T_DECLARE                  => 7,
292                                   T_DEFAULT                  => 7,
293                                   T_DIR                      => 7,
294                                   T_DIV_EQUAL                => 2,
295                                   T_DO                       => 2,
296                                   T_DOLLAR_OPEN_CURLY_BRACES => 2,
297                                   T_DOUBLE_ARROW             => 2,
298                                   T_DOUBLE_COLON             => 2,
299                                   T_ECHO                     => 4,
300                                   T_ELSE                     => 4,
301                                   T_ELSEIF                   => 6,
302                                   T_EMPTY                    => 5,
303                                   T_ENDDECLARE               => 10,
304                                   T_ENDFOR                   => 6,
305                                   T_ENDFOREACH               => 10,
306                                   T_ENDIF                    => 5,
307                                   T_ENDSWITCH                => 9,
308                                   T_ENDWHILE                 => 8,
309                                   T_EVAL                     => 4,
310                                   T_EXTENDS                  => 7,
311                                   T_FILE                     => 8,
312                                   T_FINAL                    => 5,
313                                   T_FINALLY                  => 7,
314                                   T_FOR                      => 3,
315                                   T_FOREACH                  => 7,
316                                   T_FUNCTION                 => 8,
317                                   T_FUNC_C                   => 12,
318                                   T_GLOBAL                   => 6,
319                                   T_GOTO                     => 4,
320                                   T_HALT_COMPILER            => 15,
321                                   T_IF                       => 2,
322                                   T_IMPLEMENTS               => 10,
323                                   T_INC                      => 2,
324                                   T_INCLUDE                  => 7,
325                                   T_INCLUDE_ONCE             => 12,
326                                   T_INSTANCEOF               => 10,
327                                   T_INSTEADOF                => 9,
328                                   T_INTERFACE                => 9,
329                                   T_ISSET                    => 5,
330                                   T_IS_EQUAL                 => 2,
331                                   T_IS_GREATER_OR_EQUAL      => 2,
332                                   T_IS_IDENTICAL             => 3,
333                                   T_IS_NOT_EQUAL             => 2,
334                                   T_IS_NOT_IDENTICAL         => 3,
335                                   T_IS_SMALLER_OR_EQUAL      => 2,
336                                   T_LINE                     => 8,
337                                   T_LIST                     => 4,
338                                   T_LOGICAL_AND              => 3,
339                                   T_LOGICAL_OR               => 2,
340                                   T_LOGICAL_XOR              => 3,
341                                   T_METHOD_C                 => 10,
342                                   T_MINUS_EQUAL              => 2,
343                                   T_POW_EQUAL                => 3,
344                                   T_MOD_EQUAL                => 2,
345                                   T_MUL_EQUAL                => 2,
346                                   T_NAMESPACE                => 9,
347                                   T_NS_C                     => 13,
348                                   T_NS_SEPARATOR             => 1,
349                                   T_NEW                      => 3,
350                                   T_OBJECT_OPERATOR          => 2,
351                                   T_OPEN_TAG_WITH_ECHO       => 3,
352                                   T_OR_EQUAL                 => 2,
353                                   T_PLUS_EQUAL               => 2,
354                                   T_PRINT                    => 5,
355                                   T_PRIVATE                  => 7,
356                                   T_PUBLIC                   => 6,
357                                   T_PROTECTED                => 9,
358                                   T_REQUIRE                  => 7,
359                                   T_REQUIRE_ONCE             => 12,
360                                   T_RETURN                   => 6,
361                                   T_STATIC                   => 6,
362                                   T_SWITCH                   => 6,
363                                   T_THROW                    => 5,
364                                   T_TRAIT                    => 5,
365                                   T_TRAIT_C                  => 9,
366                                   T_TRY                      => 3,
367                                   T_UNSET                    => 5,
368                                   T_USE                      => 3,
369                                   T_VAR                      => 3,
370                                   T_WHILE                    => 5,
371                                   T_XOR_EQUAL                => 2,
372                                   T_YIELD                    => 5,
373                                   T_OPEN_CURLY_BRACKET       => 1,
374                                   T_CLOSE_CURLY_BRACKET      => 1,
375                                   T_OPEN_SQUARE_BRACKET      => 1,
376                                   T_CLOSE_SQUARE_BRACKET     => 1,
377                                   T_OPEN_PARENTHESIS         => 1,
378                                   T_CLOSE_PARENTHESIS        => 1,
379                                   T_COLON                    => 1,
380                                   T_NULLABLE                 => 1,
381                                   T_STRING_CONCAT            => 1,
382                                   T_INLINE_THEN              => 1,
383                                   T_INLINE_ELSE              => 1,
384                                   T_NULL                     => 4,
385                                   T_FALSE                    => 5,
386                                   T_TRUE                     => 4,
387                                   T_SEMICOLON                => 1,
388                                   T_EQUAL                    => 1,
389                                   T_MULTIPLY                 => 1,
390                                   T_DIVIDE                   => 1,
391                                   T_PLUS                     => 1,
392                                   T_MINUS                    => 1,
393                                   T_MODULUS                  => 1,
394                                   T_POW                      => 2,
395                                   T_SPACESHIP                => 3,
396                                   T_COALESCE                 => 2,
397                                   T_COALESCE_EQUAL           => 3,
398                                   T_BITWISE_AND              => 1,
399                                   T_BITWISE_OR               => 1,
400                                   T_BITWISE_XOR              => 1,
401                                   T_SL                       => 2,
402                                   T_SR                       => 2,
403                                   T_SL_EQUAL                 => 3,
404                                   T_SR_EQUAL                 => 3,
405                                   T_ARRAY_HINT               => 5,
406                                   T_GREATER_THAN             => 1,
407                                   T_LESS_THAN                => 1,
408                                   T_BOOLEAN_NOT              => 1,
409                                   T_SELF                     => 4,
410                                   T_PARENT                   => 6,
411                                   T_COMMA                    => 1,
412                                   T_THIS                     => 4,
413                                   T_CLOSURE                  => 8,
414                                   T_BACKTICK                 => 1,
415                                   T_OPEN_SHORT_ARRAY         => 1,
416                                   T_CLOSE_SHORT_ARRAY        => 1,
417                                  );
418
419    /**
420     * Tokens that represent assignments.
421     *
422     * @var array(int)
423     */
424    public static $assignmentTokens = array(
425                                       T_EQUAL          => T_EQUAL,
426                                       T_AND_EQUAL      => T_AND_EQUAL,
427                                       T_OR_EQUAL       => T_OR_EQUAL,
428                                       T_CONCAT_EQUAL   => T_CONCAT_EQUAL,
429                                       T_DIV_EQUAL      => T_DIV_EQUAL,
430                                       T_MINUS_EQUAL    => T_MINUS_EQUAL,
431                                       T_POW_EQUAL      => T_POW_EQUAL,
432                                       T_MOD_EQUAL      => T_MOD_EQUAL,
433                                       T_MUL_EQUAL      => T_MUL_EQUAL,
434                                       T_PLUS_EQUAL     => T_PLUS_EQUAL,
435                                       T_XOR_EQUAL      => T_XOR_EQUAL,
436                                       T_DOUBLE_ARROW   => T_DOUBLE_ARROW,
437                                       T_SL_EQUAL       => T_SL_EQUAL,
438                                       T_SR_EQUAL       => T_SR_EQUAL,
439                                       T_COALESCE_EQUAL => T_COALESCE_EQUAL,
440                                      );
441
442    /**
443     * Tokens that represent equality comparisons.
444     *
445     * @var array(int)
446     */
447    public static $equalityTokens = array(
448                                     T_IS_EQUAL            => T_IS_EQUAL,
449                                     T_IS_NOT_EQUAL        => T_IS_NOT_EQUAL,
450                                     T_IS_IDENTICAL        => T_IS_IDENTICAL,
451                                     T_IS_NOT_IDENTICAL    => T_IS_NOT_IDENTICAL,
452                                     T_IS_SMALLER_OR_EQUAL => T_IS_SMALLER_OR_EQUAL,
453                                     T_IS_GREATER_OR_EQUAL => T_IS_GREATER_OR_EQUAL,
454                                    );
455
456    /**
457     * Tokens that represent comparison operator.
458     *
459     * @var array(int)
460     */
461    public static $comparisonTokens = array(
462                                       T_IS_EQUAL            => T_IS_EQUAL,
463                                       T_IS_IDENTICAL        => T_IS_IDENTICAL,
464                                       T_IS_NOT_EQUAL        => T_IS_NOT_EQUAL,
465                                       T_IS_NOT_IDENTICAL    => T_IS_NOT_IDENTICAL,
466                                       T_LESS_THAN           => T_LESS_THAN,
467                                       T_GREATER_THAN        => T_GREATER_THAN,
468                                       T_IS_SMALLER_OR_EQUAL => T_IS_SMALLER_OR_EQUAL,
469                                       T_IS_GREATER_OR_EQUAL => T_IS_GREATER_OR_EQUAL,
470                                       T_SPACESHIP           => T_SPACESHIP,
471                                       T_COALESCE            => T_COALESCE,
472                                      );
473
474    /**
475     * Tokens that represent arithmetic operators.
476     *
477     * @var array(int)
478     */
479    public static $arithmeticTokens = array(
480                                       T_PLUS     => T_PLUS,
481                                       T_MINUS    => T_MINUS,
482                                       T_MULTIPLY => T_MULTIPLY,
483                                       T_DIVIDE   => T_DIVIDE,
484                                       T_MODULUS  => T_MODULUS,
485                                       T_POW      => T_POW,
486                                      );
487
488    /**
489     * Tokens that represent casting.
490     *
491     * @var array(int)
492     */
493    public static $castTokens = array(
494                                 T_INT_CAST    => T_INT_CAST,
495                                 T_STRING_CAST => T_STRING_CAST,
496                                 T_DOUBLE_CAST => T_DOUBLE_CAST,
497                                 T_ARRAY_CAST  => T_ARRAY_CAST,
498                                 T_BOOL_CAST   => T_BOOL_CAST,
499                                 T_OBJECT_CAST => T_OBJECT_CAST,
500                                 T_UNSET_CAST  => T_UNSET_CAST,
501                                 T_BINARY_CAST => T_BINARY_CAST,
502                                );
503
504    /**
505     * Token types that open parenthesis.
506     *
507     * @var array(int)
508     */
509    public static $parenthesisOpeners = array(
510                                         T_ARRAY    => T_ARRAY,
511                                         T_FUNCTION => T_FUNCTION,
512                                         T_CLOSURE  => T_CLOSURE,
513                                         T_WHILE    => T_WHILE,
514                                         T_FOR      => T_FOR,
515                                         T_FOREACH  => T_FOREACH,
516                                         T_SWITCH   => T_SWITCH,
517                                         T_IF       => T_IF,
518                                         T_ELSEIF   => T_ELSEIF,
519                                         T_CATCH    => T_CATCH,
520                                         T_DECLARE  => T_DECLARE,
521                                        );
522
523    /**
524     * Tokens that are allowed to open scopes.
525     *
526     * @var array(int)
527     */
528    public static $scopeOpeners = array(
529                                   T_CLASS      => T_CLASS,
530                                   T_ANON_CLASS => T_ANON_CLASS,
531                                   T_INTERFACE  => T_INTERFACE,
532                                   T_TRAIT      => T_TRAIT,
533                                   T_NAMESPACE  => T_NAMESPACE,
534                                   T_FUNCTION   => T_FUNCTION,
535                                   T_CLOSURE    => T_CLOSURE,
536                                   T_IF         => T_IF,
537                                   T_SWITCH     => T_SWITCH,
538                                   T_CASE       => T_CASE,
539                                   T_DECLARE    => T_DECLARE,
540                                   T_DEFAULT    => T_DEFAULT,
541                                   T_WHILE      => T_WHILE,
542                                   T_ELSE       => T_ELSE,
543                                   T_ELSEIF     => T_ELSEIF,
544                                   T_FOR        => T_FOR,
545                                   T_FOREACH    => T_FOREACH,
546                                   T_DO         => T_DO,
547                                   T_TRY        => T_TRY,
548                                   T_CATCH      => T_CATCH,
549                                   T_FINALLY    => T_FINALLY,
550                                   T_PROPERTY   => T_PROPERTY,
551                                   T_OBJECT     => T_OBJECT,
552                                   T_USE        => T_USE,
553                                  );
554
555    /**
556     * Tokens that represent scope modifiers.
557     *
558     * @var array(int)
559     */
560    public static $scopeModifiers = array(
561                                     T_PRIVATE   => T_PRIVATE,
562                                     T_PUBLIC    => T_PUBLIC,
563                                     T_PROTECTED => T_PROTECTED,
564                                    );
565
566    /**
567     * Tokens that can prefix a method name
568     *
569     * @var array(int)
570     */
571    public static $methodPrefixes = array(
572                                     T_PRIVATE   => T_PRIVATE,
573                                     T_PUBLIC    => T_PUBLIC,
574                                     T_PROTECTED => T_PROTECTED,
575                                     T_ABSTRACT  => T_ABSTRACT,
576                                     T_STATIC    => T_STATIC,
577                                     T_FINAL     => T_FINAL,
578                                    );
579
580    /**
581     * Tokens that perform operations.
582     *
583     * @var array(int)
584     */
585    public static $operators = array(
586                                T_MINUS       => T_MINUS,
587                                T_PLUS        => T_PLUS,
588                                T_MULTIPLY    => T_MULTIPLY,
589                                T_DIVIDE      => T_DIVIDE,
590                                T_MODULUS     => T_MODULUS,
591                                T_POW         => T_POW,
592                                T_SPACESHIP   => T_SPACESHIP,
593                                T_COALESCE    => T_COALESCE,
594                                T_BITWISE_AND => T_BITWISE_AND,
595                                T_BITWISE_OR  => T_BITWISE_OR,
596                                T_BITWISE_XOR => T_BITWISE_XOR,
597                                T_SL          => T_SL,
598                                T_SR          => T_SR,
599                               );
600
601    /**
602     * Tokens that perform boolean operations.
603     *
604     * @var array(int)
605     */
606    public static $booleanOperators = array(
607                                       T_BOOLEAN_AND => T_BOOLEAN_AND,
608                                       T_BOOLEAN_OR  => T_BOOLEAN_OR,
609                                       T_LOGICAL_AND => T_LOGICAL_AND,
610                                       T_LOGICAL_OR  => T_LOGICAL_OR,
611                                       T_LOGICAL_XOR => T_LOGICAL_XOR,
612                                      );
613
614    /**
615     * Tokens that open code blocks.
616     *
617     * @var array(int)
618     */
619    public static $blockOpeners = array(
620                                   T_OPEN_CURLY_BRACKET  => T_OPEN_CURLY_BRACKET,
621                                   T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET,
622                                   T_OPEN_PARENTHESIS    => T_OPEN_PARENTHESIS,
623                                   T_OBJECT              => T_OBJECT,
624                                  );
625
626    /**
627     * Tokens that don't represent code.
628     *
629     * @var array(int)
630     */
631    public static $emptyTokens = array(
632                                  T_WHITESPACE             => T_WHITESPACE,
633                                  T_COMMENT                => T_COMMENT,
634                                  T_DOC_COMMENT            => T_DOC_COMMENT,
635                                  T_DOC_COMMENT_STAR       => T_DOC_COMMENT_STAR,
636                                  T_DOC_COMMENT_WHITESPACE => T_DOC_COMMENT_WHITESPACE,
637                                  T_DOC_COMMENT_TAG        => T_DOC_COMMENT_TAG,
638                                  T_DOC_COMMENT_OPEN_TAG   => T_DOC_COMMENT_OPEN_TAG,
639                                  T_DOC_COMMENT_CLOSE_TAG  => T_DOC_COMMENT_CLOSE_TAG,
640                                  T_DOC_COMMENT_STRING     => T_DOC_COMMENT_STRING,
641                                 );
642
643    /**
644     * Tokens that are comments.
645     *
646     * @var array(int)
647     */
648    public static $commentTokens = array(
649                                    T_COMMENT                => T_COMMENT,
650                                    T_DOC_COMMENT            => T_DOC_COMMENT,
651                                    T_DOC_COMMENT_STAR       => T_DOC_COMMENT_STAR,
652                                    T_DOC_COMMENT_WHITESPACE => T_DOC_COMMENT_WHITESPACE,
653                                    T_DOC_COMMENT_TAG        => T_DOC_COMMENT_TAG,
654                                    T_DOC_COMMENT_OPEN_TAG   => T_DOC_COMMENT_OPEN_TAG,
655                                    T_DOC_COMMENT_CLOSE_TAG  => T_DOC_COMMENT_CLOSE_TAG,
656                                    T_DOC_COMMENT_STRING     => T_DOC_COMMENT_STRING,
657                                   );
658
659    /**
660     * Tokens that represent strings.
661     *
662     * Note that T_STRINGS are NOT represented in this list.
663     *
664     * @var array(int)
665     */
666    public static $stringTokens = array(
667                                   T_CONSTANT_ENCAPSED_STRING => T_CONSTANT_ENCAPSED_STRING,
668                                   T_DOUBLE_QUOTED_STRING     => T_DOUBLE_QUOTED_STRING,
669                                  );
670
671    /**
672     * Tokens that represent text strings.
673     *
674     * @var array(int)
675     */
676    public static $textStringTokens = array(
677                                       T_CONSTANT_ENCAPSED_STRING => T_CONSTANT_ENCAPSED_STRING,
678                                       T_DOUBLE_QUOTED_STRING     => T_DOUBLE_QUOTED_STRING,
679                                       T_INLINE_HTML              => T_INLINE_HTML,
680                                       T_HEREDOC                  => T_HEREDOC,
681                                       T_NOWDOC                   => T_NOWDOC,
682                                      );
683
684    /**
685     * Tokens that represent brackets and parenthesis.
686     *
687     * @var array(int)
688     */
689    public static $bracketTokens = array(
690                                    T_OPEN_CURLY_BRACKET   => T_OPEN_CURLY_BRACKET,
691                                    T_CLOSE_CURLY_BRACKET  => T_CLOSE_CURLY_BRACKET,
692                                    T_OPEN_SQUARE_BRACKET  => T_OPEN_SQUARE_BRACKET,
693                                    T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET,
694                                    T_OPEN_PARENTHESIS     => T_OPEN_PARENTHESIS,
695                                    T_CLOSE_PARENTHESIS    => T_CLOSE_PARENTHESIS,
696                                   );
697
698    /**
699     * Tokens that include files.
700     *
701     * @var array(int)
702     */
703    public static $includeTokens = array(
704                                    T_REQUIRE_ONCE => T_REQUIRE_ONCE,
705                                    T_REQUIRE      => T_REQUIRE,
706                                    T_INCLUDE_ONCE => T_INCLUDE_ONCE,
707                                    T_INCLUDE      => T_INCLUDE,
708                                   );
709
710    /**
711     * Tokens that make up a heredoc string.
712     *
713     * @var array(int)
714     */
715    public static $heredocTokens = array(
716                                    T_START_HEREDOC => T_START_HEREDOC,
717                                    T_END_HEREDOC   => T_END_HEREDOC,
718                                    T_HEREDOC       => T_HEREDOC,
719                                    T_START_NOWDOC  => T_START_NOWDOC,
720                                    T_END_NOWDOC    => T_END_NOWDOC,
721                                    T_NOWDOC        => T_NOWDOC,
722                                   );
723
724    /**
725     * Tokens that represent the names of called functions.
726     *
727     * Mostly, these are just strings. But PHP tokenizes some language
728     * constructs and functions using their own tokens.
729     *
730     * @var array(int)
731     */
732    public static $functionNameTokens = array(
733                                         T_STRING       => T_STRING,
734                                         T_EVAL         => T_EVAL,
735                                         T_EXIT         => T_EXIT,
736                                         T_INCLUDE      => T_INCLUDE,
737                                         T_INCLUDE_ONCE => T_INCLUDE_ONCE,
738                                         T_REQUIRE      => T_REQUIRE,
739                                         T_REQUIRE_ONCE => T_REQUIRE_ONCE,
740                                         T_ISSET        => T_ISSET,
741                                         T_UNSET        => T_UNSET,
742                                         T_EMPTY        => T_EMPTY,
743                                        );
744
745
746    /**
747     * A PHP_CodeSniffer_Tokens class cannot be constructed.
748     *
749     * Only static calls are allowed.
750     */
751    private function __construct()
752    {
753
754    }//end __construct()
755
756
757    /**
758     * Returns the highest weighted token type.
759     *
760     * Tokens are weighted by their approximate frequency of appearance in code
761     * - the less frequently they appear in the code, the higher the weighting.
762     * For example T_CLASS tokens appear very infrequently in a file, and
763     * therefore have a high weighting.
764     *
765     * Returns false if there are no weightings for any of the specified tokens.
766     *
767     * @param array(int) $tokens The token types to get the highest weighted
768     *                           type for.
769     *
770     * @return int The highest weighted token.
771     */
772    public static function getHighestWeightedToken(array $tokens)
773    {
774        $highest     = -1;
775        $highestType = false;
776
777        $weights = self::$weightings;
778
779        foreach ($tokens as $token) {
780            if (isset($weights[$token]) === true) {
781                $weight = $weights[$token];
782            } else {
783                $weight = 0;
784            }
785
786            if ($weight > $highest) {
787                $highest     = $weight;
788                $highestType = $token;
789            }
790        }
791
792        return $highestType;
793
794    }//end getHighestWeightedToken()
795
796
797}//end class
798