diff --git a/PHPCI/Languages/lang.en.php b/PHPCI/Languages/lang.en.php index 63df75d2..17f302aa 100644 --- a/PHPCI/Languages/lang.en.php +++ b/PHPCI/Languages/lang.en.php @@ -440,5 +440,5 @@ PHPCI', 'php_docblock_checker' => 'PHP Docblock Checker', 'behat' => 'Behat', 'technical_debt' => 'Technical Debt', - + 'web_puc' => 'Web-Puc', ); diff --git a/PHPCI/Plugin/WebPuc.php b/PHPCI/Plugin/WebPuc.php new file mode 100644 index 00000000..017e228b --- /dev/null +++ b/PHPCI/Plugin/WebPuc.php @@ -0,0 +1,131 @@ + + * @package PHPCI + * @subpackage Plugins + */ +class WebPuc implements PHPCI\Plugin +{ + /** + * @var \PHPCI\Builder + */ + protected $phpci; + + /** + * @var \PHPCI\Model\Build + */ + protected $build; + + /** + * @var string + */ + protected $exclude; + + /** + * @var string + */ + protected $allowSupported; + + /** + * @var string + */ + protected $update; + + /** + * Standard Constructor + * + * $options['directory'] Output Directory. Default: %BUILDPATH% + * $options['filename'] Phar Filename. Default: build.phar + * $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/ + * $options['stub'] Stub Content. No Default Value + * + * @param Builder $phpci + * @param Build $build + * @param array $options + */ + public function __construct(Builder $phpci, Build $build, array $options = array()) + { + $this->phpci = $phpci; + $this->build = $build; + $this->directory = $phpci->buildPath; + + $this->exclude = ""; + $this->allowSupported = ""; + $this->update = ""; + + if (isset($options['exclude'])) { + $this->exclude = $options['exclude']; + } + if (isset($options['allow-supported'])) { + $this->allowSupported = $options['allow-supported']; + } + if (isset($options['update'])) { + $this->update = $options['update']; + } + } + + /** + * Runs Web-Puc. + */ + public function execute() + { + $path = $this->phpci->buildPath; + $webpuc = $this->phpci->findBinary('web-puc'); + $cmd = $webpuc . ' %s %s %s %s'; + + $exclude = ''; + if (!empty($this->exclude)) { + $exclude = ' -e "' . $this->exclude . '"'; + } + + $this->phpci->executeCommand( + $cmd, + $exclude, + $this->allowSupported, + $this->update, + $path + ); + $output = $this->phpci->getLastOutput(); + + $failed_findings = 0; + $stat = json_decode($output); + if ($stat === null) { + $this->phpci->log($output); + throw new \Exception('Could not parse web-puc output.'); + } + if(isset($stat->findings)) + foreach ($stat->findings as $finding) + if($finding->failure){ + $failed_findings++; + + $this->build->reportError( + $this->phpci, + 'web_puc', + $finding->description, + PHPCI\Model\BuildError::SEVERITY_HIGH, + $finding->location->path, + $finding->location->beginLine, + $finding->location->endLine + ); + } + + $this->phpci->logExecOutput(true); + + return $failed_findings == 0; + } +} diff --git a/composer.json b/composer.json index a9080a94..01afaa6f 100644 --- a/composer.json +++ b/composer.json @@ -52,6 +52,7 @@ "maknz/slack": "~1.7", "hipchat/hipchat-php": "~1.4", "mremi/flowdock": "~1.0" + "fulldecent/web-puc": "0.1" }, "require-dev": {