mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 16:22:42 +01:00
Simplify handling errors in PHPCS linter
Test Plan: libxml_use_internal_errors(true); $report_dom = new DOMDocument(); $report_dom->loadXML('<a</a>'); $report_dom = new DOMDocument(); $report_dom->loadXML('<a></a>'); $report_dom = new DOMDocument(); $report_dom->loadXML(''); print_r(libxml_get_errors()); Reviewers: aurelijus Reviewed By: aurelijus CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D2816
This commit is contained in:
parent
f931318894
commit
1708a03f96
1 changed files with 12 additions and 14 deletions
|
@ -32,7 +32,6 @@
|
||||||
final class ArcanistPhpcsLinter extends ArcanistLinter {
|
final class ArcanistPhpcsLinter extends ArcanistLinter {
|
||||||
|
|
||||||
private $reports;
|
private $reports;
|
||||||
private $stdout;
|
|
||||||
|
|
||||||
public function getLinterName() {
|
public function getLinterName() {
|
||||||
return 'PHPCS';
|
return 'PHPCS';
|
||||||
|
@ -86,27 +85,26 @@ final class ArcanistPhpcsLinter extends ArcanistLinter {
|
||||||
foreach (Futures($futures)->limit(8) as $path => $future) {
|
foreach (Futures($futures)->limit(8) as $path => $future) {
|
||||||
$this->results[$path] = $future->resolve();
|
$this->results[$path] = $future->resolve();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected function loadXmlException() {
|
libxml_use_internal_errors(true);
|
||||||
throw new ArcanistUsageException('PHPCS Linter failed to load ' .
|
|
||||||
'reporting file. Something happened when running phpcs. ' .
|
|
||||||
"Output:\n$this->stdout" .
|
|
||||||
"\nTry running lint with --trace flag to get more details.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lintPath($path) {
|
public function lintPath($path) {
|
||||||
list($rc, $stdout) = $this->results[$path];
|
list($rc, $stdout) = $this->results[$path];
|
||||||
|
|
||||||
$report = Filesystem::readFile($this->reports[$path]);
|
$report = Filesystem::readFile($this->reports[$path]);
|
||||||
$report_dom = new DOMDocument();
|
|
||||||
|
|
||||||
// Unfortunately loadXML does not have normal error reporting,
|
if ($report) {
|
||||||
// so we need temporary to take over error handler
|
$report_dom = new DOMDocument();
|
||||||
set_error_handler(array($this, 'loadXmlException'));
|
libxml_clear_errors();
|
||||||
$this->stdout = $stdout;
|
|
||||||
$report_dom->loadXML($report);
|
$report_dom->loadXML($report);
|
||||||
restore_error_handler();
|
}
|
||||||
|
if (!$report || libxml_get_errors()) {
|
||||||
|
throw new ArcanistUsageException('PHPCS Linter failed to load ' .
|
||||||
|
'reporting file. Something happened when running phpcs. ' .
|
||||||
|
"Output:\n$stdout" .
|
||||||
|
"\nTry running lint with --trace flag to get more details.");
|
||||||
|
}
|
||||||
|
|
||||||
$files = $report_dom->getElementsByTagName('file');
|
$files = $report_dom->getElementsByTagName('file');
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|
Loading…
Reference in a new issue