Skip to content

Instantly share code, notes, and snippets.

@tomjn
Created May 9, 2018 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomjn/096095c0fceef80462f1b11ccbdcb431 to your computer and use it in GitHub Desktop.
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
<?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";
@gsherwood
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment