Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code-sniffs other than line length to scrutinizer
- Loading branch information
1 parent
17ac2e3
commit b9d5f27
Showing
5 changed files
with
63 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tools: | ||
custom_commands: | ||
- | ||
scope: file | ||
command: php tests/phpcs_runner.php %pathname% |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
if(php_sapi_name() != 'cli') { | ||
die("This script must be called from the command line\n"); | ||
} | ||
|
||
if(!empty($_SERVER['argv'][1])) { | ||
$path = $_SERVER['argv'][1]; | ||
} else { | ||
die("Usage: php {$_SERVER['argv'][0]} <file>\n"); | ||
} | ||
|
||
$result = array('comments' => array()); | ||
|
||
// Run each sniff | ||
|
||
// phpcs --encoding=utf-8 --standard=framework/tests/phpcs/tabs.xml | ||
run_sniff('tabs.xml', $path, $result); | ||
|
||
// phpcs --encoding=utf-8 --tab-width=4 --standard=framework/tests/phpcs/ruleset.xml | ||
run_sniff('ruleset.xml', $path, $result, '--tab-width=4'); | ||
|
||
echo json_encode($result); | ||
|
||
function run_sniff($standard, $path, array &$result, $extraFlags = '') { | ||
$sniffPath = escapeshellarg(__DIR__ . '/phpcs/' . $standard); | ||
$checkPath = escapeshellarg($path); | ||
|
||
exec("phpcs --encoding=utf-8 $extraFlags --standard=$sniffPath --report=xml $checkPath", $output); | ||
|
||
// We can't check the return code as it's non-zero if the sniff finds an error | ||
if($output) { | ||
$xml = implode("\n", $output); | ||
$xml = simplexml_load_string($xml); | ||
$errors = $xml->xpath('/phpcs/file/error'); | ||
if($errors) { | ||
$sanePath = str_replace('/', '_', $path); | ||
foreach($errors as $error) { | ||
$attributes = $error->attributes(); | ||
$result['comments'][] = array( | ||
'line' => (int)strval($attributes->line), | ||
'id' => $standard . '-' . $sanePath . '-' . $attributes->line . '-' . $attributes->column, | ||
'message' => strval($error) | ||
); | ||
} | ||
} | ||
} | ||
} |