Drupal investigation

Tokens.php 35KB

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