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

@ -17,19 +17,21 @@ namespace PHPCI\Plugin;
*/
class Composer implements \PHPCI\Plugin
{
protected $directory;
protected $action;
protected $phpci;
protected $directory;
protected $action;
protected $phpci;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
$this->directory = isset($options['directory']) ? $phpci->buildPath . '/' . $options['directory'] : $phpci->buildPath;
$this->action = isset($options['action']) ? $options['action'] : 'update';
}
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$path = $phpci->buildPath;
$this->phpci = $phpci;
$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);
}
}
public function execute()
{
$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;
/**
@ -18,47 +19,47 @@ use PDO;
*/
class Mysql implements \PHPCI\Plugin
{
protected $phpci;
protected $queries = array();
protected $phpci;
protected $queries = array();
protected $host;
protected $user;
protected $pass;
protected $host;
protected $user;
protected $pass;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
$this->queries = $options;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
$this->queries = $options;
$db = \b8\Database::getConnection('write')->getDetails();
$this->host = PHPCI_DB_HOST;
$this->user = $db['user'];
$this->pass = $db['pass'];
$db = \b8\Database::getConnection('write')->getDetails();
$this->host = PHPCI_DB_HOST;
$this->user = $db['user'];
$this->pass = $db['pass'];
$buildSettings = $phpci->getConfig('build_settings');
if(isset($buildSettings['mysql'])) {
$sql = $buildSettings['mysql'];
$buildSettings = $phpci->getConfig('build_settings');
if (isset($buildSettings['mysql'])) {
$sql = $buildSettings['mysql'];
$this->host = !empty($sql['host']) ? $sql['host'] : $this->host;
$this->user = !empty($sql['user']) ? $sql['user'] : $this->user;
$this->pass = array_key_exists('pass', $sql) ? $sql['pass'] : $this->pass;
}
}
$this->host = !empty($sql['host']) ? $sql['host'] : $this->host;
$this->user = !empty($sql['user']) ? $sql['user'] : $this->user;
$this->pass = array_key_exists('pass', $sql) ? $sql['pass'] : $this->pass;
}
}
public function execute()
{
try {
$pdo = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
public function execute()
{
try {
$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) {
$this->phpci->logFailure($ex->getMessage());
return false;
}
foreach ($this->queries as $query) {
$pdo->query($query);
}
} catch (\Exception $ex) {
$this->phpci->logFailure($ex->getMessage());
return false;
}
return true;
}
}
return true;
}
}

View file

@ -8,6 +8,7 @@
*/
namespace PHPCI\Plugin;
use PDO;
/**
@ -18,42 +19,42 @@ use PDO;
*/
class Pgsql implements \PHPCI\Plugin
{
protected $phpci;
protected $queries = array();
protected $phpci;
protected $queries = array();
protected $host;
protected $user;
protected $pass;
protected $host;
protected $user;
protected $pass;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
$this->queries = $options;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
$this->queries = $options;
$buildSettings = $phpci->getConfig('build_settings');
$buildSettings = $phpci->getConfig('build_settings');
if(isset($buildSettings['pgsql'])) {
$sql = $buildSettings['pgsql'];
$this->host = $sql['host'];
$this->user = $sql['user'];
$this->pass = $sql['pass'];
}
}
if (isset($buildSettings['pgsql'])) {
$sql = $buildSettings['pgsql'];
$this->host = $sql['host'];
$this->user = $sql['user'];
$this->pass = $sql['pass'];
}
}
public function execute()
{
try {
$pdo = new PDO('pgsql:host=' . $this->host, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
public function execute()
{
try {
$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) {
$this->phpci->logFailure($ex->getMessage());
return false;
}
foreach ($this->queries as $query) {
$pdo->query($query);
}
} catch (\Exception $ex) {
$this->phpci->logFailure($ex->getMessage());
return false;
}
return true;
}
}
return true;
}
}

View file

@ -17,30 +17,32 @@ namespace PHPCI\Plugin;
*/
class PhpCodeSniffer implements \PHPCI\Plugin
{
protected $directory;
protected $args;
protected $phpci;
protected $directory;
protected $args;
protected $phpci;
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';
}
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';
}
public function execute()
{
$ignore = '';
if(count($this->phpci->ignore)) {
$ignore = array_map(function($item)
{
return substr($item, -1) == '/' ? $item . '*' : $item . '/*';
}, $this->phpci->ignore);
public function execute()
{
$ignore = '';
if (count($this->phpci->ignore)) {
$map = function ($item) {
return substr($item, -1) == '/' ? $item . '*' : $item . '/*';
};
$ignore = ' --ignore=' . implode(',', $ignore);
}
$ignore = array_map($map, $this->phpci->ignore);
return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpcs --standard=%s %s "%s"', $this->standard, $ignore, $this->phpci->buildPath);
}
}
$ignore = ' --ignore=' . implode(',', $ignore);
}
$cmd = PHPCI_BIN_DIR . 'phpcs --standard=%s %s "%s"';
return $this->phpci->executeCommand($cmd, $this->standard, $ignore, $this->phpci->buildPath);
}
}

View file

@ -17,30 +17,29 @@ namespace PHPCI\Plugin;
*/
class PhpCpd implements \PHPCI\Plugin
{
protected $directory;
protected $args;
protected $phpci;
protected $directory;
protected $args;
protected $phpci;
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';
}
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';
}
public function execute()
{
$ignore = '';
if(count($this->phpci->ignore))
{
$ignore = array_map(function($item)
{
return ' --exclude ' . (substr($item, -1) == '/' ? substr($item, 0, -1) : $item);
}, $this->phpci->ignore);
public function execute()
{
$ignore = '';
if (count($this->phpci->ignore)) {
$map = function ($item) {
return ' --exclude ' . (substr($item, -1) == '/' ? substr($item, 0, -1) : $item);
};
$ignore = array_map($map, $this->phpci->ignore);
$ignore = implode('', $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);
}
}

View file

@ -17,27 +17,27 @@ namespace PHPCI\Plugin;
*/
class PhpMessDetector implements \PHPCI\Plugin
{
protected $directory;
protected $directory;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
}
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
}
public function execute()
{
$ignore = '';
if(count($this->phpci->ignore))
{
$ignore = array_map(function($item)
{
return substr($item, -1) == '/' ? $item . '*' : $item . '/*';
}, $this->phpci->ignore);
public function execute()
{
$ignore = '';
if (count($this->phpci->ignore)) {
$map = function ($item) {
return substr($item, -1) == '/' ? $item . '*' : $item . '/*';
};
$ignore = array_map($map, $this->phpci->ignore);
$ignore = ' --exclude ' . implode(',', $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

@ -17,20 +17,20 @@ namespace PHPCI\Plugin;
*/
class PhpSpec implements \PHPCI\Plugin
{
protected $phpci;
protected $phpci;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
}
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
}
public function execute()
{
$curdir = getcwd();
chdir($this->phpci->buildPath);
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpspec');
chdir($curdir);
return $success;
}
}
public function execute()
{
$curdir = getcwd();
chdir($this->phpci->buildPath);
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpspec');
chdir($curdir);
return $success;
}
}

View file

@ -17,91 +17,91 @@ namespace PHPCI\Plugin;
*/
class PhpUnit implements \PHPCI\Plugin
{
protected $args;
protected $phpci;
protected $args;
protected $phpci;
/**
* @var string|string[] $directory The directory (or array of dirs) to run PHPUnit on
*/
protected $directory;
/**
* @var string $runFrom When running PHPUnit with an XML config, the command is run from this directory
*/
protected $runFrom;
/**
* @var string|string[] $directory The directory (or array of dirs) to run PHPUnit on
*/
protected $directory;
/**
* @var string $runFrom When running PHPUnit with an XML config, the command is run from this directory
*/
protected $runFrom;
/**
* @var string|string[] $xmlConfigFile The path (or array of paths) of an xml config for PHPUnit
*/
protected $xmlConfigFile;
/**
* @var string|string[] $xmlConfigFile The path (or array of paths) of an xml config for PHPUnit
*/
protected $xmlConfigFile;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
$this->directory = isset($options['directory']) ? $options['directory'] : null;
$this->xmlConfigFile = isset($options['config']) ? $options['config'] : null;
$this->runFrom = isset($options['run_from']) ? $options['run_from'] : null;
$this->args = isset($options['args']) ? $options['args'] : '';
}
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
$this->directory = isset($options['directory']) ? $options['directory'] : null;
$this->xmlConfigFile = isset($options['config']) ? $options['config'] : null;
$this->runFrom = isset($options['run_from']) ? $options['run_from'] : null;
$this->args = isset($options['args']) ? $options['args'] : '';
}
public function execute()
{
$success = true;
public function execute()
{
$success = true;
// Run any config files first. This can be either a single value or an array.
if ($this->xmlConfigFile !== null)
{
$success &= $this->runConfigFile($this->xmlConfigFile);
}
// Run any config files first. This can be either a single value or an array.
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)
{
$success &= $this->runDir($this->directory);
}
return $success;
}
// Run any dirs next. Again this can be either a single value or an array.
if ($this->directory !== null) {
$success &= $this->runDir($this->directory);
}
return $success;
}
protected function runConfigFile($configPath)
{
if (is_array($configPath))
{
return $this->recurseArg($configPath, array($this, "runConfigFile"));
}
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);
if ($this->runFrom) {
chdir($curdir);
}
return $success;
}
}
protected function runConfigFile($configPath)
{
if (is_array($configPath)) {
return $this->recurseArg($configPath, array($this, "runConfigFile"));
} else {
if ($this->runFrom) {
$curdir = getcwd();
chdir($this->phpci->buildPath.'/'.$this->runFrom);
}
protected function runDir($dirPath)
{
if (is_array($dirPath)) {
return $this->recurseArg($dirPath, array($this, "runConfigFile"));
}
else {
$curdir = getcwd();
chdir($this->phpci->buildPath);
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit %s "%s"', $this->args, $this->phpci->buildPath . $dirPath);
chdir($curdir);
return $success;
}
}
$cmd = PHPCI_BIN_DIR . 'phpunit %s -c "%s"';
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $configPath);
if ($this->runFrom) {
chdir($curdir);
}
protected function recurseArg($array, $callable) {
$success = true;
foreach($array as $subItem) {
$success &= call_user_func($callable, $subItem);
}
return $success;
}
}
return $success;
}
}
protected function runDir($dirPath)
{
if (is_array($dirPath)) {
return $this->recurseArg($dirPath, array($this, "runConfigFile"));
} else {
$curdir = getcwd();
chdir($this->phpci->buildPath);
$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)
{
$success = true;
foreach ($array as $subItem) {
$success &= call_user_func($callable, $subItem);
}
return $success;
}
}