From ea80d49a0310e28c846aa30bca564e7ab575be99 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Mon, 19 Oct 2015 23:30:27 +0000 Subject: [PATCH 1/2] Updating PHPLint plugin to output to be build log --- PHPCI/Languages/lang.en.php | 1 + PHPCI/Plugin/Lint.php | 45 ++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/PHPCI/Languages/lang.en.php b/PHPCI/Languages/lang.en.php index eec2ee07..41e01ead 100644 --- a/PHPCI/Languages/lang.en.php +++ b/PHPCI/Languages/lang.en.php @@ -432,6 +432,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', diff --git a/PHPCI/Plugin/Lint.php b/PHPCI/Plugin/Lint.php index a7ddc55c..11c0c620 100644 --- a/PHPCI/Plugin/Lint.php +++ b/PHPCI/Plugin/Lint.php @@ -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; } @@ -140,8 +163,24 @@ class Lint implements PHPCI\Plugin { $success = true; - if (!$this->phpci->executeCommand($php . ' -l "%s"', $this->phpci->buildPath . $path)) { - $this->phpci->logFailure($path); + if (!$this->phpci->executeCommand($php . ' -d display_errors=0 -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++; + $success = false; } From fe281e5c75eb520d4d7fdd990efea12e95f544bb Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Thu, 22 Oct 2015 15:31:33 +0100 Subject: [PATCH 2/2] Update Lint.php --- PHPCI/Plugin/Lint.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/PHPCI/Plugin/Lint.php b/PHPCI/Plugin/Lint.php index 11c0c620..73031dd3 100644 --- a/PHPCI/Plugin/Lint.php +++ b/PHPCI/Plugin/Lint.php @@ -161,9 +161,7 @@ class Lint implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin */ protected function lintFile($php, $path) { - $success = true; - - if (!$this->phpci->executeCommand($php . ' -d display_errors=0 -l "%s" 2>&1', $this->phpci->buildPath . $path)) { + 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);