src/AbstractAlignFixerHelper.php
protected function replacePlaceholder(Tokens $tokens)
    {
        $tmpCode = $tokens->generateCode();

        for ($j = 0; $j <= $this->deepestLevel; ++$j) {
            $placeholder = sprintf(self::ALIGNABLE_PLACEHOLDER, $j);

            if (false === strpos($tmpCode, $placeholder)) {
                continue;
            }

            $lines = explode("\n", $tmpCode);
            $linesWithPlaceholder = [];
            $blockSize = 0;

            $linesWithPlaceholder[$blockSize] = [];

            foreach ($lines as $index => $line) {
                if (substr_count($line, $placeholder) > 0) {
                    $linesWithPlaceholder[$blockSize][] = $index;
                } else {
                    ++$blockSize;
                    $linesWithPlaceholder[$blockSize] = [];
                }
            }

            foreach ($linesWithPlaceholder as $group) {
                if (\count($group) < 1) {
                    continue;
                }

                $rightmostSymbol = 0;
                foreach ($group as $index) {
                    $rightmostSymbol = max($rightmostSymbol, strpos(utf8_decode($lines[$index]), $placeholder));
                }

                foreach ($group as $index) {
                    $line = $lines[$index];
                    $currentSymbol = strpos(utf8_decode($line), $placeholder);
                    $delta = abs($rightmostSymbol - $currentSymbol);

                    if ($delta > 0) {
                        $line = str_replace($placeholder, str_repeat(' ', $delta).$placeholder, $line);
                        $lines[$index] = $line;
                    }
                }
            }

            $tmpCode = str_replace($placeholder, '', implode("\n", $lines));
        }

        return $tmpCode;
    }
protected function replacePlaceholder(Tokens $tokens)
    {
        $tmpCode = $tokens->generateCode();

        for ($j = 0; $j <= $this->deepestLevel; ++$j) {
            $placeholder = sprintf(self::ALIGNABLE_PLACEHOLDER, $j);

            if (false === strpos($tmpCode, $placeholder)) {
                continue;
            }

            $lines = explode("\n", $tmpCode);
            $linesWithPlaceholder = [];
            $blockSize = 0;

            $linesWithPlaceholder[$blockSize] = [];

            foreach ($lines as $index => $line) {
                if (substr_count($line, $placeholder) > 0) {
                    $linesWithPlaceholder[$blockSize][] = $index;
                } else {
                    ++$blockSize;
                    $linesWithPlaceholder[$blockSize] = [];
                }
            }

            foreach ($linesWithPlaceholder as $group) {
                if (\count($group) < 1) {
                    continue;
                }

                $rightmostSymbol = 0;
                foreach ($group as $index) {
                    $rightmostSymbol = max($rightmostSymbol, strpos(utf8_decode($lines[$index]), $placeholder));
                }

                foreach ($group as $index) {
                    $line = $lines[$index];
                    $currentSymbol = strpos(utf8_decode($line), $placeholder);
                    $delta = abs($rightmostSymbol - $currentSymbol);

                    if ($delta > 0) {
                        $line = str_replace($placeholder, str_repeat(' ', $delta).$placeholder, $line);
                        $lines[$index] = $line;
                    }
                }
            }

            $tmpCode = str_replace($placeholder, '', implode("\n", $lines));
        }

        return $tmpCode;
    }
protected function replacePlaceholder ( Tokens $ tokens ) { $ tmpCode = $ tokens -> generateCode ( ) ; for ( $ j = 0 ; $ j <= $ this -> deepestLevel ; ++ $ j ) { $ placeholder = sprintf ( self :: ALIGNABLE_PLACEHOLDER , $ j ) ; if ( false === strpos ( $ tmpCode , $ placeholder ) ) { continue ; } $ lines = explode ( "\n" , $ tmpCode ) ; $ linesWithPlaceholder = [ ] ; $ blockSize = 0 ; $ linesWithPlaceholder [ $ blockSize ] = [ ] ; foreach ( $ lines as $ index => $ line ) { if ( substr_count ( $ line , $ placeholder ) > 0 ) { $ linesWithPlaceholder [ $ blockSize ] [ ] = $ index ; } else { ++ $ blockSize ; $ linesWithPlaceholder [ $ blockSize ] = [ ] ; } } foreach ( $ linesWithPlaceholder as $ group ) { if ( \ count ( $ group ) < 1 ) { continue ; } $ rightmostSymbol = 0 ; foreach ( $ group as $ index ) { $ rightmostSymbol = max ( $ rightmostSymbol , strpos ( utf8_decode ( $ lines [ $ index ] ) , $ placeholder ) ) ; } foreach ( $ group as $ index ) { $ line = $ lines [ $ index ] ; $ currentSymbol = strpos ( utf8_decode ( $ line ) , $ placeholder ) ; $ delta = abs ( $ rightmostSymbol - $ currentSymbol ) ; if ( $ delta > 0 ) { $ line = str_replace ( $ placeholder , str_repeat ( ' ' , $ delta ) . $ placeholder , $ line ) ; $ lines [ $ index ] = $ line ; } } } $ tmpCode = str_replace ( $ placeholder , '' , implode ( "\n" , $ lines ) ) ; } return $ tmpCode ; }
Look for group of placeholders, and provide vertical alignment.

@param Tokens $tokens

@return string
Look for group of placeholders and provide vertical alignment .