Skip to content

Wrapper around token_get_all. Easy way to extract and modify yout code

License

Notifications You must be signed in to change notification settings

funivan/PhpTokenizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PhpTokenizer

GitHub tag Software License 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.

About

Wrapper around token_get_all. Easy way to extract and modify yout code

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages