Skip to content

ttacoder/PhpTokenizer

 
 

Repository files navigation

PhpTokenizer

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

  require __DIR__.'/vendor/autoload.php';
   
  use Funivan\PhpTokenizer\Collection;
  use Funivan\PhpTokenizer\Pattern\Pattern;
  use Funivan\PhpTokenizer\QuerySequence\QuerySequence;


  $source = "<?php while(){}"; // while (){}
  
  $collection = Collection::initFromString($source);
  
  (new Pattern($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.

About

Wrapper around token_get_all. Easy to extract and modify tokens

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%