/** * @param Tokens $tokens * @param int $index Index of the token to check * @param int $lowerLimitIndex Lower limit index. Since the token to check will always be in a conditional we must stop checking at this index * * @return bool */ private function isInConditional(Tokens $tokens, $index, $lowerLimitIndex) { $candidateIndex = $tokens->getTokenOfKindSibling($index, -1, array(')', ';', ':')); if ($tokens[$candidateIndex]->equals(':')) { return true; } if (!$tokens[$candidateIndex]->equals(')')) { return false; // token is ';' or close tag } // token is always ')' here. // If it is part of the condition the token is always in, return false. // If it is not it is a nested condition so return true $open = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $candidateIndex, false); return $tokens->getPrevMeaningfulToken($open) > $lowerLimitIndex; }