protected function isClosure(File $phpcsFile, $stackPtr, $scopeConditionPtr)
    {
        $tokens = $phpcsFile->getTokens();

        if ($this->isScopeCondition($phpcsFile, $scopeConditionPtr, T_CLOSURE) === true
            && ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true
            || $phpcsFile->hasCondition($stackPtr, T_CLOSURE) === true
            || isset($tokens[$stackPtr]['nested_parenthesis']) === true)
        ) {
            return true;
        }

        return false;
    }