src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php
private function findWhitespaceBeforeFirstCall($index, Tokens $tokens)
    {
        // semicolon followed by a closing bracket?
        if (!$tokens[$index]->equals(')')) {
            return null;
        }

        // find opening bracket
        $openingBrackets = 1;
        for (--$index; $index > 0; --$index) {
            if ($tokens[$index]->equals(')')) {
                ++$openingBrackets;

                continue;
            }

            if ($tokens[$index]->equals('(')) {
                if (1 === $openingBrackets) {
                    break;
                }
                --$openingBrackets;
            }
        }

        // method name
        if (!$tokens[--$index]->isGivenKind(T_STRING)) {
            return null;
        }

        // -> or ::
        if (!$tokens[--$index]->isGivenKind([T_OBJECT_OPERATOR, T_DOUBLE_COLON])) {
            return null;
        }

        // white space
        if (!$tokens[--$index]->isGivenKind(T_WHITESPACE)) {
            return null;
        }

        $closingBrackets = 0;
        for ($index; $index >= 0; --$index) {
            if ($tokens[$index]->equals(')')) {
                ++$closingBrackets;
            }

            if ($tokens[$index]->equals('(')) {
                --$closingBrackets;
            }

            // must be the variable of the first call in the chain
            if ($tokens[$index]->isGivenKind([T_VARIABLE, T_RETURN, T_STRING]) && 0 === $closingBrackets) {
                if ($tokens[--$index]->isGivenKind(T_WHITESPACE)
                    || $tokens[$index]->isGivenKind(T_OPEN_TAG)) {
                    return $this->getIndentAt($tokens, $index);
                }
            }
        }

        return null;
    }
private function findWhitespaceBeforeFirstCall($index, Tokens $tokens)
    {
        // semicolon followed by a closing bracket?
        if (!$tokens[$index]->equals(')')) {
            return null;
        }

        // find opening bracket
        $openingBrackets = 1;
        for (--$index; $index > 0; --$index) {
            if ($tokens[$index]->equals(')')) {
                ++$openingBrackets;

                continue;
            }

            if ($tokens[$index]->equals('(')) {
                if (1 === $openingBrackets) {
                    break;
                }
                --$openingBrackets;
            }
        }

        // method name
        if (!$tokens[--$index]->isGivenKind(T_STRING)) {
            return null;
        }

        // -> or ::
        if (!$tokens[--$index]->isGivenKind([T_OBJECT_OPERATOR, T_DOUBLE_COLON])) {
            return null;
        }

        // white space
        if (!$tokens[--$index]->isGivenKind(T_WHITESPACE)) {
            return null;
        }

        $closingBrackets = 0;
        for ($index; $index >= 0; --$index) {
            if ($tokens[$index]->equals(')')) {
                ++$closingBrackets;
            }

            if ($tokens[$index]->equals('(')) {
                --$closingBrackets;
            }

            // must be the variable of the first call in the chain
            if ($tokens[$index]->isGivenKind([T_VARIABLE, T_RETURN, T_STRING]) && 0 === $closingBrackets) {
                if ($tokens[--$index]->isGivenKind(T_WHITESPACE)
                    || $tokens[$index]->isGivenKind(T_OPEN_TAG)) {
                    return $this->getIndentAt($tokens, $index);
                }
            }
        }

        return null;
    }
private function findWhitespaceBeforeFirstCall ( $ index , Tokens $ tokens ) { // semicolon followed by a closing bracket? if ( ! $ tokens [ $ index ] -> equals ( ')' ) ) { return null ; } // find opening bracket $ openingBrackets = 1 ; for ( -- $ index ; $ index > 0 ; -- $ index ) { if ( $ tokens [ $ index ] -> equals ( ')' ) ) { ++ $ openingBrackets ; continue ; } if ( $ tokens [ $ index ] -> equals ( '(' ) ) { if ( 1 === $ openingBrackets ) { break ; } -- $ openingBrackets ; } } // method name if ( ! $ tokens [ -- $ index ] -> isGivenKind ( T_STRING ) ) { return null ; } // -> or :: if ( ! $ tokens [ -- $ index ] -> isGivenKind ( [ T_OBJECT_OPERATOR , T_DOUBLE_COLON ] ) ) { return null ; } // white space if ( ! $ tokens [ -- $ index ] -> isGivenKind ( T_WHITESPACE ) ) { return null ; } $ closingBrackets = 0 ; for ( $ index ; $ index >= 0 ; -- $ index ) { if ( $ tokens [ $ index ] -> equals ( ')' ) ) { ++ $ closingBrackets ; } if ( $ tokens [ $ index ] -> equals ( '(' ) ) { -- $ closingBrackets ; } // must be the variable of the first call in the chain if ( $ tokens [ $ index ] -> isGivenKind ( [ T_VARIABLE , T_RETURN , T_STRING ] ) && 0 === $ closingBrackets ) { if ( $ tokens [ -- $ index ] -> isGivenKind ( T_WHITESPACE ) || $ tokens [ $ index ] -> isGivenKind ( T_OPEN_TAG ) ) { return $ this -> getIndentAt ( $ tokens , $ index ) ; } } } return null ; }
Checks if the semicolon closes a chained call and returns the whitespace of the first call at $index.
i.e. it will return the whitespace marked with '____' in the example underneath.

..
____$this->methodCall()
->anotherCall();
..

@param int $index

@return null|string
Checks if the semicolon closes a chained call and returns the whitespace of the first call at $index . i . e . it will return the whitespace marked with ____ in the example underneath .