This commit is contained in:
Stephen Ball 2016-09-17 06:14:34 +00:00 committed by GitHub
commit 1caed68b53
2 changed files with 42 additions and 4 deletions

View file

@ -435,6 +435,7 @@ PHPCI',
// Plugins that generate errors:
'php_mess_detector' => 'PHP Mess Detector',
'php_code_sniffer' => 'PHP Code Sniffer',
'php_lint' => 'PHP Lint',
'php_unit' => 'PHP Unit',
'php_cpd' => 'PHP Copy/Paste Detector',
'php_docblock_checker' => 'PHP Docblock Checker',

View file

@ -19,13 +19,14 @@ use PHPCI\Model\Build;
* @package PHPCI
* @subpackage Plugins
*/
class Lint implements PHPCI\Plugin
class Lint implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
{
protected $directories;
protected $recursive = true;
protected $ignore;
protected $phpci;
protected $build;
protected $errors = 0;
/**
* Standard Constructor
@ -59,6 +60,22 @@ class Lint implements PHPCI\Plugin
}
}
/**
* Check if this plugin can be executed.
* @param $stage
* @param Builder $builder
* @param Build $build
* @return bool
*/
public static function canExecute($stage, Builder $builder, Build $build)
{
if ($stage == 'test') {
return true;
}
return false;
}
/**
* Executes parallel lint
*/
@ -69,14 +86,20 @@ class Lint implements PHPCI\Plugin
$php = $this->phpci->findBinary('php');
$this->phpci->logExecOutput(false);
foreach ($this->directories as $dir) {
if (!$this->lintDirectory($php, $dir)) {
$success = false;
}
}
$this->phpci->logExecOutput(true);
$this->phpci->quiet = false;
$this->build->storeMeta('phplint-warnings', $this->errors);
return $success;
}
@ -138,10 +161,24 @@ class Lint implements PHPCI\Plugin
*/
protected function lintFile($php, $path)
{
$success = true;
if (!$this->phpci->executeCommand($php . ' -d error_reporting=E_ALL -d display_errors=0 -n -l "%s" 2>&1', $this->phpci->buildPath . $path)) {
$output = $this->phpci->getLastOutput();
preg_match('/Parse error:\s*syntax error,(.+?)\s+in\s+.+?\s*line\s+(\d+)/', $output, $matches);
$line = trim($matches[2]);
$this->build->reportError(
$this->phpci,
'php_lint',
trim((string) $matches[1]),
PHPCI\Model\BuildError::SEVERITY_HIGH,
$path,
(int) $line
);
$this->errors++;
if (!$this->phpci->executeCommand($php . ' -l "%s"', $this->phpci->buildPath . $path)) {
$this->phpci->logFailure($path);
$success = false;
}