/** * @param Collection $collection * @return Token */ protected function getLastInvalidToken(Collection $collection) { $lastToken = $collection->getLast(); if ($lastToken and preg_match('![ ]+\\n*$!', $lastToken->getValue())) { return $lastToken; } return null; }