src/Fixer/Whitespace/IndentationTypeFixer.php
private function fixIndentToken(Tokens $tokens, $index)
    {
        $content = $tokens[$index]->getContent();
        $previousTokenHasTrailingLinebreak = false;

        // @TODO 3.0 this can be removed when we have a transformer for "T_OPEN_TAG" to "T_OPEN_TAG + T_WHITESPACE"
        if (false !== strpos($tokens[$index - 1]->getContent(), "\n")) {
            $content = "\n".$content;
            $previousTokenHasTrailingLinebreak = true;
        }

        $indent = $this->indent;
        $newContent = Preg::replaceCallback(
            '/(\R)(\h+)/', // find indent
            static function (array $matches) use ($indent) {
                // normalize mixed indent
                $content = Preg::replace('/(?:(?<! ) {1,3})?\t/', '    ', $matches[2]);

                // change indent to expected one
                return $matches[1].str_replace('    ', $indent, $content);
            },
            $content
        );

        if ($previousTokenHasTrailingLinebreak) {
            $newContent = substr($newContent, 1);
        }

        return new Token([T_WHITESPACE, $newContent]);
    }
private function fixIndentToken(Tokens $tokens, $index)
    {
        $content = $tokens[$index]->getContent();
        $previousTokenHasTrailingLinebreak = false;

        // @TODO 3.0 this can be removed when we have a transformer for "T_OPEN_TAG" to "T_OPEN_TAG + T_WHITESPACE"
        if (false !== strpos($tokens[$index - 1]->getContent(), "\n")) {
            $content = "\n".$content;
            $previousTokenHasTrailingLinebreak = true;
        }

        $indent = $this->indent;
        $newContent = Preg::replaceCallback(
            '/(\R)(\h+)/', // find indent
            static function (array $matches) use ($indent) {
                // normalize mixed indent
                $content = Preg::replace('/(?:(?<! ) {1,3})?\t/', '    ', $matches[2]);

                // change indent to expected one
                return $matches[1].str_replace('    ', $indent, $content);
            },
            $content
        );

        if ($previousTokenHasTrailingLinebreak) {
            $newContent = substr($newContent, 1);
        }

        return new Token([T_WHITESPACE, $newContent]);
    }
private function fixIndentToken ( Tokens $ tokens , $ index ) { $ content = $ tokens [ $ index ] -> getContent ( ) ; $ previousTokenHasTrailingLinebreak = false ; // @TODO 3.0 this can be removed when we have a transformer for "T_OPEN_TAG" to "T_OPEN_TAG + T_WHITESPACE" if ( false !== strpos ( $ tokens [ $ index - 1 ] -> getContent ( ) , "\n" ) ) { $ content = "\n" . $ content ; $ previousTokenHasTrailingLinebreak = true ; } $ indent = $ this -> indent ; $ newContent = Preg :: replaceCallback ( '/(\R)(\h+)/' , // find indent static function ( array $ matches ) use ( $ indent ) { // normalize mixed indent $ content = Preg :: replace ( '/(?:(?<! ) {1,3})?\t/' , '    ' , $ matches [ 2 ] ) ; // change indent to expected one return $ matches [ 1 ] . str_replace ( '    ' , $ indent , $ content ) ; } , $ content ) ; if ( $ previousTokenHasTrailingLinebreak ) { $ newContent = substr ( $ newContent , 1 ) ; } return new Token ( [ T_WHITESPACE , $ newContent ] ) ; }
@param Tokens $tokens
@param int    $index

@return Token
@param Tokens $tokens @param int $index