* @package PHPCI * @subpackage Plugins */ class PhpParallelLint extends Plugin { /** * @var string */ protected $directory; /** * @var array - paths to ignore */ protected $ignore; /** * {@inheritdoc} */ public function __construct(Builder $phpci, Build $build, array $options = []) { parent::__construct($phpci, $build, $options); $this->directory = $this->phpci->buildPath; $this->ignore = $this->phpci->ignore; if (isset($options['directory'])) { $this->directory = $this->phpci->buildPath.$options['directory']; } if (isset($options['ignore'])) { $this->ignore = $options['ignore']; } } /** * Executes parallel lint */ public function execute() { list($ignore) = $this->getFlags(); $phplint = $this->phpci->findBinary('parallel-lint'); $cmd = $phplint . ' %s "%s"'; $success = $this->phpci->executeCommand( $cmd, $ignore, $this->directory ); $output = $this->phpci->getLastOutput(); $matches = []; if (preg_match_all('/Parse error\:/', $output, $matches)) { $this->build->storeMeta('phplint-errors', count($matches[0])); } return $success; } /** * Produce an argument string for PHP Parallel Lint. * @return array */ protected function getFlags() { $ignoreFlags = []; foreach ($this->ignore as $ignoreDir) { $ignoreFlags[] = '--exclude "' . $this->phpci->buildPath . $ignoreDir . '"'; } $ignore = implode(' ', $ignoreFlags); return [$ignore]; } }