Token.php 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  1. <?php
  2. /*
  3. * This file is part of php-token-stream.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * A PHP token.
  12. */
  13. abstract class PHP_Token
  14. {
  15. /**
  16. * @var string
  17. */
  18. protected $text;
  19. /**
  20. * @var int
  21. */
  22. protected $line;
  23. /**
  24. * @var PHP_Token_Stream
  25. */
  26. protected $tokenStream;
  27. /**
  28. * @var int
  29. */
  30. protected $id;
  31. /**
  32. * @param string $text
  33. * @param int $line
  34. * @param PHP_Token_Stream $tokenStream
  35. * @param int $id
  36. */
  37. public function __construct($text, $line, PHP_Token_Stream $tokenStream, $id)
  38. {
  39. $this->text = $text;
  40. $this->line = $line;
  41. $this->tokenStream = $tokenStream;
  42. $this->id = $id;
  43. }
  44. /**
  45. * @return string
  46. */
  47. public function __toString()
  48. {
  49. return $this->text;
  50. }
  51. /**
  52. * @return int
  53. */
  54. public function getLine()
  55. {
  56. return $this->line;
  57. }
  58. /**
  59. * @return int
  60. */
  61. public function getId()
  62. {
  63. return $this->id;
  64. }
  65. }
  66. abstract class PHP_TokenWithScope extends PHP_Token
  67. {
  68. /**
  69. * @var int
  70. */
  71. protected $endTokenId;
  72. /**
  73. * Get the docblock for this token
  74. *
  75. * This method will fetch the docblock belonging to the current token. The
  76. * docblock must be placed on the line directly above the token to be
  77. * recognized.
  78. *
  79. * @return string|null Returns the docblock as a string if found
  80. */
  81. public function getDocblock()
  82. {
  83. $tokens = $this->tokenStream->tokens();
  84. $currentLineNumber = $tokens[$this->id]->getLine();
  85. $prevLineNumber = $currentLineNumber - 1;
  86. for ($i = $this->id - 1; $i; $i--) {
  87. if (!isset($tokens[$i])) {
  88. return;
  89. }
  90. if ($tokens[$i] instanceof PHP_Token_FUNCTION ||
  91. $tokens[$i] instanceof PHP_Token_CLASS ||
  92. $tokens[$i] instanceof PHP_Token_TRAIT) {
  93. // Some other trait, class or function, no docblock can be
  94. // used for the current token
  95. break;
  96. }
  97. $line = $tokens[$i]->getLine();
  98. if ($line == $currentLineNumber ||
  99. ($line == $prevLineNumber &&
  100. $tokens[$i] instanceof PHP_Token_WHITESPACE)) {
  101. continue;
  102. }
  103. if ($line < $currentLineNumber &&
  104. !$tokens[$i] instanceof PHP_Token_DOC_COMMENT) {
  105. break;
  106. }
  107. return (string) $tokens[$i];
  108. }
  109. }
  110. /**
  111. * @return int
  112. */
  113. public function getEndTokenId()
  114. {
  115. $block = 0;
  116. $i = $this->id;
  117. $tokens = $this->tokenStream->tokens();
  118. while ($this->endTokenId === null && isset($tokens[$i])) {
  119. if ($tokens[$i] instanceof PHP_Token_OPEN_CURLY ||
  120. $tokens[$i] instanceof PHP_Token_DOLLAR_OPEN_CURLY_BRACES ||
  121. $tokens[$i] instanceof PHP_Token_CURLY_OPEN) {
  122. $block++;
  123. } elseif ($tokens[$i] instanceof PHP_Token_CLOSE_CURLY) {
  124. $block--;
  125. if ($block === 0) {
  126. $this->endTokenId = $i;
  127. }
  128. } elseif (($this instanceof PHP_Token_FUNCTION ||
  129. $this instanceof PHP_Token_NAMESPACE) &&
  130. $tokens[$i] instanceof PHP_Token_SEMICOLON) {
  131. if ($block === 0) {
  132. $this->endTokenId = $i;
  133. }
  134. }
  135. $i++;
  136. }
  137. if ($this->endTokenId === null) {
  138. $this->endTokenId = $this->id;
  139. }
  140. return $this->endTokenId;
  141. }
  142. /**
  143. * @return int
  144. */
  145. public function getEndLine()
  146. {
  147. return $this->tokenStream[$this->getEndTokenId()]->getLine();
  148. }
  149. }
  150. abstract class PHP_TokenWithScopeAndVisibility extends PHP_TokenWithScope
  151. {
  152. /**
  153. * @return string
  154. */
  155. public function getVisibility()
  156. {
  157. $tokens = $this->tokenStream->tokens();
  158. for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) {
  159. if (isset($tokens[$i]) &&
  160. ($tokens[$i] instanceof PHP_Token_PRIVATE ||
  161. $tokens[$i] instanceof PHP_Token_PROTECTED ||
  162. $tokens[$i] instanceof PHP_Token_PUBLIC)) {
  163. return strtolower(
  164. str_replace('PHP_Token_', '', PHP_Token_Util::getClass($tokens[$i]))
  165. );
  166. }
  167. if (isset($tokens[$i]) &&
  168. !($tokens[$i] instanceof PHP_Token_STATIC ||
  169. $tokens[$i] instanceof PHP_Token_FINAL ||
  170. $tokens[$i] instanceof PHP_Token_ABSTRACT)) {
  171. // no keywords; stop visibility search
  172. break;
  173. }
  174. }
  175. }
  176. /**
  177. * @return string
  178. */
  179. public function getKeywords()
  180. {
  181. $keywords = [];
  182. $tokens = $this->tokenStream->tokens();
  183. for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) {
  184. if (isset($tokens[$i]) &&
  185. ($tokens[$i] instanceof PHP_Token_PRIVATE ||
  186. $tokens[$i] instanceof PHP_Token_PROTECTED ||
  187. $tokens[$i] instanceof PHP_Token_PUBLIC)) {
  188. continue;
  189. }
  190. if (isset($tokens[$i]) &&
  191. ($tokens[$i] instanceof PHP_Token_STATIC ||
  192. $tokens[$i] instanceof PHP_Token_FINAL ||
  193. $tokens[$i] instanceof PHP_Token_ABSTRACT)) {
  194. $keywords[] = strtolower(
  195. str_replace('PHP_Token_', '', PHP_Token_Util::getClass($tokens[$i]))
  196. );
  197. }
  198. }
  199. return implode(',', $keywords);
  200. }
  201. }
  202. abstract class PHP_Token_Includes extends PHP_Token
  203. {
  204. /**
  205. * @var string
  206. */
  207. protected $name;
  208. /**
  209. * @var string
  210. */
  211. protected $type;
  212. /**
  213. * @return string
  214. */
  215. public function getName()
  216. {
  217. if ($this->name === null) {
  218. $this->process();
  219. }
  220. return $this->name;
  221. }
  222. /**
  223. * @return string
  224. */
  225. public function getType()
  226. {
  227. if ($this->type === null) {
  228. $this->process();
  229. }
  230. return $this->type;
  231. }
  232. private function process()
  233. {
  234. $tokens = $this->tokenStream->tokens();
  235. if ($tokens[$this->id + 2] instanceof PHP_Token_CONSTANT_ENCAPSED_STRING) {
  236. $this->name = trim($tokens[$this->id + 2], "'\"");
  237. $this->type = strtolower(
  238. str_replace('PHP_Token_', '', PHP_Token_Util::getClass($tokens[$this->id]))
  239. );
  240. }
  241. }
  242. }
  243. class PHP_Token_FUNCTION extends PHP_TokenWithScopeAndVisibility
  244. {
  245. /**
  246. * @var array
  247. */
  248. protected $arguments;
  249. /**
  250. * @var int
  251. */
  252. protected $ccn;
  253. /**
  254. * @var string
  255. */
  256. protected $name;
  257. /**
  258. * @var string
  259. */
  260. protected $signature;
  261. /**
  262. * @var bool
  263. */
  264. private $anonymous = false;
  265. /**
  266. * @return array
  267. */
  268. public function getArguments()
  269. {
  270. if ($this->arguments !== null) {
  271. return $this->arguments;
  272. }
  273. $this->arguments = [];
  274. $tokens = $this->tokenStream->tokens();
  275. $typeDeclaration = null;
  276. // Search for first token inside brackets
  277. $i = $this->id + 2;
  278. while (!$tokens[$i - 1] instanceof PHP_Token_OPEN_BRACKET) {
  279. $i++;
  280. }
  281. while (!$tokens[$i] instanceof PHP_Token_CLOSE_BRACKET) {
  282. if ($tokens[$i] instanceof PHP_Token_STRING) {
  283. $typeDeclaration = (string) $tokens[$i];
  284. } elseif ($tokens[$i] instanceof PHP_Token_VARIABLE) {
  285. $this->arguments[(string) $tokens[$i]] = $typeDeclaration;
  286. $typeDeclaration = null;
  287. }
  288. $i++;
  289. }
  290. return $this->arguments;
  291. }
  292. /**
  293. * @return string
  294. */
  295. public function getName()
  296. {
  297. if ($this->name !== null) {
  298. return $this->name;
  299. }
  300. $tokens = $this->tokenStream->tokens();
  301. $i = $this->id + 1;
  302. if ($tokens[$i] instanceof PHP_Token_WHITESPACE) {
  303. $i++;
  304. }
  305. if ($tokens[$i] instanceof PHP_Token_AMPERSAND) {
  306. $i++;
  307. }
  308. if ($tokens[$i + 1] instanceof PHP_Token_OPEN_BRACKET) {
  309. $this->name = (string) $tokens[$i];
  310. } elseif ($tokens[$i + 1] instanceof PHP_Token_WHITESPACE && $tokens[$i + 2] instanceof PHP_Token_OPEN_BRACKET) {
  311. $this->name = (string) $tokens[$i];
  312. } else {
  313. $this->anonymous = true;
  314. $this->name = sprintf(
  315. 'anonymousFunction:%s#%s',
  316. $this->getLine(),
  317. $this->getId()
  318. );
  319. }
  320. if (!$this->isAnonymous()) {
  321. for ($i = $this->id; $i; --$i) {
  322. if ($tokens[$i] instanceof PHP_Token_NAMESPACE) {
  323. $this->name = $tokens[$i]->getName() . '\\' . $this->name;
  324. break;
  325. }
  326. if ($tokens[$i] instanceof PHP_Token_INTERFACE) {
  327. break;
  328. }
  329. }
  330. }
  331. return $this->name;
  332. }
  333. /**
  334. * @return int
  335. */
  336. public function getCCN()
  337. {
  338. if ($this->ccn !== null) {
  339. return $this->ccn;
  340. }
  341. $this->ccn = 1;
  342. $end = $this->getEndTokenId();
  343. $tokens = $this->tokenStream->tokens();
  344. for ($i = $this->id; $i <= $end; $i++) {
  345. switch (PHP_Token_Util::getClass($tokens[$i])) {
  346. case 'PHP_Token_IF':
  347. case 'PHP_Token_ELSEIF':
  348. case 'PHP_Token_FOR':
  349. case 'PHP_Token_FOREACH':
  350. case 'PHP_Token_WHILE':
  351. case 'PHP_Token_CASE':
  352. case 'PHP_Token_CATCH':
  353. case 'PHP_Token_BOOLEAN_AND':
  354. case 'PHP_Token_LOGICAL_AND':
  355. case 'PHP_Token_BOOLEAN_OR':
  356. case 'PHP_Token_LOGICAL_OR':
  357. case 'PHP_Token_QUESTION_MARK':
  358. $this->ccn++;
  359. break;
  360. }
  361. }
  362. return $this->ccn;
  363. }
  364. /**
  365. * @return string
  366. */
  367. public function getSignature()
  368. {
  369. if ($this->signature !== null) {
  370. return $this->signature;
  371. }
  372. if ($this->isAnonymous()) {
  373. $this->signature = 'anonymousFunction';
  374. $i = $this->id + 1;
  375. } else {
  376. $this->signature = '';
  377. $i = $this->id + 2;
  378. }
  379. $tokens = $this->tokenStream->tokens();
  380. while (isset($tokens[$i]) &&
  381. !$tokens[$i] instanceof PHP_Token_OPEN_CURLY &&
  382. !$tokens[$i] instanceof PHP_Token_SEMICOLON) {
  383. $this->signature .= $tokens[$i++];
  384. }
  385. $this->signature = trim($this->signature);
  386. return $this->signature;
  387. }
  388. /**
  389. * @return bool
  390. */
  391. public function isAnonymous()
  392. {
  393. return $this->anonymous;
  394. }
  395. }
  396. class PHP_Token_INTERFACE extends PHP_TokenWithScopeAndVisibility
  397. {
  398. /**
  399. * @var array
  400. */
  401. protected $interfaces;
  402. /**
  403. * @return string
  404. */
  405. public function getName()
  406. {
  407. return (string) $this->tokenStream[$this->id + 2];
  408. }
  409. /**
  410. * @return bool
  411. */
  412. public function hasParent()
  413. {
  414. return $this->tokenStream[$this->id + 4] instanceof PHP_Token_EXTENDS;
  415. }
  416. /**
  417. * @return array
  418. */
  419. public function getPackage()
  420. {
  421. $className = $this->getName();
  422. $docComment = $this->getDocblock();
  423. $result = [
  424. 'namespace' => '',
  425. 'fullPackage' => '',
  426. 'category' => '',
  427. 'package' => '',
  428. 'subpackage' => ''
  429. ];
  430. for ($i = $this->id; $i; --$i) {
  431. if ($this->tokenStream[$i] instanceof PHP_Token_NAMESPACE) {
  432. $result['namespace'] = $this->tokenStream[$i]->getName();
  433. break;
  434. }
  435. }
  436. if (preg_match('/@category[\s]+([\.\w]+)/', $docComment, $matches)) {
  437. $result['category'] = $matches[1];
  438. }
  439. if (preg_match('/@package[\s]+([\.\w]+)/', $docComment, $matches)) {
  440. $result['package'] = $matches[1];
  441. $result['fullPackage'] = $matches[1];
  442. }
  443. if (preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) {
  444. $result['subpackage'] = $matches[1];
  445. $result['fullPackage'] .= '.' . $matches[1];
  446. }
  447. if (empty($result['fullPackage'])) {
  448. $result['fullPackage'] = $this->arrayToName(
  449. explode('_', str_replace('\\', '_', $className)),
  450. '.'
  451. );
  452. }
  453. return $result;
  454. }
  455. /**
  456. * @param array $parts
  457. * @param string $join
  458. *
  459. * @return string
  460. */
  461. protected function arrayToName(array $parts, $join = '\\')
  462. {
  463. $result = '';
  464. if (count($parts) > 1) {
  465. array_pop($parts);
  466. $result = implode($join, $parts);
  467. }
  468. return $result;
  469. }
  470. /**
  471. * @return bool|string
  472. */
  473. public function getParent()
  474. {
  475. if (!$this->hasParent()) {
  476. return false;
  477. }
  478. $i = $this->id + 6;
  479. $tokens = $this->tokenStream->tokens();
  480. $className = (string) $tokens[$i];
  481. while (isset($tokens[$i + 1]) &&
  482. !$tokens[$i + 1] instanceof PHP_Token_WHITESPACE) {
  483. $className .= (string) $tokens[++$i];
  484. }
  485. return $className;
  486. }
  487. /**
  488. * @return bool
  489. */
  490. public function hasInterfaces()
  491. {
  492. return (isset($this->tokenStream[$this->id + 4]) &&
  493. $this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) ||
  494. (isset($this->tokenStream[$this->id + 8]) &&
  495. $this->tokenStream[$this->id + 8] instanceof PHP_Token_IMPLEMENTS);
  496. }
  497. /**
  498. * @return array|bool
  499. */
  500. public function getInterfaces()
  501. {
  502. if ($this->interfaces !== null) {
  503. return $this->interfaces;
  504. }
  505. if (!$this->hasInterfaces()) {
  506. return ($this->interfaces = false);
  507. }
  508. if ($this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) {
  509. $i = $this->id + 3;
  510. } else {
  511. $i = $this->id + 7;
  512. }
  513. $tokens = $this->tokenStream->tokens();
  514. while (!$tokens[$i + 1] instanceof PHP_Token_OPEN_CURLY) {
  515. $i++;
  516. if ($tokens[$i] instanceof PHP_Token_STRING) {
  517. $this->interfaces[] = (string) $tokens[$i];
  518. }
  519. }
  520. return $this->interfaces;
  521. }
  522. }
  523. class PHP_Token_ABSTRACT extends PHP_Token
  524. {
  525. }
  526. class PHP_Token_AMPERSAND extends PHP_Token
  527. {
  528. }
  529. class PHP_Token_AND_EQUAL extends PHP_Token
  530. {
  531. }
  532. class PHP_Token_ARRAY extends PHP_Token
  533. {
  534. }
  535. class PHP_Token_ARRAY_CAST extends PHP_Token
  536. {
  537. }
  538. class PHP_Token_AS extends PHP_Token
  539. {
  540. }
  541. class PHP_Token_AT extends PHP_Token
  542. {
  543. }
  544. class PHP_Token_BACKTICK extends PHP_Token
  545. {
  546. }
  547. class PHP_Token_BAD_CHARACTER extends PHP_Token
  548. {
  549. }
  550. class PHP_Token_BOOLEAN_AND extends PHP_Token
  551. {
  552. }
  553. class PHP_Token_BOOLEAN_OR extends PHP_Token
  554. {
  555. }
  556. class PHP_Token_BOOL_CAST extends PHP_Token
  557. {
  558. }
  559. class PHP_Token_BREAK extends PHP_Token
  560. {
  561. }
  562. class PHP_Token_CARET extends PHP_Token
  563. {
  564. }
  565. class PHP_Token_CASE extends PHP_Token
  566. {
  567. }
  568. class PHP_Token_CATCH extends PHP_Token
  569. {
  570. }
  571. class PHP_Token_CHARACTER extends PHP_Token
  572. {
  573. }
  574. class PHP_Token_CLASS extends PHP_Token_INTERFACE
  575. {
  576. /**
  577. * @var bool
  578. */
  579. private $anonymous = false;
  580. /**
  581. * @var string
  582. */
  583. private $name;
  584. /**
  585. * @return string
  586. */
  587. public function getName()
  588. {
  589. if ($this->name !== null) {
  590. return $this->name;
  591. }
  592. $next = $this->tokenStream[$this->id + 1];
  593. if ($next instanceof PHP_Token_WHITESPACE) {
  594. $next = $this->tokenStream[$this->id + 2];
  595. }
  596. if ($next instanceof PHP_Token_STRING) {
  597. $this->name =(string) $next;
  598. return $this->name;
  599. }
  600. if ($next instanceof PHP_Token_OPEN_CURLY ||
  601. $next instanceof PHP_Token_EXTENDS ||
  602. $next instanceof PHP_Token_IMPLEMENTS) {
  603. $this->name = sprintf(
  604. 'AnonymousClass:%s#%s',
  605. $this->getLine(),
  606. $this->getId()
  607. );
  608. $this->anonymous = true;
  609. return $this->name;
  610. }
  611. }
  612. public function isAnonymous()
  613. {
  614. return $this->anonymous;
  615. }
  616. }
  617. class PHP_Token_CLASS_C extends PHP_Token
  618. {
  619. }
  620. class PHP_Token_CLASS_NAME_CONSTANT extends PHP_Token
  621. {
  622. }
  623. class PHP_Token_CLONE extends PHP_Token
  624. {
  625. }
  626. class PHP_Token_CLOSE_BRACKET extends PHP_Token
  627. {
  628. }
  629. class PHP_Token_CLOSE_CURLY extends PHP_Token
  630. {
  631. }
  632. class PHP_Token_CLOSE_SQUARE extends PHP_Token
  633. {
  634. }
  635. class PHP_Token_CLOSE_TAG extends PHP_Token
  636. {
  637. }
  638. class PHP_Token_COLON extends PHP_Token
  639. {
  640. }
  641. class PHP_Token_COMMA extends PHP_Token
  642. {
  643. }
  644. class PHP_Token_COMMENT extends PHP_Token
  645. {
  646. }
  647. class PHP_Token_CONCAT_EQUAL extends PHP_Token
  648. {
  649. }
  650. class PHP_Token_CONST extends PHP_Token
  651. {
  652. }
  653. class PHP_Token_CONSTANT_ENCAPSED_STRING extends PHP_Token
  654. {
  655. }
  656. class PHP_Token_CONTINUE extends PHP_Token
  657. {
  658. }
  659. class PHP_Token_CURLY_OPEN extends PHP_Token
  660. {
  661. }
  662. class PHP_Token_DEC extends PHP_Token
  663. {
  664. }
  665. class PHP_Token_DECLARE extends PHP_Token
  666. {
  667. }
  668. class PHP_Token_DEFAULT extends PHP_Token
  669. {
  670. }
  671. class PHP_Token_DIV extends PHP_Token
  672. {
  673. }
  674. class PHP_Token_DIV_EQUAL extends PHP_Token
  675. {
  676. }
  677. class PHP_Token_DNUMBER extends PHP_Token
  678. {
  679. }
  680. class PHP_Token_DO extends PHP_Token
  681. {
  682. }
  683. class PHP_Token_DOC_COMMENT extends PHP_Token
  684. {
  685. }
  686. class PHP_Token_DOLLAR extends PHP_Token
  687. {
  688. }
  689. class PHP_Token_DOLLAR_OPEN_CURLY_BRACES extends PHP_Token
  690. {
  691. }
  692. class PHP_Token_DOT extends PHP_Token
  693. {
  694. }
  695. class PHP_Token_DOUBLE_ARROW extends PHP_Token
  696. {
  697. }
  698. class PHP_Token_DOUBLE_CAST extends PHP_Token
  699. {
  700. }
  701. class PHP_Token_DOUBLE_COLON extends PHP_Token
  702. {
  703. }
  704. class PHP_Token_DOUBLE_QUOTES extends PHP_Token
  705. {
  706. }
  707. class PHP_Token_ECHO extends PHP_Token
  708. {
  709. }
  710. class PHP_Token_ELSE extends PHP_Token
  711. {
  712. }
  713. class PHP_Token_ELSEIF extends PHP_Token
  714. {
  715. }
  716. class PHP_Token_EMPTY extends PHP_Token
  717. {
  718. }
  719. class PHP_Token_ENCAPSED_AND_WHITESPACE extends PHP_Token
  720. {
  721. }
  722. class PHP_Token_ENDDECLARE extends PHP_Token
  723. {
  724. }
  725. class PHP_Token_ENDFOR extends PHP_Token
  726. {
  727. }
  728. class PHP_Token_ENDFOREACH extends PHP_Token
  729. {
  730. }
  731. class PHP_Token_ENDIF extends PHP_Token
  732. {
  733. }
  734. class PHP_Token_ENDSWITCH extends PHP_Token
  735. {
  736. }
  737. class PHP_Token_ENDWHILE extends PHP_Token
  738. {
  739. }
  740. class PHP_Token_END_HEREDOC extends PHP_Token
  741. {
  742. }
  743. class PHP_Token_EQUAL extends PHP_Token
  744. {
  745. }
  746. class PHP_Token_EVAL extends PHP_Token
  747. {
  748. }
  749. class PHP_Token_EXCLAMATION_MARK extends PHP_Token
  750. {
  751. }
  752. class PHP_Token_EXIT extends PHP_Token
  753. {
  754. }
  755. class PHP_Token_EXTENDS extends PHP_Token
  756. {
  757. }
  758. class PHP_Token_FILE extends PHP_Token
  759. {
  760. }
  761. class PHP_Token_FINAL extends PHP_Token
  762. {
  763. }
  764. class PHP_Token_FOR extends PHP_Token
  765. {
  766. }
  767. class PHP_Token_FOREACH extends PHP_Token
  768. {
  769. }
  770. class PHP_Token_FUNC_C extends PHP_Token
  771. {
  772. }
  773. class PHP_Token_GLOBAL extends PHP_Token
  774. {
  775. }
  776. class PHP_Token_GT extends PHP_Token
  777. {
  778. }
  779. class PHP_Token_IF extends PHP_Token
  780. {
  781. }
  782. class PHP_Token_IMPLEMENTS extends PHP_Token
  783. {
  784. }
  785. class PHP_Token_INC extends PHP_Token
  786. {
  787. }
  788. class PHP_Token_INCLUDE extends PHP_Token_Includes
  789. {
  790. }
  791. class PHP_Token_INCLUDE_ONCE extends PHP_Token_Includes
  792. {
  793. }
  794. class PHP_Token_INLINE_HTML extends PHP_Token
  795. {
  796. }
  797. class PHP_Token_INSTANCEOF extends PHP_Token
  798. {
  799. }
  800. class PHP_Token_INT_CAST extends PHP_Token
  801. {
  802. }
  803. class PHP_Token_ISSET extends PHP_Token
  804. {
  805. }
  806. class PHP_Token_IS_EQUAL extends PHP_Token
  807. {
  808. }
  809. class PHP_Token_IS_GREATER_OR_EQUAL extends PHP_Token
  810. {
  811. }
  812. class PHP_Token_IS_IDENTICAL extends PHP_Token
  813. {
  814. }
  815. class PHP_Token_IS_NOT_EQUAL extends PHP_Token
  816. {
  817. }
  818. class PHP_Token_IS_NOT_IDENTICAL extends PHP_Token
  819. {
  820. }
  821. class PHP_Token_IS_SMALLER_OR_EQUAL extends PHP_Token
  822. {
  823. }
  824. class PHP_Token_LINE extends PHP_Token
  825. {
  826. }
  827. class PHP_Token_LIST extends PHP_Token
  828. {
  829. }
  830. class PHP_Token_LNUMBER extends PHP_Token
  831. {
  832. }
  833. class PHP_Token_LOGICAL_AND extends PHP_Token
  834. {
  835. }
  836. class PHP_Token_LOGICAL_OR extends PHP_Token
  837. {
  838. }
  839. class PHP_Token_LOGICAL_XOR extends PHP_Token
  840. {
  841. }
  842. class PHP_Token_LT extends PHP_Token
  843. {
  844. }
  845. class PHP_Token_METHOD_C extends PHP_Token
  846. {
  847. }
  848. class PHP_Token_MINUS extends PHP_Token
  849. {
  850. }
  851. class PHP_Token_MINUS_EQUAL extends PHP_Token
  852. {
  853. }
  854. class PHP_Token_MOD_EQUAL extends PHP_Token
  855. {
  856. }
  857. class PHP_Token_MULT extends PHP_Token
  858. {
  859. }
  860. class PHP_Token_MUL_EQUAL extends PHP_Token
  861. {
  862. }
  863. class PHP_Token_NEW extends PHP_Token
  864. {
  865. }
  866. class PHP_Token_NUM_STRING extends PHP_Token
  867. {
  868. }
  869. class PHP_Token_OBJECT_CAST extends PHP_Token
  870. {
  871. }
  872. class PHP_Token_OBJECT_OPERATOR extends PHP_Token
  873. {
  874. }
  875. class PHP_Token_OPEN_BRACKET extends PHP_Token
  876. {
  877. }
  878. class PHP_Token_OPEN_CURLY extends PHP_Token
  879. {
  880. }
  881. class PHP_Token_OPEN_SQUARE extends PHP_Token
  882. {
  883. }
  884. class PHP_Token_OPEN_TAG extends PHP_Token
  885. {
  886. }
  887. class PHP_Token_OPEN_TAG_WITH_ECHO extends PHP_Token
  888. {
  889. }
  890. class PHP_Token_OR_EQUAL extends PHP_Token
  891. {
  892. }
  893. class PHP_Token_PAAMAYIM_NEKUDOTAYIM extends PHP_Token
  894. {
  895. }
  896. class PHP_Token_PERCENT extends PHP_Token
  897. {
  898. }
  899. class PHP_Token_PIPE extends PHP_Token
  900. {
  901. }
  902. class PHP_Token_PLUS extends PHP_Token
  903. {
  904. }
  905. class PHP_Token_PLUS_EQUAL extends PHP_Token
  906. {
  907. }
  908. class PHP_Token_PRINT extends PHP_Token
  909. {
  910. }
  911. class PHP_Token_PRIVATE extends PHP_Token
  912. {
  913. }
  914. class PHP_Token_PROTECTED extends PHP_Token
  915. {
  916. }
  917. class PHP_Token_PUBLIC extends PHP_Token
  918. {
  919. }
  920. class PHP_Token_QUESTION_MARK extends PHP_Token
  921. {
  922. }
  923. class PHP_Token_REQUIRE extends PHP_Token_Includes
  924. {
  925. }
  926. class PHP_Token_REQUIRE_ONCE extends PHP_Token_Includes
  927. {
  928. }
  929. class PHP_Token_RETURN extends PHP_Token
  930. {
  931. }
  932. class PHP_Token_SEMICOLON extends PHP_Token
  933. {
  934. }
  935. class PHP_Token_SL extends PHP_Token
  936. {
  937. }
  938. class PHP_Token_SL_EQUAL extends PHP_Token
  939. {
  940. }
  941. class PHP_Token_SR extends PHP_Token
  942. {
  943. }
  944. class PHP_Token_SR_EQUAL extends PHP_Token
  945. {
  946. }
  947. class PHP_Token_START_HEREDOC extends PHP_Token
  948. {
  949. }
  950. class PHP_Token_STATIC extends PHP_Token
  951. {
  952. }
  953. class PHP_Token_STRING extends PHP_Token
  954. {
  955. }
  956. class PHP_Token_STRING_CAST extends PHP_Token
  957. {
  958. }
  959. class PHP_Token_STRING_VARNAME extends PHP_Token
  960. {
  961. }
  962. class PHP_Token_SWITCH extends PHP_Token
  963. {
  964. }
  965. class PHP_Token_THROW extends PHP_Token
  966. {
  967. }
  968. class PHP_Token_TILDE extends PHP_Token
  969. {
  970. }
  971. class PHP_Token_TRY extends PHP_Token
  972. {
  973. }
  974. class PHP_Token_UNSET extends PHP_Token
  975. {
  976. }
  977. class PHP_Token_UNSET_CAST extends PHP_Token
  978. {
  979. }
  980. class PHP_Token_USE extends PHP_Token
  981. {
  982. }
  983. class PHP_Token_USE_FUNCTION extends PHP_Token
  984. {
  985. }
  986. class PHP_Token_VAR extends PHP_Token
  987. {
  988. }
  989. class PHP_Token_VARIABLE extends PHP_Token
  990. {
  991. }
  992. class PHP_Token_WHILE extends PHP_Token
  993. {
  994. }
  995. class PHP_Token_WHITESPACE extends PHP_Token
  996. {
  997. }
  998. class PHP_Token_XOR_EQUAL extends PHP_Token
  999. {
  1000. }
  1001. // Tokens introduced in PHP 5.1
  1002. class PHP_Token_HALT_COMPILER extends PHP_Token
  1003. {
  1004. }
  1005. // Tokens introduced in PHP 5.3
  1006. class PHP_Token_DIR extends PHP_Token
  1007. {
  1008. }
  1009. class PHP_Token_GOTO extends PHP_Token
  1010. {
  1011. }
  1012. class PHP_Token_NAMESPACE extends PHP_TokenWithScope
  1013. {
  1014. /**
  1015. * @return string
  1016. */
  1017. public function getName()
  1018. {
  1019. $tokens = $this->tokenStream->tokens();
  1020. $namespace = (string) $tokens[$this->id + 2];
  1021. for ($i = $this->id + 3;; $i += 2) {
  1022. if (isset($tokens[$i]) &&
  1023. $tokens[$i] instanceof PHP_Token_NS_SEPARATOR) {
  1024. $namespace .= '\\' . $tokens[$i + 1];
  1025. } else {
  1026. break;
  1027. }
  1028. }
  1029. return $namespace;
  1030. }
  1031. }
  1032. class PHP_Token_NS_C extends PHP_Token
  1033. {
  1034. }
  1035. class PHP_Token_NS_SEPARATOR extends PHP_Token
  1036. {
  1037. }
  1038. // Tokens introduced in PHP 5.4
  1039. class PHP_Token_CALLABLE extends PHP_Token
  1040. {
  1041. }
  1042. class PHP_Token_INSTEADOF extends PHP_Token
  1043. {
  1044. }
  1045. class PHP_Token_TRAIT extends PHP_Token_INTERFACE
  1046. {
  1047. }
  1048. class PHP_Token_TRAIT_C extends PHP_Token
  1049. {
  1050. }
  1051. // Tokens introduced in PHP 5.5
  1052. class PHP_Token_FINALLY extends PHP_Token
  1053. {
  1054. }
  1055. class PHP_Token_YIELD extends PHP_Token
  1056. {
  1057. }
  1058. // Tokens introduced in PHP 5.6
  1059. class PHP_Token_ELLIPSIS extends PHP_Token
  1060. {
  1061. }
  1062. class PHP_Token_POW extends PHP_Token
  1063. {
  1064. }
  1065. class PHP_Token_POW_EQUAL extends PHP_Token
  1066. {
  1067. }
  1068. // Tokens introduced in PHP 7.0
  1069. class PHP_Token_COALESCE extends PHP_Token
  1070. {
  1071. }
  1072. class PHP_Token_SPACESHIP extends PHP_Token
  1073. {
  1074. }
  1075. class PHP_Token_YIELD_FROM extends PHP_Token
  1076. {
  1077. }
  1078. // Tokens introduced in PHP 7.4
  1079. class PHP_Token_COALESCE_EQUAL extends PHP_Token
  1080. {
  1081. }
  1082. class PHP_Token_FN extends PHP_Token
  1083. {
  1084. }