Exemplo n.º 1
0
 /**
  * @param File $file
  * @param Report $report
  */
 public function process(File $file, Report $report)
 {
     $collection = Collection::createFromString($file->getContent()->get());
     (new PatternMatcher($collection))->apply(function (QuerySequence $q) {
         $any = Strict::create()->valueLike('!.+!');
         $q->strict('function');
         $q->strict(T_WHITESPACE);
         $q->strict($any);
         $q->possible(T_WHITESPACE);
         $q->section('(', ')');
         // return type
         $beforeSpace = $q->possible(T_WHITESPACE);
         $identifier = $q->strict(':');
         $afterSpace = $q->possible(T_WHITESPACE);
         $q->strict($any);
         $q->search(Search::create()->valueLike('!^\\{|\\;$!'));
         if ($q->isValid()) {
             $beforeSpace->remove();
             $identifier->prependToValue($this->before);
             // add symbol before
             $identifier->appendToValue($this->after);
             // add symbol after
             $afterSpace->remove();
         }
     });
     $file->getContent()->set((string) $collection);
 }
Exemplo n.º 2
0
 /**
  * By default we search forward
  *
  * @param int|string|Search $condition
  * @param null $direction
  * @return Token
  */
 public function search($condition, $direction = null)
 {
     $strategy = Search::create();
     if ($direction !== null) {
         $strategy->setDirection($direction);
     }
     $query = $this->buildStrategyCondition($condition, $strategy);
     return $this->process($query);
 }