Beispiel #1
0
 /**
  * @param \Funivan\PhpTokenizer\Collection $collection
  * @param int $currentIndex
  * @return int|null
  */
 public function process(\Funivan\PhpTokenizer\Collection $collection, $currentIndex)
 {
     $this->requireQueries();
     $result = new StrategyResult();
     $token = $collection->offsetGet($currentIndex);
     if (empty($token) or $this->startQuery->isValid($token) === false) {
         return $result;
     }
     $blockEndFlag = null;
     $startIndex = null;
     foreach ($collection as $tokenIndex => $token) {
         if ($tokenIndex < $currentIndex) {
             continue;
         }
         if ($this->startQuery->isValid($token)) {
             $blockEndFlag++;
             if ($blockEndFlag == 1) {
                 $startIndex = $tokenIndex;
             }
         } elseif ($startIndex !== null and $this->endQuery->isValid($token)) {
             $blockEndFlag--;
         }
         if ($blockEndFlag === 0) {
             $endIndex = $tokenIndex;
             break;
         }
     }
     if (isset($startIndex) and isset($endIndex)) {
         $result = new StrategyResult();
         $result->setValid(true);
         $result->setNexTokenIndex(++$endIndex);
         $result->setToken($token);
     }
     return $result;
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function process(\Funivan\PhpTokenizer\Collection $collection, $currentIndex)
 {
     $result = new StrategyResult();
     $endIndex = $currentIndex + $this->steps;
     $result->setNexTokenIndex($endIndex);
     if (isset($collection[$endIndex])) {
         $result->setValid(true);
         $result->setToken($collection[$endIndex]);
     } else {
         $result->setValid(false);
     }
     return $result;
 }
Beispiel #3
0
 /**
  * @inheritdoc
  */
 public function process(\Funivan\PhpTokenizer\Collection $collection, $currentIndex)
 {
     $result = new StrategyResult();
     # getProcessor while we can check toke
     $index = $currentIndex;
     $searchForward = $this->direction === static::FORWARD;
     do {
         $token = $collection->offsetGet($index);
         if ($token === null) {
             return $result;
         }
         $index = $searchForward ? ++$index : --$index;
         if ($this->isValid($token)) {
             $result->setNexTokenIndex($index);
             $result->setValid(true);
             $result->setToken($token);
             break;
         }
     } while (!empty($token));
     return $result;
 }