/**
  * Method to move index over the non-array elements like function calls or function declarations.
  *
  * @param int    $index
  * @param Tokens $tokens
  *
  * @return int New index
  */
 private function skipNonArrayElements($index, Tokens $tokens)
 {
     if ($tokens[$index]->equals('}')) {
         return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index, false);
     }
     if ($tokens[$index]->equals(')')) {
         $startIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index, false);
         $startIndex = $tokens->getPrevMeaningfulToken($startIndex);
         if (!$tokens->isArray($startIndex)) {
             return $startIndex;
         }
     }
     return $index;
 }
 private function fixOptionNames(Tokens $tokens, $fieldNameTokens, $oldName, $newName, $start = 0)
 {
     $matchedTokens = $tokens->findSequence(array_merge([[T_OBJECT_OPERATOR], [T_STRING, 'add'], '(', [T_CONSTANT_ENCAPSED_STRING], ','], $fieldNameTokens, [',']), $start);
     if (null === $matchedTokens) {
         return;
     }
     $matchedTokenIndexes = array_keys($matchedTokens);
     $isArray = $tokens->isArray($index = $tokens->getNextMeaningfulToken(end($matchedTokenIndexes)));
     if (!$isArray) {
         return;
     }
     do {
         $index = $tokens->getNextMeaningfulToken($index);
         $token = $tokens[$index];
         if (!$token->isGivenKind(T_CONSTANT_ENCAPSED_STRING)) {
             continue;
         }
         if ("'{$oldName}'" === $token->getContent()) {
             $token->setContent("'{$newName}'");
         }
     } while (!in_array($token->getContent(), [')', ']']));
     $this->fixOptionNames($tokens, $fieldNameTokens, $oldName, $newName, $index);
 }