Adding PHPCS report parsing.
This commit is contained in:
parent
195d85a82c
commit
cc4bd7011b
|
@ -151,7 +151,7 @@ class PhpCodeSniffer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
return false;
|
||||
}
|
||||
|
||||
$cmd = $phpcs . ' --report=emacs %s %s %s %s %s "%s"';
|
||||
$cmd = $phpcs . ' --report=json %s %s %s %s %s "%s"';
|
||||
$this->phpci->executeCommand(
|
||||
$cmd,
|
||||
$standard,
|
||||
|
@ -163,26 +163,19 @@ class PhpCodeSniffer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
);
|
||||
|
||||
$output = $this->phpci->getLastOutput();
|
||||
list($errors, $warnings, $data) = $this->processReport(json_decode(trim($output), true));
|
||||
|
||||
$success = true;
|
||||
$matches = array();
|
||||
if (preg_match_all('/\: warning \-/', $output, $matches)) {
|
||||
$warnings = count($matches[0]);
|
||||
$this->build->storeMeta('phpcs-warnings', $warnings);
|
||||
$this->build->storeMeta('phpcs-warnings', $warnings);
|
||||
$this->build->storeMeta('phpcs-errors', $errors);
|
||||
$this->build->storeMeta('phpcs-data', $data);
|
||||
|
||||
if ($this->allowed_warnings != -1 && $warnings > $this->allowed_warnings) {
|
||||
$success = false;
|
||||
}
|
||||
if ($this->allowed_warnings != -1 && $warnings > $this->allowed_warnings) {
|
||||
$success = false;
|
||||
}
|
||||
|
||||
$matches = array();
|
||||
if (preg_match_all('/\: error \-/', $output, $matches)) {
|
||||
$errors = count($matches[0]);
|
||||
$this->build->storeMeta('phpcs-errors', $errors);
|
||||
|
||||
if ($this->allowed_errors != -1 && $errors > $this->allowed_errors) {
|
||||
$success = false;
|
||||
}
|
||||
if ($this->allowed_errors != -1 && $errors > $this->allowed_errors) {
|
||||
$success = false;
|
||||
}
|
||||
|
||||
return $success;
|
||||
|
@ -208,4 +201,31 @@ class PhpCodeSniffer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
|
||||
return array($ignore, $standard, $suffixes);
|
||||
}
|
||||
|
||||
protected function processReport($data)
|
||||
{
|
||||
if (!is_array($data)) {
|
||||
throw new \Exception('Could not process PHPCS report JSON.');
|
||||
}
|
||||
|
||||
$errors = $data['totals']['errors'];
|
||||
$warnings = $data['totals']['warnings'];
|
||||
|
||||
$rtn = array();
|
||||
|
||||
foreach ($data['files'] as $fileName => $file) {
|
||||
$fileName = str_replace($this->phpci->buildPath, '', $fileName);
|
||||
|
||||
foreach ($file['messages'] as $message) {
|
||||
$rtn[] = array(
|
||||
'file' => $fileName,
|
||||
'line' => $message['line'],
|
||||
'type' => $message['type'],
|
||||
'message' => $message['message'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array($errors, $warnings, $rtn);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue