src/Fixer/Operator/BinaryOperatorSpacesFixer.php
private function replacePlaceholders(Tokens $tokens, $alignStrategy)
    {
        $tmpCode = $tokens->generateCode();

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

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

            $lines = explode("\n", $tmpCode);
            $groups = [];
            $groupIndex = 0;
            $groups[$groupIndex] = [];

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

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

                if (self::ALIGN !== $alignStrategy) {
                    // move place holders to match strategy
                    foreach ($group as $index) {
                        $currentPosition = strpos($lines[$index], $placeholder);
                        $before = substr($lines[$index], 0, $currentPosition);

                        if (self::ALIGN_SINGLE_SPACE === $alignStrategy) {
                            if (1 > \strlen($before) || ' ' !== substr($before, -1)) { // if last char of before-content is not ' '; add it
                                $before .= ' ';
                            }
                        } elseif (self::ALIGN_SINGLE_SPACE_MINIMAL === $alignStrategy) {
                            if (1 !== Preg::match('/^\h+$/', $before)) { // if indent; do not move, leave to other fixer
                                $before = rtrim($before).' ';
                            }
                        }

                        $lines[$index] = $before.substr($lines[$index], $currentPosition);
                    }
                }

                $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;
    }
private function replacePlaceholders(Tokens $tokens, $alignStrategy)
    {
        $tmpCode = $tokens->generateCode();

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

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

            $lines = explode("\n", $tmpCode);
            $groups = [];
            $groupIndex = 0;
            $groups[$groupIndex] = [];

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

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

                if (self::ALIGN !== $alignStrategy) {
                    // move place holders to match strategy
                    foreach ($group as $index) {
                        $currentPosition = strpos($lines[$index], $placeholder);
                        $before = substr($lines[$index], 0, $currentPosition);

                        if (self::ALIGN_SINGLE_SPACE === $alignStrategy) {
                            if (1 > \strlen($before) || ' ' !== substr($before, -1)) { // if last char of before-content is not ' '; add it
                                $before .= ' ';
                            }
                        } elseif (self::ALIGN_SINGLE_SPACE_MINIMAL === $alignStrategy) {
                            if (1 !== Preg::match('/^\h+$/', $before)) { // if indent; do not move, leave to other fixer
                                $before = rtrim($before).' ';
                            }
                        }

                        $lines[$index] = $before.substr($lines[$index], $currentPosition);
                    }
                }

                $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;
    }
private function replacePlaceholders ( Tokens $ tokens , $ alignStrategy ) { $ tmpCode = $ tokens -> generateCode ( ) ; for ( $ j = 0 ; $ j <= $ this -> deepestLevel ; ++ $ j ) { $ placeholder = sprintf ( self :: ALIGN_PLACEHOLDER , $ j ) ; if ( false === strpos ( $ tmpCode , $ placeholder ) ) { continue ; } $ lines = explode ( "\n" , $ tmpCode ) ; $ groups = [ ] ; $ groupIndex = 0 ; $ groups [ $ groupIndex ] = [ ] ; foreach ( $ lines as $ index => $ line ) { if ( substr_count ( $ line , $ placeholder ) > 0 ) { $ groups [ $ groupIndex ] [ ] = $ index ; } else { ++ $ groupIndex ; $ groups [ $ groupIndex ] = [ ] ; } } foreach ( $ groups as $ group ) { if ( \ count ( $ group ) < 1 ) { continue ; } if ( self :: ALIGN !== $ alignStrategy ) { // move place holders to match strategy foreach ( $ group as $ index ) { $ currentPosition = strpos ( $ lines [ $ index ] , $ placeholder ) ; $ before = substr ( $ lines [ $ index ] , 0 , $ currentPosition ) ; if ( self :: ALIGN_SINGLE_SPACE === $ alignStrategy ) { if ( 1 > \ strlen ( $ before ) || ' ' !== substr ( $ before , - 1 ) ) { // if last char of before-content is not ' '; add it $ before .= ' ' ; } } elseif ( self :: ALIGN_SINGLE_SPACE_MINIMAL === $ alignStrategy ) { if ( 1 !== Preg :: match ( '/^\h+$/' , $ before ) ) { // if indent; do not move, leave to other fixer $ before = rtrim ( $ before ) . ' ' ; } } $ lines [ $ index ] = $ before . substr ( $ lines [ $ index ] , $ currentPosition ) ; } } $ 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
@param string $alignStrategy

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