localheinz / token
This package is abandoned and no longer maintained.
No replacement package was suggested.
Provides a simple abstraction for a token and a sequence of tokens.
0.2.2
2017-10-09 16:45 UTC
Requires
- php: ^7.0
Requires (Dev)
- codeclimate/php-test-reporter: 0.4.4
- localheinz/php-cs-fixer-config: ~1.6.2
- localheinz/test-util: 0.2.2
- phpbench/phpbench: 0.13.0
- phpunit/phpunit: ^6.3.1
This package is auto-updated.
Last update: 2019-12-05 20:36:03 UTC
README
Provides a simple read-only abstraction for a token and a sequence of tokens, inspired by friendsofphp/php-cs-fixer
.
Installation
Run
$ composer require localheinz/token
Usage
Sequence of tokens
Create a sequence of tokens from source code:
use Localheinz\Token\Sequence; $source = <<<'PHP' <?php class Foo { /** * @param Bar $bar */ public function __construct(Bar $bar) { $this->bar = $bar; } } PHP; $sequence = Sequence::fromSource($source);
Token in sequence
Retrieve the token at an index in the sequence of tokens:
use Localheinz\Token\Token; /** @var Token $token */ $token = $sequence->at(10); var_dump($token->index()); // 10 var_dump($token->isType(T_PUBLIC)); // true var_dump($token->isContent('public')); // true
Retrieve the next significant token before an index in the sequence of tokens:
use Localheinz\Token\Token; /** @var Token $before */ $before = $sequence->significantBefore(10); var_dump($before->index()); // 6 var_dump($before->isType(T_STRING)); // true var_dump($before->isContent('{')); // true
Retrieve the next significant token after an index in the sequence of tokens:
use Localheinz\Token\Token; /** @var Token $after */ $after = $sequence->significantAfter(10); var_dump($after->index()); // 12 var_dump($after->isType(T_FUNCTION)); // true var_dump($after->isContent('function')); // true
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.