3
* The Tokens class contains weightings for tokens based on their
4
* probability of occurance in a file.
9
* @package PHP_CodeSniffer
10
* @author Greg Sherwood <gsherwood@squiz.net>
11
* @author Marc McIntyre <mmcintyre@squiz.net>
12
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
13
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
14
* @version CVS: $Id: Tokens.php,v 1.13 2007/11/15 22:26:23 squiz Exp $
15
* @link http://pear.php.net/package/PHP_CodeSniffer
19
define('T_OPEN_CURLY_BRACKET', 1000);
20
define('T_CLOSE_CURLY_BRACKET', 1001);
21
define('T_OPEN_SQUARE_BRACKET', 1002);
22
define('T_CLOSE_SQUARE_BRACKET', 1003);
23
define('T_OPEN_PARENTHESIS', 1004);
24
define('T_CLOSE_PARENTHESIS', 1005);
25
define('T_COLON', 1006);
26
define('T_STRING_CONCAT', 1007);
27
define('T_INLINE_THEN', 1008);
28
define('T_NULL', 1009);
29
define('T_FALSE', 1010);
30
define('T_TRUE', 1011);
31
define('T_SEMICOLON', 1012);
32
define('T_EQUAL', 1013);
33
define('T_MULTIPLY', 1015);
34
define('T_DIVIDE', 1016);
35
define('T_PLUS', 1017);
36
define('T_MINUS', 1018);
37
define('T_MODULUS', 1019);
38
define('T_POWER', 1020);
39
define('T_BITWISE_AND', 1021);
40
define('T_BITWISE_OR', 1022);
41
define('T_ARRAY_HINT', 1023);
42
define('T_GREATER_THAN', 1024);
43
define('T_LESS_THAN', 1025);
44
define('T_BOOLEAN_NOT', 1026);
45
define('T_SELF', 1027);
46
define('T_PARENT', 1028);
47
define('T_DOUBLE_QUOTED_STRING', 1029);
48
define('T_COMMA', 1030);
49
define('T_HEREDOC', 1031);
52
* The Tokens class contains weightings for tokens based on their
53
* probability of occurance in a file.
55
* The less the chance of a high occurance of an abitrary token, the higher
59
* @package PHP_CodeSniffer
60
* @author Greg Sherwood <gsherwood@squiz.net>
61
* @author Marc McIntyre <mmcintyre@squiz.net>
62
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
63
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
64
* @version Release: 1.0.1
65
* @link http://pear.php.net/package/PHP_CodeSniffer
67
final class PHP_CodeSniffer_Tokens
71
* The token weightings.
73
* @var array(int => int)
75
public static $weightings = array(
99
Operators and arithmetic.
133
T_IS_NOT_IDENTICAL => 5,
134
T_IS_SMALLER_OR_EQUAL => 5,
135
T_IS_GREATER_OR_EQUAL => 5,
141
* Tokens that represent assignments.
145
public static $assignmentTokens = array(
158
* Tokens that represent equality comparisons.
162
public static $equalityTokens = array(
167
T_IS_SMALLER_OR_EQUAL,
168
T_IS_GREATER_OR_EQUAL,
172
* Tokens that represent comparison operator.
176
public static $comparisonTokens = array(
183
T_IS_SMALLER_OR_EQUAL,
184
T_IS_GREATER_OR_EQUAL,
188
* Tokens that represent arithmetic operators.
192
public static $arithmeticTokens = array(
201
* Tokens that represent casting.
205
public static $castTokens = array(
216
* Token types that open parethesis.
220
public static $parenthesisOpeners = array(
233
* Tokens that are allowed to open scopes.
237
public static $scopeOpeners = array(
255
* Tokens that represent scope modifiers.
259
public static $scopeModifiers = array(
266
* Tokens that perform operations.
270
public static $operators = array(
282
* Tokens that perform operations.
286
public static $blockOpeners = array(
287
T_OPEN_CURLY_BRACKET,
288
T_OPEN_SQUARE_BRACKET,
293
* Tokens that don't represent code.
297
public static $emptyTokens = array(
304
* Tokens that are comments.
308
public static $commentTokens = array(
314
* Tokens that represent strings.
316
* Note that T_STRINGS are NOT represented in this list.
320
public static $stringTokens = array(
321
T_CONSTANT_ENCAPSED_STRING,
322
T_DOUBLE_QUOTED_STRING,
326
* Tokens that include files.
330
public static $includeTokens = array(
339
* A PHP_CodeSniffer_Tokens class cannot be constructed.
341
* Only static calls are allowed.
343
private function __construct()
350
* Returns the highest weighted token type.
352
* Tokens are weighted by their approximate frequency of appearance in code
353
* - the less frequently they appear in the code, the higher the weighting.
354
* For example T_CLASS tokens apprear very infrequently in a file, and
355
* therefore have a high weighting.
357
* Returns false if there are no weightings for any of the specified tokens.
359
* @param array(int) $tokens The token types to get the highest weighted
362
* @return int The highest weighted token.
364
public static function getHighestWeightedToken(array $tokens)
367
$highestType = false;
369
$weights = self::$weightings;
371
foreach ($tokens as $token) {
372
if (isset($weights[$token]) === true && $weights[$token] > $highest) {
373
$highest = $weights[$token];
374
$highestType = $token;
380
}//end getHighestWeightedToken()