Example #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);
 }
Example #2
0
 /**
  * @param $key
  * @param $items
  */
 public function append($key, $items)
 {
     (new Pattern($this->collection))->apply(function (QuerySequence $checker) use($key, $items) {
         $key = $checker->strict(Strict::create()->valueLike('!^(\'|")' . $key . '\\1$!'));
         $checker->possible(T_WHITESPACE);
         $checker->strict('=>');
         $checker->possible(T_WHITESPACE);
         $openBracket = $checker->strict('[');
         $checker->moveToToken($openBracket);
         $section = $checker->section('[', ']');
         if ($checker->isValid()) {
             # add comma if needed
             $index = $section->count() - 2;
             // move to latest token
             $lastToken = $section[$index];
             if ($lastToken->getType() == T_WHITESPACE) {
                 $lastToken = $section[$index - 1];
             }
             // add a comma if needed
             if ($lastToken->getValue() != ',') {
                 $lastToken->appendToValue(',');
             }
             $tokens = $this->renderItemTokens($items);
             $lastToken->appendToValue($tokens);
         }
     });
 }
Example #3
0
 /**
  * @param QueryStrategy|string $name
  * @return $this
  */
 public function withName($name)
 {
     if (is_string($name)) {
         $this->nameQuery = Strict::create()->valueIs($name);
     } elseif ($name instanceof QueryStrategy) {
         $this->nameQuery = $name;
     } else {
         throw new \InvalidArgumentException('Expect string or QueryInterface');
     }
     return $this;
 }
Example #4
0
 /**
  * @param string|int|StrategyInterface $value
  * @return Token
  */
 private function checkFromSequence($value)
 {
     if ($value instanceof StrategyInterface) {
         $query = $value;
     } else {
         $query = $this->buildStrategyCondition($value, Strict::create());
     }
     $token = $this->process($query);
     return $token;
 }