funivan/php-tokenizer

Wrapper around token_get_all. Easy to extract and modify php code.

0.3.0 2020-01-20 09:23 UTC

This package is auto-updated.

Last update: 2022-06-20 14:27:27 UTC


README

GitHub tag Software License Build Status Coverage Status Quality Score Total Downloads

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

Documentation

Testing

./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.