funivan / php-tokenizer
Wrapper around token_get_all. Easy to extract and modify php code.
Installs: 38 440
Dependents: 4
Suggesters: 0
Security: 0
Stars: 12
Watchers: 6
Forks: 2
Open Issues: 1
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-11-12 05:50:34 UTC
README
Wrapper around token_get_all. Easy to extract and modify tokens
Install
Via Composer
composer require funivan/php-tokenizer
Usage
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;
Documentation
Testing
./vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.