/** * @param Collection $collection * @return Collection */ protected function getInvalidTokens(Collection $collection) { $resultCollection = new Collection(); $classBody = (new PatternMatcher($collection))->apply(new ClassPattern())->getCollections(); if (empty($classBody)) { return $resultCollection; } foreach ($classBody as $body) { if ($body->count() === 0) { continue; } $resultCollection->append($body->getLast()); } foreach ($resultCollection as $index => $token) { if ($this->isValidBodyEndToken($token)) { $resultCollection->offsetUnset($index); } } $resultCollection->rewind(); return $resultCollection; }
/** * @param Token $tokenStart * @param Token $tokenEnd * @return Collection */ public function extractByTokens(Token $tokenStart, Token $tokenEnd) { $collection = new Collection(); $startIndex = $tokenStart->getIndex(); $endIndex = $tokenEnd->getIndex(); foreach ($this->getItems() as $token) { if ($token->getIndex() >= $startIndex and $token->getIndex() <= $endIndex) { $collection->append($token); } } return $collection; }