src/Fixer/StringNotation/HeredocToNowdocFixer.php
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        foreach ($tokens as $index => $token) {
            if (!$token->isGivenKind(T_START_HEREDOC) || false !== strpos($token->getContent(), "'")) {
                continue;
            }

            if ($tokens[$index + 1]->isGivenKind(T_END_HEREDOC)) {
                $tokens[$index] = $this->convertToNowdoc($token);

                continue;
            }

            if (
                !$tokens[$index + 1]->isGivenKind(T_ENCAPSED_AND_WHITESPACE) ||
                !$tokens[$index + 2]->isGivenKind(T_END_HEREDOC)
            ) {
                continue;
            }

            $content = $tokens[$index + 1]->getContent();
            // regex: odd number of backslashes, not followed by dollar
            if (Preg::match('/(?<!\\\\)(?:\\\\{2})*\\\\(?![$\\\\])/', $content)) {
                continue;
            }

            $tokens[$index] = $this->convertToNowdoc($token);
            $content = str_replace(['\\\\', '\\$'], ['\\', '$'], $content);
            $tokens[$index + 1] = new Token([
                $tokens[$index + 1]->getId(),
                $content,
            ]);
        }
    }
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        foreach ($tokens as $index => $token) {
            if (!$token->isGivenKind(T_START_HEREDOC) || false !== strpos($token->getContent(), "'")) {
                continue;
            }

            if ($tokens[$index + 1]->isGivenKind(T_END_HEREDOC)) {
                $tokens[$index] = $this->convertToNowdoc($token);

                continue;
            }

            if (
                !$tokens[$index + 1]->isGivenKind(T_ENCAPSED_AND_WHITESPACE) ||
                !$tokens[$index + 2]->isGivenKind(T_END_HEREDOC)
            ) {
                continue;
            }

            $content = $tokens[$index + 1]->getContent();
            // regex: odd number of backslashes, not followed by dollar
            if (Preg::match('/(?<!\\\\)(?:\\\\{2})*\\\\(?![$\\\\])/', $content)) {
                continue;
            }

            $tokens[$index] = $this->convertToNowdoc($token);
            $content = str_replace(['\\\\', '\\$'], ['\\', '$'], $content);
            $tokens[$index + 1] = new Token([
                $tokens[$index + 1]->getId(),
                $content,
            ]);
        }
    }
protected function applyFix ( \ SplFileInfo $ file , Tokens $ tokens ) { foreach ( $ tokens as $ index => $ token ) { if ( ! $ token -> isGivenKind ( T_START_HEREDOC ) || false !== strpos ( $ token -> getContent ( ) , "'" ) ) { continue ; } if ( $ tokens [ $ index + 1 ] -> isGivenKind ( T_END_HEREDOC ) ) { $ tokens [ $ index ] = $ this -> convertToNowdoc ( $ token ) ; continue ; } if ( ! $ tokens [ $ index + 1 ] -> isGivenKind ( T_ENCAPSED_AND_WHITESPACE ) || ! $ tokens [ $ index + 2 ] -> isGivenKind ( T_END_HEREDOC ) ) { continue ; } $ content = $ tokens [ $ index + 1 ] -> getContent ( ) ; // regex: odd number of backslashes, not followed by dollar if ( Preg :: match ( '/(?<!\\\\)(?:\\\\{2})*\\\\(?![$\\\\])/' , $ content ) ) { continue ; } $ tokens [ $ index ] = $ this -> convertToNowdoc ( $ token ) ; $ content = str_replace ( [ '\\\\' , '\\$' ] , [ '\\' , '$' ] , $ content ) ; $ tokens [ $ index + 1 ] = new Token ( [ $ tokens [ $ index + 1 ] -> getId ( ) , $ content , ] ) ; } }
{@inheritdoc}
{