extensions/felixfbecker.php-intellisense-0.0.12/vendor/felixfbecker/language-server/src/Formatter.php
/**
     * Generate array of TextEdit changes for content formatting.
     *
     * @param string $content source code to format
     * @param string $uri URI of document
     *
     * @return \LanguageServer\Protocol\TextEdit[]
     * @throws \Exception
     */
Generate array of TextEdit changes for content formatting.
@param string $content source code to format
@param string $uri URI of document


Generate array of TextEdit changes for content formatting . @param string $content source code to format @param string $uri URI of document
public static function format(string $content, string $uri)
    {
        if (!defined('PHP_CODESNIFFER_CBF')) {
            define('PHP_CODESNIFFER_CBF', true);
        }
        if (!defined('PHP_CODESNIFFER_VERBOSITY')) {
            define('PHP_CODESNIFFER_VERBOSITY', false);
        }
        $path = uriToPath($uri);
        $config = new Config(['dummy'], false);
        $config->standards = self::findConfiguration($path);
        spl_autoload_call(Tokens::class);
        $file = new DummyFile($content, new Ruleset($config), $config);
        $file->process();
        $fixed = $file->fixer->fixFile();
        if (!$fixed && $file->getErrorCount() > 0) {
            throw new Exception('Unable to format file');
        }
        $new = $file->fixer->getContents();
        if ($content === $new) {
            return [];
        }
        return [new TextEdit(new Range(new Position(0, 0), self::calculateEndPosition($content)), $new)];
    }
public static function format ( string $ content , string $ uri ) { if ( ! defined ( 'PHP_CODESNIFFER_CBF' ) ) { define ( 'PHP_CODESNIFFER_CBF' , true ) ; } if ( ! defined ( 'PHP_CODESNIFFER_VERBOSITY' ) ) { define ( 'PHP_CODESNIFFER_VERBOSITY' , false ) ; } $ path = uriToPath ( $ uri ) ; $ config = new Config ( [ 'dummy' ] , false ) ; $ config -> standards = self :: findConfiguration ( $ path ) ; spl_autoload_call ( Tokens :: class ) ; $ file = new DummyFile ( $ content , new Ruleset ( $ config ) , $ config ) ; $ file -> process ( ) ; $ fixed = $ file -> fixer -> fixFile ( ) ; if ( ! $ fixed && $ file -> getErrorCount ( ) > 0 ) { throw new Exception ( 'Unable to format file' ) ; } $ new = $ file -> fixer -> getContents ( ) ; if ( $ content === $ new ) { return [ ] ; } return [ new TextEdit ( new Range ( new Position ( 0 , 0 ) , self :: calculateEndPosition ( $ content ) ) , $ new ) ] ; }
Generate array of TextEdit changes for content formatting.
Generate array of TextEdit changes for content formatting .
// Autoload class to set up a bunch of PHP_CodeSniffer-specific token type constants