PHPCI/Plugin PSR2 compliance. Issue #18

This commit is contained in:
Dan Cryer 2013-05-16 15:50:19 +01:00
parent 11a3e3403f
commit 83dcb2ba0c
8 changed files with 247 additions and 242 deletions

View file

@ -23,13 +23,15 @@ class Composer implements \PHPCI\Plugin
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$path = $phpci->buildPath;
$this->phpci = $phpci;
$this->directory = isset($options['directory']) ? $phpci->buildPath . '/' . $options['directory'] : $phpci->buildPath;
$this->directory = isset($options['directory']) ? $path . '/' . $options['directory'] : $path;
$this->action = isset($options['action']) ? $options['action'] : 'update';
}
public function execute()
{
return $this->phpci->executeCommand(PHPCI_DIR . 'composer.phar --prefer-dist --working-dir="%s" %s', $this->directory, $this->action);
$cmd = PHPCI_DIR . 'composer.phar --prefer-dist --working-dir="%s" %s';
return $this->phpci->executeCommand($cmd, $this->directory, $this->action);
}
}

View file

@ -8,6 +8,7 @@
*/
namespace PHPCI\Plugin;
use PDO;
/**
@ -48,13 +49,13 @@ class Mysql implements \PHPCI\Plugin
public function execute()
{
try {
$pdo = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$opts = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$pdo = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, $opts);
foreach ($this->queries as $query) {
$pdo->query($query);
}
}
catch(\Exception $ex) {
} catch (\Exception $ex) {
$this->phpci->logFailure($ex->getMessage());
return false;
}

View file

@ -8,6 +8,7 @@
*/
namespace PHPCI\Plugin;
use PDO;
/**
@ -43,13 +44,13 @@ class Pgsql implements \PHPCI\Plugin
public function execute()
{
try {
$pdo = new PDO('pgsql:host=' . $this->host, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$opts = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$pdo = new PDO('pgsql:host=' . $this->host, $this->user, $this->pass, $opts);
foreach ($this->queries as $query) {
$pdo->query($query);
}
}
catch(\Exception $ex) {
} catch (\Exception $ex) {
$this->phpci->logFailure($ex->getMessage());
return false;
}

View file

@ -33,14 +33,16 @@ class PhpCodeSniffer implements \PHPCI\Plugin
$ignore = '';
if (count($this->phpci->ignore)) {
$ignore = array_map(function($item)
{
$map = function ($item) {
return substr($item, -1) == '/' ? $item . '*' : $item . '/*';
}, $this->phpci->ignore);
};
$ignore = array_map($map, $this->phpci->ignore);
$ignore = ' --ignore=' . implode(',', $ignore);
}
return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpcs --standard=%s %s "%s"', $this->standard, $ignore, $this->phpci->buildPath);
$cmd = PHPCI_BIN_DIR . 'phpcs --standard=%s %s "%s"';
return $this->phpci->executeCommand($cmd, $this->standard, $ignore, $this->phpci->buildPath);
}
}

View file

@ -31,12 +31,11 @@ class PhpCpd implements \PHPCI\Plugin
public function execute()
{
$ignore = '';
if(count($this->phpci->ignore))
{
$ignore = array_map(function($item)
{
if (count($this->phpci->ignore)) {
$map = function ($item) {
return ' --exclude ' . (substr($item, -1) == '/' ? substr($item, 0, -1) : $item);
}, $this->phpci->ignore);
};
$ignore = array_map($map, $this->phpci->ignore);
$ignore = implode('', $ignore);
}

View file

@ -28,16 +28,16 @@ class PhpMessDetector implements \PHPCI\Plugin
{
$ignore = '';
if(count($this->phpci->ignore))
{
$ignore = array_map(function($item)
{
if (count($this->phpci->ignore)) {
$map = function ($item) {
return substr($item, -1) == '/' ? $item . '*' : $item . '/*';
}, $this->phpci->ignore);
};
$ignore = array_map($map, $this->phpci->ignore);
$ignore = ' --exclude ' . implode(',', $ignore);
}
return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpmd "%s" text codesize,unusedcode,naming %s', $this->phpci->buildPath, $ignore);
$cmd = PHPCI_BIN_DIR . 'phpmd "%s" text codesize,unusedcode,naming %s';
return $this->phpci->executeCommand($cmd, $this->phpci->buildPath, $ignore);
}
}

View file

@ -49,14 +49,12 @@ class PhpUnit implements \PHPCI\Plugin
$success = true;
// Run any config files first. This can be either a single value or an array.
if ($this->xmlConfigFile !== null)
{
if ($this->xmlConfigFile !== null) {
$success &= $this->runConfigFile($this->xmlConfigFile);
}
// Run any dirs next. Again this can be either a single value or an array.
if ($this->directory !== null)
{
if ($this->directory !== null) {
$success &= $this->runDir($this->directory);
}
@ -65,20 +63,21 @@ class PhpUnit implements \PHPCI\Plugin
protected function runConfigFile($configPath)
{
if (is_array($configPath))
{
if (is_array($configPath)) {
return $this->recurseArg($configPath, array($this, "runConfigFile"));
}
else
{
} else {
if ($this->runFrom) {
$curdir = getcwd();
chdir($this->phpci->buildPath.'/'.$this->runFrom);
}
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit %s -c "%s"', $this->args, $this->phpci->buildPath . $configPath);
$cmd = PHPCI_BIN_DIR . 'phpunit %s -c "%s"';
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $configPath);
if ($this->runFrom) {
chdir($curdir);
}
return $success;
}
}
@ -87,17 +86,18 @@ class PhpUnit implements \PHPCI\Plugin
{
if (is_array($dirPath)) {
return $this->recurseArg($dirPath, array($this, "runConfigFile"));
}
else {
} else {
$curdir = getcwd();
chdir($this->phpci->buildPath);
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit %s "%s"', $this->args, $this->phpci->buildPath . $dirPath);
$cmd = PHPCI_BIN_DIR . 'phpunit %s "%s"';
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $dirPath);
chdir($curdir);
return $success;
}
}
protected function recurseArg($array, $callable) {
protected function recurseArg($array, $callable)
{
$success = true;
foreach ($array as $subItem) {
$success &= call_user_func($callable, $subItem);