コード例 #1
0
ファイル: Section.php プロジェクト: savelyeva/PhpTokenizer
 /**
  * @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;
 }
コード例 #2
0
ファイル: Possible.php プロジェクト: savelyeva/PhpTokenizer
 /**
  * @inheritdoc
  */
 public function process(\Funivan\PhpTokenizer\Collection $collection, $currentIndex)
 {
     $result = new StrategyResult();
     $result->setValid(true);
     $token = $collection->offsetGet($currentIndex);
     if ($token and $this->isValid($token)) {
         $result->setToken($token);
         ++$currentIndex;
     }
     $result->setNexTokenIndex($currentIndex);
     return $result;
 }
コード例 #3
0
ファイル: Search.php プロジェクト: savelyeva/PhpTokenizer
 /**
  * @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;
 }