squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

Storing formatted code in a variable as a string within PHP scripts #3547

Open onet4 opened 2 years ago

onet4 commented 2 years ago

Hello,

I'm looking for a way to store formatted code as a string in a variable within PHP scripts, not from a console program. Is it possible with this library? Something like,

    $phpcbf = new \PHP_CodeSniffer\Fixer();
    $phpcbf->setConfig($config);
    $fixedCode = $phpcbf->getFormatted($codeToFix);