Created
May 9, 2018 18:13
-
-
Save tomjn/096095c0fceef80462f1b11ccbdcb431 to your computer and use it in GitHub Desktop.
BEHOLD probably one of the hackiest things I've done in a long time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once( 'vendor/squizlabs/php_codesniffer/autoload.php' ); | |
// set the current working directory as the current directory | |
chdir( __DIR__ ); | |
$_SERVER['argv'] = [ | |
'phpcs', | |
'test.php', | |
'--report=json', | |
]; | |
ob_start(); | |
$runner = new \PHP_CodeSniffer\Runner(); | |
$exitCode = $runner->runPHPCS(); | |
$phpcs_output = ob_get_clean(); | |
echo "This is the output:\n"; | |
echo $phpcs_output."\n"; | |
echo "all good?\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also do this without trying to replicate
argv
. See this example, which uses a dummy file to process content but could be changed to process a file path as well: https://gist.github.com/gsherwood/aafd2c16631a8a872f0c4a23916962ac