Add ability to specify sub path and override global ignore list in phpci.yml
This commit is contained in:
parent
9b4c35a11e
commit
f5c7f85bed
19
PHPCI/Plugin/PhpCodeSniffer.php
Normal file → Executable file
19
PHPCI/Plugin/PhpCodeSniffer.php
Normal file → Executable file
|
@ -47,6 +47,17 @@ class PhpCodeSniffer implements \PHPCI\Plugin
|
|||
*/
|
||||
protected $encoding;
|
||||
|
||||
/**
|
||||
* @var string, based on the assumption the root may not hold the code to be
|
||||
* tested, exteds the base path
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* @var array - paths to ignore
|
||||
*/
|
||||
protected $ignore;
|
||||
|
||||
/**
|
||||
* @param \PHPCI\Builder $phpci
|
||||
* @param array $options
|
||||
|
@ -59,6 +70,8 @@ class PhpCodeSniffer implements \PHPCI\Plugin
|
|||
$this->standard = isset($options['standard']) ? $options['standard'] : 'PSR2';
|
||||
$this->tab_width = isset($options['tab_width']) ? $options['tab_width'] : '';
|
||||
$this->encoding = isset($options['encoding']) ? $options['encoding'] : '';
|
||||
$this->path = (isset($options['path'])) ? $options['path'] : '';
|
||||
$this->ignore = (isset($options['ignore'])) ? (array)$options['ignore'] : $this->phpci->ignore;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,8 +80,8 @@ class PhpCodeSniffer implements \PHPCI\Plugin
|
|||
public function execute()
|
||||
{
|
||||
$ignore = '';
|
||||
if (count($this->phpci->ignore)) {
|
||||
$ignore = ' --ignore=' . implode(',', $this->phpci->ignore);
|
||||
if (count($this->ignore)) {
|
||||
$ignore = ' --ignore=' . implode(',', $this->ignore);
|
||||
}
|
||||
|
||||
if (strpos($this->standard, '/') !== false) {
|
||||
|
@ -93,6 +106,6 @@ class PhpCodeSniffer implements \PHPCI\Plugin
|
|||
}
|
||||
|
||||
$cmd = PHPCI_BIN_DIR . 'phpcs %s %s %s %s %s "%s"';
|
||||
return $this->phpci->executeCommand($cmd, $standard, $suffixes, $ignore, $tab_width, $encoding, $this->phpci->buildPath);
|
||||
return $this->phpci->executeCommand($cmd, $standard, $suffixes, $ignore, $tab_width, $encoding, $this->phpci->buildPath . $this->path);
|
||||
}
|
||||
}
|
||||
|
|
20
PHPCI/Plugin/PhpCpd.php
Normal file → Executable file
20
PHPCI/Plugin/PhpCpd.php
Normal file → Executable file
|
@ -21,11 +21,25 @@ class PhpCpd implements \PHPCI\Plugin
|
|||
protected $args;
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var string, based on the assumption the root may not hold the code to be
|
||||
* tested, exteds the base path
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* @var array - paths to ignore
|
||||
*/
|
||||
protected $ignore;
|
||||
|
||||
public function __construct(\PHPCI\Builder $phpci, array $options = array())
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->directory = isset($options['directory']) ? $options['directory'] : $phpci->buildPath;
|
||||
$this->standard = isset($options['standard']) ? $options['standard'] : 'PSR2';
|
||||
$this->path = (isset($options['path'])) ? $options['path'] : '';
|
||||
$this->ignore = (isset($options['ignore'])) ? (array)$options['ignore'] : $this->phpci->ignore;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,15 +48,15 @@ class PhpCpd implements \PHPCI\Plugin
|
|||
public function execute()
|
||||
{
|
||||
$ignore = '';
|
||||
if (count($this->phpci->ignore)) {
|
||||
if (count($this->ignore)) {
|
||||
$map = function ($item) {
|
||||
return ' --exclude ' . (substr($item, -1) == '/' ? substr($item, 0, -1) : $item);
|
||||
};
|
||||
$ignore = array_map($map, $this->phpci->ignore);
|
||||
$ignore = array_map($map, $this->ignore);
|
||||
|
||||
$ignore = implode('', $ignore);
|
||||
}
|
||||
|
||||
return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpcpd %s "%s"', $ignore, $this->phpci->buildPath);
|
||||
return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpcpd %s "%s"', $ignore, $this->phpci->buildPath.$this->path);
|
||||
}
|
||||
}
|
||||
|
|
21
PHPCI/Plugin/PhpMessDetector.php
Normal file → Executable file
21
PHPCI/Plugin/PhpMessDetector.php
Normal file → Executable file
|
@ -27,6 +27,17 @@ class PhpMessDetector implements \PHPCI\Plugin
|
|||
*/
|
||||
protected $suffixes;
|
||||
|
||||
/**
|
||||
* @var string, based on the assumption the root may not hold the code to be
|
||||
* tested, exteds the base path
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* @var array - paths to ignore
|
||||
*/
|
||||
protected $ignore;
|
||||
|
||||
/**
|
||||
* Array of PHPMD rules. Can be one of the builtins (codesize, unusedcode, naming, design, controversial)
|
||||
* or a filenname (detected by checking for a / in it), either absolute or relative to the project root.
|
||||
|
@ -44,6 +55,10 @@ class PhpMessDetector implements \PHPCI\Plugin
|
|||
|
||||
$this->suffixes = isset($options['suffixes']) ? (array)$options['suffixes'] : array('php');
|
||||
|
||||
$this->ignore = (isset($options['ignore'])) ? (array)$options['ignore'] : $this->phpci->ignore;
|
||||
|
||||
$this->path = (isset($options['path'])) ? $options['path'] : '';
|
||||
|
||||
$this->rules = isset($options['rules']) ? (array)$options['rules'] : array('codesize', 'unusedcode', 'naming');
|
||||
foreach ($this->rules as &$rule) {
|
||||
if ($rule[0] !== '/' && strpos($rule, '/') !== FALSE) {
|
||||
|
@ -58,8 +73,8 @@ class PhpMessDetector implements \PHPCI\Plugin
|
|||
public function execute()
|
||||
{
|
||||
$ignore = '';
|
||||
if (count($this->phpci->ignore)) {
|
||||
$ignore = ' --exclude ' . implode(',', $this->phpci->ignore);
|
||||
if (count($this->ignore)) {
|
||||
$ignore = ' --exclude ' . implode(',', $this->ignore);
|
||||
}
|
||||
|
||||
$suffixes = '';
|
||||
|
@ -68,6 +83,6 @@ class PhpMessDetector implements \PHPCI\Plugin
|
|||
}
|
||||
|
||||
$cmd = PHPCI_BIN_DIR . 'phpmd "%s" text %s %s %s';
|
||||
return $this->phpci->executeCommand($cmd, $this->phpci->buildPath, implode(',', $this->rules), $ignore, $suffixes);
|
||||
return $this->phpci->executeCommand($cmd, $this->phpci->buildPath . $this->path, implode(',', $this->rules), $ignore, $suffixes);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue