Provides a simple read-only abstraction for a token and a sequence of tokens, inspired by friendsofphp/php-cs-fixer
.
Run
$ composer require localheinz/token
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);
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
Please have a look at CHANGELOG.md
.
Please have a look at CONTRIBUTING.md
.
Please have a look at CODE_OF_CONDUCT.md
.
This package is licensed using the MIT License.