src/Fixer/ControlStructure/NoBreakCommentFixer.php
private function ensureNewLineAt(Tokens $tokens, $position)
    {
        $lineEnding = $this->whitespacesConfig->getLineEnding();
        $content = $lineEnding.$this->getIndentAt($tokens, $position);

        $whitespaceToken = $tokens[$position - 1];
        if (!$whitespaceToken->isGivenKind(T_WHITESPACE)) {
            if ($whitespaceToken->isGivenKind(T_OPEN_TAG)) {
                $content = Preg::replace('/\R/', '', $content);
                if (!Preg::match('/\R/', $whitespaceToken->getContent())) {
                    $tokens[$position - 1] = new Token([T_OPEN_TAG, Preg::replace('/\s+$/', $lineEnding, $whitespaceToken->getContent())]);
                }
            }

            if ('' !== $content) {
                $tokens->insertAt($position, new Token([T_WHITESPACE, $content]));

                return $position;
            }

            return $position - 1;
        }

        if ($tokens[$position - 2]->isGivenKind(T_OPEN_TAG) && Preg::match('/\R/', $tokens[$position - 2]->getContent())) {
            $content = Preg::replace('/^\R/', '', $content);
        }

        if (!Preg::match('/\R/', $whitespaceToken->getContent())) {
            $tokens[$position - 1] = new Token([T_WHITESPACE, $content]);
        }

        return $position - 1;
    }
private function ensureNewLineAt(Tokens $tokens, $position)
    {
        $lineEnding = $this->whitespacesConfig->getLineEnding();
        $content = $lineEnding.$this->getIndentAt($tokens, $position);

        $whitespaceToken = $tokens[$position - 1];
        if (!$whitespaceToken->isGivenKind(T_WHITESPACE)) {
            if ($whitespaceToken->isGivenKind(T_OPEN_TAG)) {
                $content = Preg::replace('/\R/', '', $content);
                if (!Preg::match('/\R/', $whitespaceToken->getContent())) {
                    $tokens[$position - 1] = new Token([T_OPEN_TAG, Preg::replace('/\s+$/', $lineEnding, $whitespaceToken->getContent())]);
                }
            }

            if ('' !== $content) {
                $tokens->insertAt($position, new Token([T_WHITESPACE, $content]));

                return $position;
            }

            return $position - 1;
        }

        if ($tokens[$position - 2]->isGivenKind(T_OPEN_TAG) && Preg::match('/\R/', $tokens[$position - 2]->getContent())) {
            $content = Preg::replace('/^\R/', '', $content);
        }

        if (!Preg::match('/\R/', $whitespaceToken->getContent())) {
            $tokens[$position - 1] = new Token([T_WHITESPACE, $content]);
        }

        return $position - 1;
    }
private function ensureNewLineAt ( Tokens $ tokens , $ position ) { $ lineEnding = $ this -> whitespacesConfig -> getLineEnding ( ) ; $ content = $ lineEnding . $ this -> getIndentAt ( $ tokens , $ position ) ; $ whitespaceToken = $ tokens [ $ position - 1 ] ; if ( ! $ whitespaceToken -> isGivenKind ( T_WHITESPACE ) ) { if ( $ whitespaceToken -> isGivenKind ( T_OPEN_TAG ) ) { $ content = Preg :: replace ( '/\R/' , '' , $ content ) ; if ( ! Preg :: match ( '/\R/' , $ whitespaceToken -> getContent ( ) ) ) { $ tokens [ $ position - 1 ] = new Token ( [ T_OPEN_TAG , Preg :: replace ( '/\s+$/' , $ lineEnding , $ whitespaceToken -> getContent ( ) ) ] ) ; } } if ( '' !== $ content ) { $ tokens -> insertAt ( $ position , new Token ( [ T_WHITESPACE , $ content ] ) ) ; return $ position ; } return $ position - 1 ; } if ( $ tokens [ $ position - 2 ] -> isGivenKind ( T_OPEN_TAG ) && Preg :: match ( '/\R/' , $ tokens [ $ position - 2 ] -> getContent ( ) ) ) { $ content = Preg :: replace ( '/^\R/' , '' , $ content ) ; } if ( ! Preg :: match ( '/\R/' , $ whitespaceToken -> getContent ( ) ) ) { $ tokens [ $ position - 1 ] = new Token ( [ T_WHITESPACE , $ content ] ) ; } return $ position - 1 ; }
@param Tokens $tokens
@param int    $position

@return int The newline token position
@param Tokens $tokens @param int $position