Wrapper around token_get_all. Easy to extract and modify tokens
Via Composer
composer require funivan/php-tokenizer
Reformat our code like PhpStorm. Lets create rule: place single spaces after while
use Funivan\PhpTokenizer\Collection;
use Funivan\PhpTokenizer\Pattern\PatternMatcher;
use Funivan\PhpTokenizer\QuerySequence\QuerySequence;
$source = "<?php while(){}"; // while (){}
$collection = Collection::createFromString($source);
(new PatternMatcher($collection))->apply(function (QuerySequence $checker) {
$while = $checker->strict('while');
$space = $checker->possible(T_WHITESPACE);
if ($checker->isValid()) {
$space->remove();
$while->appendToValue(" ");
}
});
echo (string) $collection;
./vendor/bin/phpunit
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.