From d6f72b0b7e66c74ae70db440d379a3000637279d Mon Sep 17 00:00:00 2001 From: James Inman Date: Wed, 18 Feb 2015 14:26:21 +0000 Subject: [PATCH] PHPCS/PHPMD fixes for Technical Debt plugin. --- PHPCI/Plugin/TechnicalDebt.php | 40 +++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/PHPCI/Plugin/TechnicalDebt.php b/PHPCI/Plugin/TechnicalDebt.php index 408f40fb..71ff0052 100755 --- a/PHPCI/Plugin/TechnicalDebt.php +++ b/PHPCI/Plugin/TechnicalDebt.php @@ -122,21 +122,42 @@ class TechnicalDebt implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin } /** - * Runs in a specified directory, to a specified standard. + * Runs the plugin */ public function execute() { $this->phpci->logExecOutput(false); - $ignores = $this->ignore; - $ignores[] = 'phpci.yml'; + list($errorCount, $data) = $this->getErrorList(); + $this->phpci->log("Found $errorCount instances of " . implode(', ', $this->searches)); + + $this->build->storeMeta('technical_debt-warnings', $errorCount); + $this->build->storeMeta('technical_debt-data', $data); + + if ($this->allowed_errors != -1 && $errorCount > $this->allowed_errors) { + $success = false; + } + + return $success; + } + + /** + * Gets the number and list of errors returned from the search + * + * @return array + */ + public function getErrorList() + { $dirIterator = new \RecursiveDirectoryIterator($this->directory); $iterator = new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::SELF_FIRST); $files = []; + $ignores = $this->ignore; + $ignores[] = 'phpci.yml'; + foreach ($iterator as $file) { - $filePath = $file->getRealPath(); + $filePath = $file->getRealPath(); $skipFile = false; foreach ($ignores as $ignore) { if (stripos($filePath, $ignore) !== false) { @@ -180,16 +201,5 @@ class TechnicalDebt implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin } } } - - $this->phpci->log("Found $errorCount instances of " . implode(', ', $this->searches)); - - $this->build->storeMeta('technical_debt-warnings', $errorCount); - $this->build->storeMeta('technical_debt-data', $data); - - if ($this->allowed_errors != -1 && $errorCount > $this->allowed_errors) { - $success = false; - } - - return $success; } }