├── .gitattributes ├── .gitignore ├── ChangeLog.md ├── LICENSE ├── README.md ├── composer.json └── src ├── Abstract.php ├── Ampersand.php ├── AndEqual.php ├── Array.php ├── ArrayCast.php ├── As.php ├── At.php ├── Backtick.php ├── BadCharacter.php ├── BoolCast.php ├── BooleanAnd.php ├── BooleanOr.php ├── CachingFactory.php ├── Callable.php ├── Caret.php ├── Case.php ├── Catch.php ├── Character.php ├── Class.php ├── ClassC.php ├── ClassNameConstant.php ├── Clone.php ├── CloseBracket.php ├── CloseCurly.php ├── CloseSquare.php ├── CloseTag.php ├── Coalesce.php ├── CoalesceEqual.php ├── Colon.php ├── Comma.php ├── Comment.php ├── ConcatEqual.php ├── Const.php ├── ConstantEncapsedString.php ├── Continue.php ├── CurlyOpen.php ├── DNumber.php ├── Dec.php ├── Declare.php ├── Default.php ├── Dir.php ├── Div.php ├── DivEqual.php ├── Do.php ├── DocComment.php ├── Dollar.php ├── DollarOpenCurlyBraces.php ├── Dot.php ├── DoubleArrow.php ├── DoubleCast.php ├── DoubleColon.php ├── DoubleQuotes.php ├── Echo.php ├── Ellipsis.php ├── Else.php ├── Elseif.php ├── Empty.php ├── EncapsedAndWhitespace.php ├── EndHeredoc.php ├── Enddeclare.php ├── Endfor.php ├── Endforeach.php ├── Endif.php ├── Endswitch.php ├── Endwhile.php ├── Equal.php ├── Eval.php ├── ExclamationMark.php ├── Exit.php ├── Extends.php ├── File.php ├── Final.php ├── Finally.php ├── Fn.php ├── For.php ├── Foreach.php ├── FuncC.php ├── Function.php ├── Global.php ├── Goto.php ├── Gt.php ├── HaltCompiler.php ├── If.php ├── Implements.php ├── Inc.php ├── Include.php ├── IncludeOnce.php ├── Includes.php ├── InlineHtml.php ├── Instanceof.php ├── Insteadof.php ├── IntCast.php ├── Interface.php ├── IsEqual.php ├── IsGreaterOrEqual.php ├── IsIdentical.php ├── IsNotEqual.php ├── IsNotIdentical.php ├── IsSmallerOrEqual.php ├── Isset.php ├── Line.php ├── List.php ├── Lnumber.php ├── LogicalAnd.php ├── LogicalOr.php ├── LogicalXor.php ├── Lt.php ├── MethodC.php ├── Minus.php ├── MinusEqual.php ├── ModEqual.php ├── MulEqual.php ├── Mult.php ├── NameFullyQualified.php ├── NameQualified.php ├── NameRelative.php ├── Namespace.php ├── New.php ├── NsC.php ├── NsSeparator.php ├── NumString.php ├── ObjectCast.php ├── ObjectOperator.php ├── OpenBracket.php ├── OpenCurly.php ├── OpenSquare.php ├── OpenTag.php ├── OpenTagWithEcho.php ├── OrEqual.php ├── PaamayimNekudotayim.php ├── Percent.php ├── Pipe.php ├── Plus.php ├── PlusEqual.php ├── Pow.php ├── PowEqual.php ├── Print.php ├── Private.php ├── Protected.php ├── Public.php ├── QuestionMark.php ├── Require.php ├── RequireOnce.php ├── Return.php ├── Semicolon.php ├── Sl.php ├── SlEqual.php ├── Spaceship.php ├── Sr.php ├── SrEqual.php ├── StartHeredoc.php ├── Static.php ├── Stream.php ├── String.php ├── StringCast.php ├── StringVarname.php ├── Switch.php ├── Throw.php ├── Tilde.php ├── Token.php ├── TokenWithScope.php ├── TokenWithScopeAndVisibility.php ├── Trait.php ├── TraitC.php ├── Try.php ├── Unset.php ├── UnsetCast.php ├── Use.php ├── UseFunction.php ├── Util.php ├── Var.php ├── Variable.php ├── While.php ├── Whitespace.php ├── XorEqual.php ├── Yield.php ├── YieldFrom.php └── break.php /.gitattributes: -------------------------------------------------------------------------------- 1 | /.github export-ignore 2 | /.phive export-ignore 3 | /.php_cs.dist export-ignore 4 | /.psalm export-ignore 5 | /bin export-ignore 6 | /build.xml export-ignore 7 | /phpunit.xml export-ignore 8 | /tests export-ignore 9 | /tools export-ignore 10 | /tools/* binary 11 | 12 | *.php diff=php 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /.php_cs 3 | /.php_cs.cache 4 | /.phpunit.result.cache 5 | /.psalm/cache 6 | /composer.lock 7 | /vendor 8 | -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to `sebastianbergmann/php-token-stream` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. 4 | 5 | ## [4.0.4] - 2020-08-04 6 | 7 | ### Added 8 | 9 | * Support for `NAME_FULLY_QUALIFIED`, `NAME_QUALIFIED`, and `NAME_RELATIVE` tokens 10 | 11 | ## [4.0.3] - 2020-06-27 12 | 13 | ### Added 14 | 15 | * This component is now supported on PHP 8 16 | 17 | ## [4.0.2] - 2020-06-16 18 | 19 | ### Fixed 20 | 21 | * Fixed backward compatibility breaks introduced in version 4.0.1 22 | 23 | ## [4.0.1] - 2020-05-06 24 | 25 | ### Fixed 26 | 27 | * [#93](https://github.com/sebastianbergmann/php-token-stream/issues/93): Class with method that uses anonymous class is not processed correctly 28 | 29 | ## [4.0.0] - 2020-02-07 30 | 31 | ### Removed 32 | 33 | * This component is no longer supported PHP 7.1 and PHP 7.2 34 | 35 | ## [3.1.1] - 2019-09-17 36 | 37 | ### Fixed 38 | 39 | * [#84](https://github.com/sebastianbergmann/php-token-stream/issues/84): Methods named `class` are not handled correctly 40 | 41 | ## [3.1.0] - 2019-07-25 42 | 43 | ### Added 44 | 45 | * Added support for `FN` and `COALESCE_EQUAL` tokens introduced in PHP 7.4 46 | 47 | ## [3.0.2] - 2019-07-08 48 | 49 | ### Changed 50 | 51 | * [#82](https://github.com/sebastianbergmann/php-token-stream/issues/82): Make sure this component works when its classes are prefixed using php-scoper 52 | 53 | ## [3.0.1] - 2018-10-30 54 | 55 | ### Fixed 56 | 57 | * [#78](https://github.com/sebastianbergmann/php-token-stream/pull/78): `getEndTokenId()` does not handle string-dollar (`"${var}"`) interpolation 58 | 59 | ## [3.0.0] - 2018-02-01 60 | 61 | ### Removed 62 | 63 | * [#71](https://github.com/sebastianbergmann/php-token-stream/issues/71): Remove code specific to Hack language constructs 64 | * [#72](https://github.com/sebastianbergmann/php-token-stream/issues/72): Drop support for PHP 7.0 65 | 66 | ## [2.0.2] - 2017-11-27 67 | 68 | ### Fixed 69 | 70 | * [#69](https://github.com/sebastianbergmann/php-token-stream/issues/69): `PHP_Token_USE_FUNCTION` does not serialize correctly 71 | 72 | ## [2.0.1] - 2017-08-20 73 | 74 | ### Fixed 75 | 76 | * [#68](https://github.com/sebastianbergmann/php-token-stream/issues/68): Method with name `empty` wrongly recognized as anonymous function 77 | 78 | ## [2.0.0] - 2017-08-03 79 | 80 | [4.0.4]: https://github.com/sebastianbergmann/php-token-stream/compare/4.0.3...4.0.4 81 | [4.0.3]: https://github.com/sebastianbergmann/php-token-stream/compare/4.0.2...4.0.3 82 | [4.0.2]: https://github.com/sebastianbergmann/php-token-stream/compare/4.0.1...4.0.2 83 | [4.0.1]: https://github.com/sebastianbergmann/php-token-stream/compare/4.0.0...4.0.1 84 | [4.0.0]: https://github.com/sebastianbergmann/php-token-stream/compare/3.1.1...4.0.0 85 | [3.1.1]: https://github.com/sebastianbergmann/php-token-stream/compare/3.1.0...3.1.1 86 | [3.1.0]: https://github.com/sebastianbergmann/php-token-stream/compare/3.0.2...3.1.0 87 | [3.0.2]: https://github.com/sebastianbergmann/php-token-stream/compare/3.0.1...3.0.2 88 | [3.0.1]: https://github.com/sebastianbergmann/php-token-stream/compare/3.0.0...3.0.1 89 | [3.0.0]: https://github.com/sebastianbergmann/php-token-stream/compare/2.0...3.0.0 90 | [2.0.2]: https://github.com/sebastianbergmann/php-token-stream/compare/2.0.1...2.0.2 91 | [2.0.1]: https://github.com/sebastianbergmann/php-token-stream/compare/2.0.0...2.0.1 92 | [2.0.0]: https://github.com/sebastianbergmann/php-token-stream/compare/1.4.11...2.0.0 93 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | php-token-stream 2 | 3 | Copyright (c) 2009-2020, Sebastian Bergmann . 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 18 | * Neither the name of Sebastian Bergmann nor the names of his 19 | contributors may be used to endorse or promote products derived 20 | from this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | POSSIBILITY OF SUCH DAMAGE. 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # phpunit/php-token-stream 2 | 3 | [![CI Status](https://github.com/sebastianbergmann/php-token-stream/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/php-token-stream/actions) 4 | [![Type Coverage](https://shepherd.dev/github/sebastianbergmann/php-token-stream/coverage.svg)](https://shepherd.dev/github/sebastianbergmann/php-token-stream) 5 | 6 | ## Installation 7 | 8 | You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/): 9 | 10 | ``` 11 | composer require phpunit/php-token-stream 12 | ``` 13 | 14 | If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency: 15 | 16 | ``` 17 | composer require --dev phpunit/php-token-stream 18 | ``` 19 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phpunit/php-token-stream", 3 | "description": "Wrapper around PHP's tokenizer extension.", 4 | "type": "library", 5 | "keywords": ["tokenizer"], 6 | "homepage": "https://github.com/sebastianbergmann/php-token-stream/", 7 | "license": "BSD-3-Clause", 8 | "authors": [ 9 | { 10 | "name": "Sebastian Bergmann", 11 | "email": "sebastian@phpunit.de" 12 | } 13 | ], 14 | "support": { 15 | "issues": "https://github.com/sebastianbergmann/php-token-stream/issues" 16 | }, 17 | "prefer-stable": true, 18 | "require": { 19 | "php": "^7.3 || ^8.0", 20 | "ext-tokenizer": "*" 21 | }, 22 | "require-dev": { 23 | "phpunit/phpunit": "^9.0" 24 | }, 25 | "config": { 26 | "platform": { 27 | "php": "7.3.0" 28 | }, 29 | "optimize-autoloader": true, 30 | "sort-packages": true 31 | }, 32 | "autoload": { 33 | "classmap": [ 34 | "src/" 35 | ] 36 | }, 37 | "extra": { 38 | "branch-alias": { 39 | "dev-master": "4.0-dev" 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Abstract.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ABSTRACT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Ampersand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_AMPERSAND extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/AndEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_AND_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Array.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ARRAY extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/ArrayCast.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ARRAY_CAST extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/As.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_AS extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/At.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_AT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Backtick.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_BACKTICK extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/BadCharacter.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_BAD_CHARACTER extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/BoolCast.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_BOOL_CAST extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/BooleanAnd.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_BOOLEAN_AND extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/BooleanOr.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_BOOLEAN_OR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/CachingFactory.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_Stream_CachingFactory 11 | { 12 | /** 13 | * @var array 14 | */ 15 | protected static $cache = []; 16 | 17 | /** 18 | * @param string $filename 19 | * 20 | * @return PHP_Token_Stream 21 | */ 22 | public static function get($filename) 23 | { 24 | if (!isset(self::$cache[$filename])) { 25 | self::$cache[$filename] = new PHP_Token_Stream($filename); 26 | } 27 | 28 | return self::$cache[$filename]; 29 | } 30 | 31 | /** 32 | * @param string $filename 33 | */ 34 | public static function clear($filename = null)/*: void*/ 35 | { 36 | if (\is_string($filename)) { 37 | unset(self::$cache[$filename]); 38 | } else { 39 | self::$cache = []; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Callable.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CALLABLE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Caret.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CARET extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Case.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CASE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Catch.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CATCH extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Character.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CHARACTER extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Class.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CLASS extends PHP_Token_INTERFACE 11 | { 12 | /** 13 | * @var bool 14 | */ 15 | private $anonymous = false; 16 | 17 | /** 18 | * @var string 19 | */ 20 | private $name; 21 | 22 | /** 23 | * @return string 24 | */ 25 | public function getName() 26 | { 27 | if ($this->name !== null) { 28 | return $this->name; 29 | } 30 | 31 | $next = $this->tokenStream[$this->id + 1]; 32 | 33 | if ($next instanceof PHP_Token_WHITESPACE) { 34 | $next = $this->tokenStream[$this->id + 2]; 35 | } 36 | 37 | if ($next instanceof PHP_Token_STRING) { 38 | $this->name =(string) $next; 39 | 40 | return $this->name; 41 | } 42 | 43 | if ($next instanceof PHP_Token_OPEN_CURLY || 44 | $next instanceof PHP_Token_EXTENDS || 45 | $next instanceof PHP_Token_IMPLEMENTS) { 46 | $this->name = \sprintf( 47 | 'AnonymousClass:%s#%s', 48 | $this->getLine(), 49 | $this->getId() 50 | ); 51 | 52 | $this->anonymous = true; 53 | 54 | return $this->name; 55 | } 56 | } 57 | 58 | public function isAnonymous() 59 | { 60 | return $this->anonymous; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/ClassC.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CLASS_C extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/ClassNameConstant.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CLASS_NAME_CONSTANT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Clone.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CLONE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/CloseBracket.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CLOSE_BRACKET extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/CloseCurly.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CLOSE_CURLY extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/CloseSquare.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CLOSE_SQUARE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/CloseTag.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CLOSE_TAG extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Coalesce.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_COALESCE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/CoalesceEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_COALESCE_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Colon.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_COLON extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Comma.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_COMMA extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Comment.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_COMMENT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/ConcatEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CONCAT_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Const.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CONST extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/ConstantEncapsedString.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CONSTANT_ENCAPSED_STRING extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Continue.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CONTINUE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/CurlyOpen.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_CURLY_OPEN extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/DNumber.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DNUMBER extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Dec.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DEC extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Declare.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DECLARE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Default.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DEFAULT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Dir.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DIR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Div.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DIV extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/DivEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DIV_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Do.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DO extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/DocComment.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DOC_COMMENT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Dollar.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DOLLAR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/DollarOpenCurlyBraces.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DOLLAR_OPEN_CURLY_BRACES extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Dot.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DOT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/DoubleArrow.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DOUBLE_ARROW extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/DoubleCast.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DOUBLE_CAST extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/DoubleColon.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DOUBLE_COLON extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/DoubleQuotes.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_DOUBLE_QUOTES extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Echo.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ECHO extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Ellipsis.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ELLIPSIS extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Else.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ELSE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Elseif.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ELSEIF extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Empty.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_EMPTY extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/EncapsedAndWhitespace.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ENCAPSED_AND_WHITESPACE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/EndHeredoc.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_END_HEREDOC extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Enddeclare.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ENDDECLARE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Endfor.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ENDFOR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Endforeach.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ENDFOREACH extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Endif.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ENDIF extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Endswitch.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ENDSWITCH extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Endwhile.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ENDWHILE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Equal.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Eval.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_EVAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/ExclamationMark.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_EXCLAMATION_MARK extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Exit.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_EXIT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Extends.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_EXTENDS extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/File.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_FILE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Final.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_FINAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Finally.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_FINALLY extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Fn.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_FN extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/For.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_FOR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Foreach.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_FOREACH extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/FuncC.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_FUNC_C extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Function.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_FUNCTION extends PHP_TokenWithScopeAndVisibility 11 | { 12 | /** 13 | * @var array 14 | */ 15 | protected $arguments; 16 | 17 | /** 18 | * @var int 19 | */ 20 | protected $ccn; 21 | 22 | /** 23 | * @var string 24 | */ 25 | protected $name; 26 | 27 | /** 28 | * @var string 29 | */ 30 | protected $signature; 31 | 32 | /** 33 | * @var bool 34 | */ 35 | private $anonymous = false; 36 | 37 | /** 38 | * @return array 39 | */ 40 | public function getArguments() 41 | { 42 | if ($this->arguments !== null) { 43 | return $this->arguments; 44 | } 45 | 46 | $this->arguments = []; 47 | $tokens = $this->tokenStream->tokens(); 48 | $typeDeclaration = null; 49 | 50 | // Search for first token inside brackets 51 | $i = $this->id + 2; 52 | 53 | while (!$tokens[$i - 1] instanceof PHP_Token_OPEN_BRACKET) { 54 | $i++; 55 | } 56 | 57 | while (!$tokens[$i] instanceof PHP_Token_CLOSE_BRACKET) { 58 | if ($tokens[$i] instanceof PHP_Token_STRING) { 59 | $typeDeclaration = (string) $tokens[$i]; 60 | } elseif ($tokens[$i] instanceof PHP_Token_VARIABLE) { 61 | $this->arguments[(string) $tokens[$i]] = $typeDeclaration; 62 | $typeDeclaration = null; 63 | } 64 | 65 | $i++; 66 | } 67 | 68 | return $this->arguments; 69 | } 70 | 71 | /** 72 | * @return string 73 | */ 74 | public function getName() 75 | { 76 | if ($this->name !== null) { 77 | return $this->name; 78 | } 79 | 80 | $tokens = $this->tokenStream->tokens(); 81 | 82 | $i = $this->id + 1; 83 | 84 | if ($tokens[$i] instanceof PHP_Token_WHITESPACE) { 85 | $i++; 86 | } 87 | 88 | if ($tokens[$i] instanceof PHP_Token_AMPERSAND) { 89 | $i++; 90 | } 91 | 92 | if ($tokens[$i + 1] instanceof PHP_Token_OPEN_BRACKET) { 93 | $this->name = (string) $tokens[$i]; 94 | } elseif ($tokens[$i + 1] instanceof PHP_Token_WHITESPACE && $tokens[$i + 2] instanceof PHP_Token_OPEN_BRACKET) { 95 | $this->name = (string) $tokens[$i]; 96 | } else { 97 | $this->anonymous = true; 98 | 99 | $this->name = \sprintf( 100 | 'anonymousFunction:%s#%s', 101 | $this->getLine(), 102 | $this->getId() 103 | ); 104 | } 105 | 106 | if (!$this->isAnonymous()) { 107 | for ($i = $this->id; $i; --$i) { 108 | if ($tokens[$i] instanceof PHP_Token_NAMESPACE) { 109 | $this->name = $tokens[$i]->getName() . '\\' . $this->name; 110 | 111 | break; 112 | } 113 | 114 | if ($tokens[$i] instanceof PHP_Token_INTERFACE) { 115 | break; 116 | } 117 | } 118 | } 119 | 120 | return $this->name; 121 | } 122 | 123 | /** 124 | * @return int 125 | */ 126 | public function getCCN() 127 | { 128 | if ($this->ccn !== null) { 129 | return $this->ccn; 130 | } 131 | 132 | $this->ccn = 1; 133 | $end = $this->getEndTokenId(); 134 | $tokens = $this->tokenStream->tokens(); 135 | 136 | for ($i = $this->id; $i <= $end; $i++) { 137 | switch (\get_class($tokens[$i])) { 138 | case PHP_Token_IF::class: 139 | case PHP_Token_ELSEIF::class: 140 | case PHP_Token_FOR::class: 141 | case PHP_Token_FOREACH::class: 142 | case PHP_Token_WHILE::class: 143 | case PHP_Token_CASE::class: 144 | case PHP_Token_CATCH::class: 145 | case PHP_Token_BOOLEAN_AND::class: 146 | case PHP_Token_LOGICAL_AND::class: 147 | case PHP_Token_BOOLEAN_OR::class: 148 | case PHP_Token_LOGICAL_OR::class: 149 | case PHP_Token_QUESTION_MARK::class: 150 | $this->ccn++; 151 | 152 | break; 153 | } 154 | } 155 | 156 | return $this->ccn; 157 | } 158 | 159 | /** 160 | * @return string 161 | */ 162 | public function getSignature() 163 | { 164 | if ($this->signature !== null) { 165 | return $this->signature; 166 | } 167 | 168 | if ($this->isAnonymous()) { 169 | $this->signature = 'anonymousFunction'; 170 | $i = $this->id + 1; 171 | } else { 172 | $this->signature = ''; 173 | $i = $this->id + 2; 174 | } 175 | 176 | $tokens = $this->tokenStream->tokens(); 177 | 178 | while (isset($tokens[$i]) && 179 | !$tokens[$i] instanceof PHP_Token_OPEN_CURLY && 180 | !$tokens[$i] instanceof PHP_Token_SEMICOLON) { 181 | $this->signature .= $tokens[$i++]; 182 | } 183 | 184 | $this->signature = \trim($this->signature); 185 | 186 | return $this->signature; 187 | } 188 | 189 | /** 190 | * @return bool 191 | */ 192 | public function isAnonymous() 193 | { 194 | return $this->anonymous; 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/Global.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_GLOBAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Goto.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_GOTO extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Gt.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_GT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/HaltCompiler.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_HALT_COMPILER extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/If.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_IF extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Implements.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_IMPLEMENTS extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Inc.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_INC extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Include.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_INCLUDE extends PHP_Token_Includes 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/IncludeOnce.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_INCLUDE_ONCE extends PHP_Token_Includes 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Includes.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | abstract class PHP_Token_Includes extends PHP_Token 11 | { 12 | /** 13 | * @var string 14 | */ 15 | protected $name; 16 | 17 | /** 18 | * @var string 19 | */ 20 | protected $type; 21 | 22 | /** 23 | * @return string 24 | */ 25 | public function getName() 26 | { 27 | if ($this->name === null) { 28 | $this->process(); 29 | } 30 | 31 | return $this->name; 32 | } 33 | 34 | /** 35 | * @return string 36 | */ 37 | public function getType() 38 | { 39 | if ($this->type === null) { 40 | $this->process(); 41 | } 42 | 43 | return $this->type; 44 | } 45 | 46 | private function process(): void 47 | { 48 | $tokens = $this->tokenStream->tokens(); 49 | 50 | if ($tokens[$this->id + 2] instanceof PHP_Token_CONSTANT_ENCAPSED_STRING) { 51 | $this->name = \trim((string) $tokens[$this->id + 2], "'\""); 52 | $this->type = \strtolower( 53 | \str_replace('PHP_Token_', '', PHP_Token_Util::getClass($tokens[$this->id])) 54 | ); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/InlineHtml.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_INLINE_HTML extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Instanceof.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_INSTANCEOF extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Insteadof.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_INSTEADOF extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/IntCast.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_INT_CAST extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Interface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_INTERFACE extends PHP_TokenWithScopeAndVisibility 11 | { 12 | /** 13 | * @var array 14 | */ 15 | protected $interfaces; 16 | 17 | /** 18 | * @return string 19 | */ 20 | public function getName() 21 | { 22 | return (string) $this->tokenStream[$this->id + 2]; 23 | } 24 | 25 | /** 26 | * @return bool 27 | */ 28 | public function hasParent() 29 | { 30 | return $this->tokenStream[$this->id + 4] instanceof PHP_Token_EXTENDS; 31 | } 32 | 33 | /** 34 | * @return array 35 | */ 36 | public function getPackage() 37 | { 38 | $result = [ 39 | 'namespace' => '', 40 | 'fullPackage' => '', 41 | 'category' => '', 42 | 'package' => '', 43 | 'subpackage' => '', 44 | ]; 45 | 46 | $docComment = $this->getDocblock(); 47 | $className = $this->getName(); 48 | 49 | for ($i = $this->id; $i; --$i) { 50 | if ($this->tokenStream[$i] instanceof PHP_Token_NAMESPACE) { 51 | $result['namespace'] = $this->tokenStream[$i]->getName(); 52 | 53 | break; 54 | } 55 | } 56 | 57 | if ($docComment === null) { 58 | return $result; 59 | } 60 | 61 | if (\preg_match('/@category[\s]+([\.\w]+)/', $docComment, $matches)) { 62 | $result['category'] = $matches[1]; 63 | } 64 | 65 | if (\preg_match('/@package[\s]+([\.\w]+)/', $docComment, $matches)) { 66 | $result['package'] = $matches[1]; 67 | $result['fullPackage'] = $matches[1]; 68 | } 69 | 70 | if (\preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) { 71 | $result['subpackage'] = $matches[1]; 72 | $result['fullPackage'] .= '.' . $matches[1]; 73 | } 74 | 75 | if (empty($result['fullPackage'])) { 76 | $result['fullPackage'] = $this->arrayToName( 77 | \explode('_', \str_replace('\\', '_', $className)), 78 | '.' 79 | ); 80 | } 81 | 82 | return $result; 83 | } 84 | 85 | /** 86 | * @return bool|string 87 | */ 88 | public function getParent() 89 | { 90 | if (!$this->hasParent()) { 91 | return false; 92 | } 93 | 94 | $i = $this->id + 6; 95 | $tokens = $this->tokenStream->tokens(); 96 | $className = (string) $tokens[$i]; 97 | 98 | while (isset($tokens[$i + 1]) && 99 | !$tokens[$i + 1] instanceof PHP_Token_WHITESPACE) { 100 | $className .= (string) $tokens[++$i]; 101 | } 102 | 103 | return $className; 104 | } 105 | 106 | /** 107 | * @return bool 108 | */ 109 | public function hasInterfaces() 110 | { 111 | return (isset($this->tokenStream[$this->id + 4]) && 112 | $this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) || 113 | (isset($this->tokenStream[$this->id + 8]) && 114 | $this->tokenStream[$this->id + 8] instanceof PHP_Token_IMPLEMENTS); 115 | } 116 | 117 | /** 118 | * @return array|bool 119 | */ 120 | public function getInterfaces() 121 | { 122 | if ($this->interfaces !== null) { 123 | return $this->interfaces; 124 | } 125 | 126 | if (!$this->hasInterfaces()) { 127 | return $this->interfaces = false; 128 | } 129 | 130 | if ($this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) { 131 | $i = $this->id + 3; 132 | } else { 133 | $i = $this->id + 7; 134 | } 135 | 136 | $tokens = $this->tokenStream->tokens(); 137 | 138 | while (!$tokens[$i + 1] instanceof PHP_Token_OPEN_CURLY) { 139 | $i++; 140 | 141 | if ($tokens[$i] instanceof PHP_Token_STRING) { 142 | $this->interfaces[] = (string) $tokens[$i]; 143 | } 144 | } 145 | 146 | return $this->interfaces; 147 | } 148 | 149 | /** 150 | * @param string $join 151 | * 152 | * @return string 153 | */ 154 | protected function arrayToName(array $parts, $join = '\\') 155 | { 156 | $result = ''; 157 | 158 | if (\count($parts) > 1) { 159 | \array_pop($parts); 160 | 161 | $result = \implode($join, $parts); 162 | } 163 | 164 | return $result; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/IsEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_IS_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/IsGreaterOrEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_IS_GREATER_OR_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/IsIdentical.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_IS_IDENTICAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/IsNotEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_IS_NOT_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/IsNotIdentical.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_IS_NOT_IDENTICAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/IsSmallerOrEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_IS_SMALLER_OR_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Isset.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_ISSET extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Line.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_LINE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/List.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_LIST extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Lnumber.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_LNUMBER extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/LogicalAnd.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_LOGICAL_AND extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/LogicalOr.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_LOGICAL_OR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/LogicalXor.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_LOGICAL_XOR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Lt.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_LT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/MethodC.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_METHOD_C extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Minus.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_MINUS extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/MinusEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_MINUS_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/ModEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_MOD_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/MulEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_MUL_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Mult.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_MULT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/NameFullyQualified.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_NAME_FULLY_QUALIFIED extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/NameQualified.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_NAME_QUALIFIED extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/NameRelative.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_NAME_RELATIVE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Namespace.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_NAMESPACE extends PHP_TokenWithScope 11 | { 12 | /** 13 | * @return string 14 | */ 15 | public function getName() 16 | { 17 | $tokens = $this->tokenStream->tokens(); 18 | $namespace = (string) $tokens[$this->id + 2]; 19 | 20 | for ($i = $this->id + 3;; $i += 2) { 21 | if (isset($tokens[$i]) && 22 | $tokens[$i] instanceof PHP_Token_NS_SEPARATOR) { 23 | $namespace .= '\\' . $tokens[$i + 1]; 24 | } else { 25 | break; 26 | } 27 | } 28 | 29 | return $namespace; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/New.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_NEW extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/NsC.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_NS_C extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/NsSeparator.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_NS_SEPARATOR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/NumString.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_NUM_STRING extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/ObjectCast.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_OBJECT_CAST extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/ObjectOperator.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_OBJECT_OPERATOR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/OpenBracket.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_OPEN_BRACKET extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/OpenCurly.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_OPEN_CURLY extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/OpenSquare.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_OPEN_SQUARE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/OpenTag.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_OPEN_TAG extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/OpenTagWithEcho.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_OPEN_TAG_WITH_ECHO extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/OrEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_OR_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/PaamayimNekudotayim.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_PAAMAYIM_NEKUDOTAYIM extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Percent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_PERCENT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Pipe.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_PIPE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Plus.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_PLUS extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/PlusEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_PLUS_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Pow.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_POW extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/PowEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_POW_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Print.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_PRINT extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Private.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_PRIVATE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Protected.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_PROTECTED extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Public.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_PUBLIC extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/QuestionMark.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_QUESTION_MARK extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Require.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_REQUIRE extends PHP_Token_Includes 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/RequireOnce.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_REQUIRE_ONCE extends PHP_Token_Includes 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Return.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_RETURN extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Semicolon.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_SEMICOLON extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Sl.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_SL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/SlEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_SL_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Spaceship.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_SPACESHIP extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Sr.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_SR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/SrEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_SR_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/StartHeredoc.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_START_HEREDOC extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Static.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_STATIC extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Stream.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator 11 | { 12 | /** 13 | * @var array> 14 | */ 15 | protected static $customTokens = [ 16 | '(' => PHP_Token_OPEN_BRACKET::class, 17 | ')' => PHP_Token_CLOSE_BRACKET::class, 18 | '[' => PHP_Token_OPEN_SQUARE::class, 19 | ']' => PHP_Token_CLOSE_SQUARE::class, 20 | '{' => PHP_Token_OPEN_CURLY::class, 21 | '}' => PHP_Token_CLOSE_CURLY::class, 22 | ';' => PHP_Token_SEMICOLON::class, 23 | '.' => PHP_Token_DOT::class, 24 | ',' => PHP_Token_COMMA::class, 25 | '=' => PHP_Token_EQUAL::class, 26 | '<' => PHP_Token_LT::class, 27 | '>' => PHP_Token_GT::class, 28 | '+' => PHP_Token_PLUS::class, 29 | '-' => PHP_Token_MINUS::class, 30 | '*' => PHP_Token_MULT::class, 31 | '/' => PHP_Token_DIV::class, 32 | '?' => PHP_Token_QUESTION_MARK::class, 33 | '!' => PHP_Token_EXCLAMATION_MARK::class, 34 | ':' => PHP_Token_COLON::class, 35 | '"' => PHP_Token_DOUBLE_QUOTES::class, 36 | '@' => PHP_Token_AT::class, 37 | '&' => PHP_Token_AMPERSAND::class, 38 | '%' => PHP_Token_PERCENT::class, 39 | '|' => PHP_Token_PIPE::class, 40 | '$' => PHP_Token_DOLLAR::class, 41 | '^' => PHP_Token_CARET::class, 42 | '~' => PHP_Token_TILDE::class, 43 | '`' => PHP_Token_BACKTICK::class, 44 | ]; 45 | 46 | /** 47 | * @var string 48 | */ 49 | protected $filename; 50 | 51 | /** 52 | * @var array 53 | */ 54 | protected $tokens = []; 55 | 56 | /** 57 | * @var array 58 | */ 59 | protected $tokensByLine = []; 60 | 61 | /** 62 | * @var int 63 | */ 64 | protected $position = 0; 65 | 66 | /** 67 | * @var array 68 | */ 69 | protected $linesOfCode = ['loc' => 0, 'cloc' => 0, 'ncloc' => 0]; 70 | 71 | /** 72 | * @var array 73 | */ 74 | protected $classes; 75 | 76 | /** 77 | * @var array 78 | */ 79 | protected $functions; 80 | 81 | /** 82 | * @var array 83 | */ 84 | protected $includes; 85 | 86 | /** 87 | * @var array 88 | */ 89 | protected $interfaces; 90 | 91 | /** 92 | * @var array 93 | */ 94 | protected $traits; 95 | 96 | /** 97 | * @var array 98 | */ 99 | protected $lineToFunctionMap = []; 100 | 101 | /** 102 | * Constructor. 103 | * 104 | * @param string $sourceCode 105 | */ 106 | public function __construct($sourceCode) 107 | { 108 | if (\is_file($sourceCode)) { 109 | $this->filename = $sourceCode; 110 | $sourceCode = \file_get_contents($sourceCode); 111 | } 112 | 113 | $this->scan($sourceCode); 114 | } 115 | 116 | /** 117 | * Destructor. 118 | */ 119 | public function __destruct() 120 | { 121 | $this->tokens = []; 122 | $this->tokensByLine = []; 123 | } 124 | 125 | /** 126 | * @return string 127 | */ 128 | public function __toString() 129 | { 130 | $buffer = ''; 131 | 132 | foreach ($this as $token) { 133 | $buffer .= $token; 134 | } 135 | 136 | return $buffer; 137 | } 138 | 139 | /** 140 | * @return string 141 | */ 142 | public function getFilename() 143 | { 144 | return $this->filename; 145 | } 146 | 147 | /** 148 | * @return int 149 | */ 150 | public function count() 151 | { 152 | return \count($this->tokens); 153 | } 154 | 155 | /** 156 | * @return PHP_Token[] 157 | */ 158 | public function tokens() 159 | { 160 | return $this->tokens; 161 | } 162 | 163 | /** 164 | * @return array 165 | */ 166 | public function getClasses() 167 | { 168 | if ($this->classes !== null) { 169 | return $this->classes; 170 | } 171 | 172 | $this->parse(); 173 | 174 | return $this->classes; 175 | } 176 | 177 | /** 178 | * @return array 179 | */ 180 | public function getFunctions() 181 | { 182 | if ($this->functions !== null) { 183 | return $this->functions; 184 | } 185 | 186 | $this->parse(); 187 | 188 | return $this->functions; 189 | } 190 | 191 | /** 192 | * @return array 193 | */ 194 | public function getInterfaces() 195 | { 196 | if ($this->interfaces !== null) { 197 | return $this->interfaces; 198 | } 199 | 200 | $this->parse(); 201 | 202 | return $this->interfaces; 203 | } 204 | 205 | /** 206 | * @return array 207 | */ 208 | public function getTraits() 209 | { 210 | if ($this->traits !== null) { 211 | return $this->traits; 212 | } 213 | 214 | $this->parse(); 215 | 216 | return $this->traits; 217 | } 218 | 219 | /** 220 | * Gets the names of all files that have been included 221 | * using include(), include_once(), require() or require_once(). 222 | * 223 | * Parameter $categorize set to TRUE causing this function to return a 224 | * multi-dimensional array with categories in the keys of the first dimension 225 | * and constants and their values in the second dimension. 226 | * 227 | * Parameter $category allow to filter following specific inclusion type 228 | * 229 | * @param bool $categorize OPTIONAL 230 | * @param string $category OPTIONAL Either 'require_once', 'require', 231 | * 'include_once', 'include' 232 | * 233 | * @return array 234 | */ 235 | public function getIncludes($categorize = false, $category = null) 236 | { 237 | if ($this->includes === null) { 238 | $this->includes = [ 239 | 'require_once' => [], 240 | 'require' => [], 241 | 'include_once' => [], 242 | 'include' => [], 243 | ]; 244 | 245 | foreach ($this->tokens as $token) { 246 | switch (\get_class($token)) { 247 | case PHP_Token_REQUIRE_ONCE::class: 248 | case PHP_Token_REQUIRE::class: 249 | case PHP_Token_INCLUDE_ONCE::class: 250 | case PHP_Token_INCLUDE::class: 251 | $this->includes[$token->getType()][] = $token->getName(); 252 | 253 | break; 254 | } 255 | } 256 | } 257 | 258 | if (isset($this->includes[$category])) { 259 | $includes = $this->includes[$category]; 260 | } elseif ($categorize === false) { 261 | $includes = \array_merge( 262 | $this->includes['require_once'], 263 | $this->includes['require'], 264 | $this->includes['include_once'], 265 | $this->includes['include'] 266 | ); 267 | } else { 268 | $includes = $this->includes; 269 | } 270 | 271 | return $includes; 272 | } 273 | 274 | /** 275 | * Returns the name of the function or method a line belongs to. 276 | * 277 | * @return string or null if the line is not in a function or method 278 | */ 279 | public function getFunctionForLine($line) 280 | { 281 | $this->parse(); 282 | 283 | if (isset($this->lineToFunctionMap[$line])) { 284 | return $this->lineToFunctionMap[$line]; 285 | } 286 | } 287 | 288 | /** 289 | * @return array 290 | */ 291 | public function getLinesOfCode() 292 | { 293 | return $this->linesOfCode; 294 | } 295 | 296 | public function rewind()/*: void*/ 297 | { 298 | $this->position = 0; 299 | } 300 | 301 | /** 302 | * @return bool 303 | */ 304 | public function valid() 305 | { 306 | return isset($this->tokens[$this->position]); 307 | } 308 | 309 | /** 310 | * @return int 311 | */ 312 | public function key() 313 | { 314 | return $this->position; 315 | } 316 | 317 | /** 318 | * @return PHP_Token 319 | */ 320 | public function current() 321 | { 322 | return $this->tokens[$this->position]; 323 | } 324 | 325 | public function next()/*: void*/ 326 | { 327 | $this->position++; 328 | } 329 | 330 | /** 331 | * @param int $offset 332 | * 333 | * @return bool 334 | */ 335 | public function offsetExists($offset) 336 | { 337 | return isset($this->tokens[$offset]); 338 | } 339 | 340 | /** 341 | * @param int $offset 342 | * 343 | * @throws OutOfBoundsException 344 | */ 345 | public function offsetGet($offset) 346 | { 347 | if (!$this->offsetExists($offset)) { 348 | throw new OutOfBoundsException( 349 | \sprintf( 350 | 'No token at position "%s"', 351 | $offset 352 | ) 353 | ); 354 | } 355 | 356 | return $this->tokens[$offset]; 357 | } 358 | 359 | /** 360 | * @param int $offset 361 | */ 362 | public function offsetSet($offset, $value)/*: void*/ 363 | { 364 | $this->tokens[$offset] = $value; 365 | } 366 | 367 | /** 368 | * @param int $offset 369 | * 370 | * @throws OutOfBoundsException 371 | */ 372 | public function offsetUnset($offset)/*: void*/ 373 | { 374 | if (!$this->offsetExists($offset)) { 375 | throw new OutOfBoundsException( 376 | \sprintf( 377 | 'No token at position "%s"', 378 | $offset 379 | ) 380 | ); 381 | } 382 | 383 | unset($this->tokens[$offset]); 384 | } 385 | 386 | /** 387 | * Seek to an absolute position. 388 | * 389 | * @param int $position 390 | * 391 | * @throws OutOfBoundsException 392 | */ 393 | public function seek($position)/*: void*/ 394 | { 395 | $this->position = $position; 396 | 397 | if (!$this->valid()) { 398 | throw new OutOfBoundsException( 399 | \sprintf( 400 | 'No token at position "%s"', 401 | $this->position 402 | ) 403 | ); 404 | } 405 | } 406 | 407 | /** 408 | * Scans the source for sequences of characters and converts them into a 409 | * stream of tokens. 410 | * 411 | * @param string $sourceCode 412 | */ 413 | protected function scan($sourceCode)/*: void*/ 414 | { 415 | $id = 0; 416 | $line = 1; 417 | $tokens = \token_get_all($sourceCode); 418 | $numTokens = \count($tokens); 419 | 420 | $lastNonWhitespaceTokenWasDoubleColon = false; 421 | 422 | $name = null; 423 | 424 | for ($i = 0; $i < $numTokens; ++$i) { 425 | $token = $tokens[$i]; 426 | $skip = 0; 427 | 428 | if (\is_array($token)) { 429 | $name = \substr(\token_name($token[0]), 2); 430 | $text = $token[1]; 431 | 432 | if ($lastNonWhitespaceTokenWasDoubleColon && $name == 'CLASS') { 433 | $name = 'CLASS_NAME_CONSTANT'; 434 | } elseif ($name == 'USE' && isset($tokens[$i + 2][0]) && $tokens[$i + 2][0] == \T_FUNCTION) { 435 | $name = 'USE_FUNCTION'; 436 | $text .= $tokens[$i + 1][1] . $tokens[$i + 2][1]; 437 | $skip = 2; 438 | } 439 | 440 | /** @var class-string $tokenClass */ 441 | $tokenClass = 'PHP_Token_' . $name; 442 | } else { 443 | $text = $token; 444 | $tokenClass = self::$customTokens[$token]; 445 | } 446 | 447 | /* 448 | * @see https://github.com/sebastianbergmann/php-token-stream/issues/95 449 | */ 450 | if (PHP_MAJOR_VERSION >= 8 && 451 | $name === 'WHITESPACE' && // Current token is T_WHITESPACE 452 | isset($this->tokens[$id - 1]) && // Current token is not the first token 453 | $this->tokens[$id - 1] instanceof PHP_Token_COMMENT && // Previous token is T_COMMENT 454 | strpos((string) $this->tokens[$id - 1], '/*') === false && // Previous token is comment that starts with '#' or '//' 455 | strpos($text, "\n") === 0 // Text of current token begins with newline 456 | ) { 457 | $this->tokens[$id - 1] = new PHP_Token_COMMENT( 458 | $this->tokens[$id - 1] . "\n", 459 | $this->tokens[$id - 1]->getLine(), 460 | $this, 461 | $id - 1 462 | ); 463 | 464 | $text = substr($text, 1); 465 | 466 | $line++; 467 | 468 | if (empty($text)) { 469 | continue; 470 | } 471 | } 472 | 473 | if (!isset($this->tokensByLine[$line])) { 474 | $this->tokensByLine[$line] = []; 475 | } 476 | 477 | $token = new $tokenClass($text, $line, $this, $id++); 478 | 479 | $this->tokens[] = $token; 480 | $this->tokensByLine[$line][] = $token; 481 | 482 | $line += \substr_count($text, "\n"); 483 | 484 | if ($tokenClass == PHP_Token_HALT_COMPILER::class) { 485 | break; 486 | } 487 | 488 | if ($name == 'DOUBLE_COLON') { 489 | $lastNonWhitespaceTokenWasDoubleColon = true; 490 | } elseif ($name != 'WHITESPACE') { 491 | $lastNonWhitespaceTokenWasDoubleColon = false; 492 | } 493 | 494 | $i += $skip; 495 | } 496 | 497 | foreach ($this->tokens as $token) { 498 | if (!$token instanceof PHP_Token_COMMENT && !$token instanceof PHP_Token_DOC_COMMENT) { 499 | continue; 500 | } 501 | 502 | foreach ($this->tokensByLine[$token->getLine()] as $_token) { 503 | if (!$_token instanceof PHP_Token_COMMENT && !$_token instanceof PHP_Token_DOC_COMMENT && !$_token instanceof PHP_Token_WHITESPACE) { 504 | continue 2; 505 | } 506 | } 507 | 508 | $this->linesOfCode['cloc'] += max(1, \substr_count((string) $token, "\n")); 509 | } 510 | 511 | $this->linesOfCode['loc'] = \substr_count($sourceCode, "\n"); 512 | $this->linesOfCode['ncloc'] = $this->linesOfCode['loc'] - 513 | $this->linesOfCode['cloc']; 514 | } 515 | 516 | protected function parse()/*: void*/ 517 | { 518 | $this->interfaces = []; 519 | $this->classes = []; 520 | $this->traits = []; 521 | $this->functions = []; 522 | $class = []; 523 | $classEndLine = []; 524 | $trait = false; 525 | $traitEndLine = false; 526 | $interface = false; 527 | $interfaceEndLine = false; 528 | 529 | foreach ($this->tokens as $token) { 530 | switch (\get_class($token)) { 531 | case PHP_Token_HALT_COMPILER::class: 532 | return; 533 | 534 | case PHP_Token_INTERFACE::class: 535 | $interface = $token->getName(); 536 | $interfaceEndLine = $token->getEndLine(); 537 | 538 | $this->interfaces[$interface] = [ 539 | 'methods' => [], 540 | 'parent' => $token->getParent(), 541 | 'keywords' => $token->getKeywords(), 542 | 'docblock' => $token->getDocblock(), 543 | 'startLine' => $token->getLine(), 544 | 'endLine' => $interfaceEndLine, 545 | 'package' => $token->getPackage(), 546 | 'file' => $this->filename, 547 | ]; 548 | 549 | break; 550 | 551 | case PHP_Token_CLASS::class: 552 | case PHP_Token_TRAIT::class: 553 | $tmp = [ 554 | 'methods' => [], 555 | 'parent' => $token->getParent(), 556 | 'interfaces'=> $token->getInterfaces(), 557 | 'keywords' => $token->getKeywords(), 558 | 'docblock' => $token->getDocblock(), 559 | 'startLine' => $token->getLine(), 560 | 'endLine' => $token->getEndLine(), 561 | 'package' => $token->getPackage(), 562 | 'file' => $this->filename, 563 | ]; 564 | 565 | if ($token instanceof PHP_Token_CLASS) { 566 | $class[] = $token->getName(); 567 | $classEndLine[] = $token->getEndLine(); 568 | 569 | if ($token->getName() !== null) { 570 | $this->classes[$class[\count($class) - 1]] = $tmp; 571 | } 572 | } else { 573 | $trait = $token->getName(); 574 | $traitEndLine = $token->getEndLine(); 575 | $this->traits[$trait] = $tmp; 576 | } 577 | 578 | break; 579 | 580 | case PHP_Token_FUNCTION::class: 581 | $name = $token->getName(); 582 | $tmp = [ 583 | 'docblock' => $token->getDocblock(), 584 | 'keywords' => $token->getKeywords(), 585 | 'visibility'=> $token->getVisibility(), 586 | 'signature' => $token->getSignature(), 587 | 'startLine' => $token->getLine(), 588 | 'endLine' => $token->getEndLine(), 589 | 'ccn' => $token->getCCN(), 590 | 'file' => $this->filename, 591 | ]; 592 | 593 | if (empty($class) && 594 | $trait === false && 595 | $interface === false) { 596 | $this->functions[$name] = $tmp; 597 | 598 | $this->addFunctionToMap( 599 | $name, 600 | $tmp['startLine'], 601 | $tmp['endLine'] 602 | ); 603 | } elseif (!empty($class)) { 604 | if ($class[\count($class) - 1] !== null) { 605 | $this->classes[$class[\count($class) - 1]]['methods'][$name] = $tmp; 606 | 607 | $this->addFunctionToMap( 608 | $class[\count($class) - 1] . '::' . $name, 609 | $tmp['startLine'], 610 | $tmp['endLine'] 611 | ); 612 | } 613 | } elseif ($trait !== false) { 614 | $this->traits[$trait]['methods'][$name] = $tmp; 615 | 616 | $this->addFunctionToMap( 617 | $trait . '::' . $name, 618 | $tmp['startLine'], 619 | $tmp['endLine'] 620 | ); 621 | } else { 622 | $this->interfaces[$interface]['methods'][$name] = $tmp; 623 | } 624 | 625 | break; 626 | 627 | case PHP_Token_CLOSE_CURLY::class: 628 | if (!empty($classEndLine) && 629 | $classEndLine[\count($classEndLine) - 1] == $token->getLine()) { 630 | \array_pop($classEndLine); 631 | \array_pop($class); 632 | } elseif ($traitEndLine !== false && 633 | $traitEndLine == $token->getLine()) { 634 | $trait = false; 635 | $traitEndLine = false; 636 | } elseif ($interfaceEndLine !== false && 637 | $interfaceEndLine == $token->getLine()) { 638 | $interface = false; 639 | $interfaceEndLine = false; 640 | } 641 | 642 | break; 643 | } 644 | } 645 | } 646 | 647 | /** 648 | * @param string $name 649 | * @param int $startLine 650 | * @param int $endLine 651 | */ 652 | private function addFunctionToMap($name, $startLine, $endLine): void 653 | { 654 | for ($line = $startLine; $line <= $endLine; $line++) { 655 | $this->lineToFunctionMap[$line] = $name; 656 | } 657 | } 658 | } 659 | -------------------------------------------------------------------------------- /src/String.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_STRING extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/StringCast.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_STRING_CAST extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/StringVarname.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_STRING_VARNAME extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Switch.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_SWITCH extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Throw.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_THROW extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Tilde.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_TILDE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Token.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | abstract class PHP_Token 11 | { 12 | /** 13 | * @var string 14 | */ 15 | protected $text; 16 | 17 | /** 18 | * @var int 19 | */ 20 | protected $line; 21 | 22 | /** 23 | * @var PHP_Token_Stream 24 | */ 25 | protected $tokenStream; 26 | 27 | /** 28 | * @var int 29 | */ 30 | protected $id; 31 | 32 | /** 33 | * @param string $text 34 | * @param int $line 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 | /** 46 | * @return string 47 | */ 48 | public function __toString() 49 | { 50 | return $this->text; 51 | } 52 | 53 | /** 54 | * @return int 55 | */ 56 | public function getLine() 57 | { 58 | return $this->line; 59 | } 60 | 61 | /** 62 | * @return int 63 | */ 64 | public function getId() 65 | { 66 | return $this->id; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/TokenWithScope.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | abstract class PHP_TokenWithScope extends PHP_Token 11 | { 12 | /** 13 | * @var int 14 | */ 15 | protected $endTokenId; 16 | 17 | /** 18 | * Get the docblock for this token. 19 | * 20 | * This method will fetch the docblock belonging to the current token. The 21 | * docblock must be placed on the line directly above the token to be 22 | * recognized. 23 | * 24 | * @return null|string Returns the docblock as a string if found 25 | */ 26 | public function getDocblock() 27 | { 28 | $tokens = $this->tokenStream->tokens(); 29 | $currentLineNumber = $tokens[$this->id]->getLine(); 30 | $prevLineNumber = $currentLineNumber - 1; 31 | 32 | for ($i = $this->id - 1; $i; $i--) { 33 | if (!isset($tokens[$i])) { 34 | return; 35 | } 36 | 37 | if ($tokens[$i] instanceof PHP_Token_FUNCTION || 38 | $tokens[$i] instanceof PHP_Token_CLASS || 39 | $tokens[$i] instanceof PHP_Token_TRAIT) { 40 | // Some other trait, class or function, no docblock can be 41 | // used for the current token 42 | break; 43 | } 44 | 45 | $line = $tokens[$i]->getLine(); 46 | 47 | if ($line == $currentLineNumber || 48 | ($line == $prevLineNumber && 49 | $tokens[$i] instanceof PHP_Token_WHITESPACE)) { 50 | continue; 51 | } 52 | 53 | if ($line < $currentLineNumber && 54 | !$tokens[$i] instanceof PHP_Token_DOC_COMMENT) { 55 | break; 56 | } 57 | 58 | return (string) $tokens[$i]; 59 | } 60 | } 61 | 62 | /** 63 | * @return int 64 | */ 65 | public function getEndTokenId() 66 | { 67 | $block = 0; 68 | $i = $this->id; 69 | $tokens = $this->tokenStream->tokens(); 70 | 71 | while ($this->endTokenId === null && isset($tokens[$i])) { 72 | if ($tokens[$i] instanceof PHP_Token_OPEN_CURLY || 73 | $tokens[$i] instanceof PHP_Token_DOLLAR_OPEN_CURLY_BRACES || 74 | $tokens[$i] instanceof PHP_Token_CURLY_OPEN) { 75 | $block++; 76 | } elseif ($tokens[$i] instanceof PHP_Token_CLOSE_CURLY) { 77 | $block--; 78 | 79 | if ($block === 0) { 80 | $this->endTokenId = $i; 81 | } 82 | } elseif (($this instanceof PHP_Token_FUNCTION || 83 | $this instanceof PHP_Token_NAMESPACE) && 84 | $tokens[$i] instanceof PHP_Token_SEMICOLON) { 85 | if ($block === 0) { 86 | $this->endTokenId = $i; 87 | } 88 | } 89 | 90 | $i++; 91 | } 92 | 93 | if ($this->endTokenId === null) { 94 | $this->endTokenId = $this->id; 95 | } 96 | 97 | return $this->endTokenId; 98 | } 99 | 100 | /** 101 | * @return int 102 | */ 103 | public function getEndLine() 104 | { 105 | return $this->tokenStream[$this->getEndTokenId()]->getLine(); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/TokenWithScopeAndVisibility.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | abstract class PHP_TokenWithScopeAndVisibility extends PHP_TokenWithScope 11 | { 12 | /** 13 | * @return string 14 | */ 15 | public function getVisibility() 16 | { 17 | $tokens = $this->tokenStream->tokens(); 18 | 19 | for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) { 20 | if (isset($tokens[$i]) && 21 | ($tokens[$i] instanceof PHP_Token_PRIVATE || 22 | $tokens[$i] instanceof PHP_Token_PROTECTED || 23 | $tokens[$i] instanceof PHP_Token_PUBLIC)) { 24 | return \strtolower( 25 | \str_replace('PHP_Token_', '', PHP_Token_Util::getClass($tokens[$i])) 26 | ); 27 | } 28 | 29 | if (isset($tokens[$i]) && 30 | !($tokens[$i] instanceof PHP_Token_STATIC || 31 | $tokens[$i] instanceof PHP_Token_FINAL || 32 | $tokens[$i] instanceof PHP_Token_ABSTRACT)) { 33 | // no keywords; stop visibility search 34 | break; 35 | } 36 | } 37 | } 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function getKeywords() 43 | { 44 | $keywords = []; 45 | $tokens = $this->tokenStream->tokens(); 46 | 47 | for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) { 48 | if (isset($tokens[$i]) && 49 | ($tokens[$i] instanceof PHP_Token_PRIVATE || 50 | $tokens[$i] instanceof PHP_Token_PROTECTED || 51 | $tokens[$i] instanceof PHP_Token_PUBLIC)) { 52 | continue; 53 | } 54 | 55 | if (isset($tokens[$i]) && 56 | ($tokens[$i] instanceof PHP_Token_STATIC || 57 | $tokens[$i] instanceof PHP_Token_FINAL || 58 | $tokens[$i] instanceof PHP_Token_ABSTRACT)) { 59 | $keywords[] = \strtolower( 60 | \str_replace('PHP_Token_', '', PHP_Token_Util::getClass($tokens[$i])) 61 | ); 62 | } 63 | } 64 | 65 | return \implode(',', $keywords); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Trait.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_TRAIT extends PHP_Token_INTERFACE 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/TraitC.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_TRAIT_C extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Try.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_TRY extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Unset.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_UNSET extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/UnsetCast.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_UNSET_CAST extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Use.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_USE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/UseFunction.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_USE_FUNCTION extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Util.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | final class PHP_Token_Util 11 | { 12 | public static function getClass($object): string 13 | { 14 | $parts = \explode('\\', \get_class($object)); 15 | 16 | return \array_pop($parts); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Var.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_VAR extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Variable.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_VARIABLE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/While.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_WHILE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Whitespace.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_WHITESPACE extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/XorEqual.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_XOR_EQUAL extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/Yield.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_YIELD extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/YieldFrom.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_YIELD_FROM extends PHP_Token 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /src/break.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | class PHP_Token_BREAK extends PHP_Token 11 | { 12 | } 13 | --------------------------------------------------------------------------------