protected function getReturnTypes(File $phpCsFile, int $stackPointer): array
    {
        $tokens = $phpCsFile->getTokens();

        // We skip for interface methods
        if (empty($tokens[$stackPointer]['scope_opener']) || empty($tokens[$stackPointer]['scope_closer'])) {
            return [];
        }

        $scopeOpener = $tokens[$stackPointer]['scope_opener'];
        $scopeCloser = $tokens[$stackPointer]['scope_closer'];

        $returnTypes = [];
        for ($i = $scopeOpener; $i < $scopeCloser; $i++) {
            if ($tokens[$i]['code'] !== T_RETURN) {
                continue;
            }

            if (in_array(T_CLOSURE, $tokens[$i]['conditions'])) {
                continue;
            }

            $contentIndex = $phpCsFile->findNext(Tokens::$emptyTokens, $i + 1, $scopeCloser, true);
            if (!$contentIndex) {
                continue;
            }

            if ($tokens[$contentIndex]['code'] === T_PARENT) {
                $parentMethodName = $tokens[$contentIndex + 2]['content'];

                if ($parentMethodName === FunctionHelper::getName($phpCsFile, $stackPointer)) {
                    continue;
                }
            }

            $returnTypes[] = $tokens[$contentIndex]['content'];
        }

        return array_unique($returnTypes);
    }
protected function getReturnTypes(File $phpCsFile, int $stackPointer): array
    {
        $tokens = $phpCsFile->getTokens();

        // We skip for interface methods
        if (empty($tokens[$stackPointer]['scope_opener']) || empty($tokens[$stackPointer]['scope_closer'])) {
            return [];
        }

        $scopeOpener = $tokens[$stackPointer]['scope_opener'];
        $scopeCloser = $tokens[$stackPointer]['scope_closer'];

        $returnTypes = [];
        for ($i = $scopeOpener; $i < $scopeCloser; $i++) {
            if ($tokens[$i]['code'] !== T_RETURN) {
                continue;
            }

            if (in_array(T_CLOSURE, $tokens[$i]['conditions'])) {
                continue;
            }

            $contentIndex = $phpCsFile->findNext(Tokens::$emptyTokens, $i + 1, $scopeCloser, true);
            if (!$contentIndex) {
                continue;
            }

            if ($tokens[$contentIndex]['code'] === T_PARENT) {
                $parentMethodName = $tokens[$contentIndex + 2]['content'];

                if ($parentMethodName === FunctionHelper::getName($phpCsFile, $stackPointer)) {
                    continue;
                }
            }

            $returnTypes[] = $tokens[$contentIndex]['content'];
        }

        return array_unique($returnTypes);
    }
protected function getReturnTypes ( File $ phpCsFile , int $ stackPointer ) : array { $ tokens = $ phpCsFile -> getTokens ( ) ; // We skip for interface methods if ( empty ( $ tokens [ $ stackPointer ] [ 'scope_opener' ] ) || empty ( $ tokens [ $ stackPointer ] [ 'scope_closer' ] ) ) { return [ ] ; } $ scopeOpener = $ tokens [ $ stackPointer ] [ 'scope_opener' ] ; $ scopeCloser = $ tokens [ $ stackPointer ] [ 'scope_closer' ] ; $ returnTypes = [ ] ; for ( $ i = $ scopeOpener ; $ i < $ scopeCloser ; $ i ++ ) { if ( $ tokens [ $ i ] [ 'code' ] !== T_RETURN ) { continue ; } if ( in_array ( T_CLOSURE , $ tokens [ $ i ] [ 'conditions' ] ) ) { continue ; } $ contentIndex = $ phpCsFile -> findNext ( Tokens :: $ emptyTokens , $ i + 1 , $ scopeCloser , true ) ; if ( ! $ contentIndex ) { continue ; } if ( $ tokens [ $ contentIndex ] [ 'code' ] === T_PARENT ) { $ parentMethodName = $ tokens [ $ contentIndex + 2 ] [ 'content' ] ; if ( $ parentMethodName === FunctionHelper :: getName ( $ phpCsFile , $ stackPointer ) ) { continue ; } } $ returnTypes [ ] = $ tokens [ $ contentIndex ] [ 'content' ] ; } return array_unique ( $ returnTypes ) ; }
We want to skip for static or other non chainable use cases.

@param \PHP_CodeSniffer\Files\File $phpCsFile
@param int $stackPointer

@return string[]
We want to skip for static or other non chainable use cases .