Mmoreram\PHPFormatter\Compiler\Compiler::stripWhitespace PHP Метод

stripWhitespace() защищенный Метод

Removes whitespace from a PHP source string while preserving line numbers.
protected stripWhitespace ( string $source ) : string
$source string A PHP string
Результат string The PHP string with the whitespace removed
    protected function stripWhitespace($source)
    {
        if (!function_exists('token_get_all')) {
            return $source;
        }
        $output = '';
        foreach (token_get_all($source) as $token) {
            if (is_string($token)) {
                $output .= $token;
            } elseif (in_array($token[0], [T_COMMENT, T_DOC_COMMENT])) {
                $output .= str_repeat("\n", substr_count($token[1], "\n"));
            } elseif (T_WHITESPACE === $token[0]) {
                // reduce wide spaces
                $whitespace = preg_replace('{[ \\t]+}', ' ', $token[1]);
                // normalize newlines to \n
                $whitespace = preg_replace('{(?:\\r\\n|\\r|\\n)}', "\n", $whitespace);
                // trim leading spaces
                $whitespace = preg_replace('{\\n +}', "\n", $whitespace);
                $output .= $whitespace;
            } else {
                $output .= $token[1];
            }
        }
        return $output;
    }