tokens = $phpcsFile->getTokens(); $this->file = $phpcsFile; $this->leftLimit = $open = $this->tokens[$stackPtr]['parenthesis_opener']; $this->rightLimit = $close = $this->tokens[$stackPtr]['parenthesis_closer']; for ($i = ($open + 1); $i < $close; $i++) { if (($this->tokens[$i]['code'] === T_STRING && in_array($this->tokens[$i]['content'], $this->functions)) && (!$this->findIdentical($i - 1, $this->findFunctionParenthesisCloser($i) + 1)) ) { $foundFunctionName = $this->tokens[$i]['content']; $phpcsFile->addError($this->errorMessage, $i, $this->errorCode, [$foundFunctionName]); } } } /** * Recursively finds identical operators in current scope. * * @param int $leftCurrentPosition * @param int $rightCurrentPosition * @return bool */ protected function findIdentical($leftCurrentPosition, $rightCurrentPosition) { $leftBound = $this->file->findPrevious($this->leftRangeTokens, $leftCurrentPosition, $this->leftLimit - 1); $rightBound = $this->file->findNext($this->rightRangeTokens, $rightCurrentPosition, $this->rightLimit + 1); $leftToken = $this->tokens[$leftBound]; $rightToken = $this->tokens[$rightBound]; if ($leftToken['code'] === T_OPEN_PARENTHESIS && $rightToken['code'] === T_CLOSE_PARENTHESIS) { return $this->findIdentical($leftBound - 1, $rightBound + 1); } else { return ( in_array($leftToken['code'], $this->identical) || in_array($rightToken['code'], $this->identical) ) ?: false; } } /** * Finds the position of close parenthesis of detected function. * * @param int $currentPosition * @return mixed */ protected function findFunctionParenthesisCloser($currentPosition) { $nextOpenParenthesis = $this->file->findNext(T_OPEN_PARENTHESIS, $currentPosition, $this->rightLimit); return $nextOpenParenthesis ? $this->tokens[$nextOpenParenthesis]['parenthesis_closer'] : false; } }