Code style fixes.

This commit is contained in:
Dmitry Khomutov 2017-12-05 20:57:53 +07:00
parent ffb8ef334c
commit e59e4a397f
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
10 changed files with 59 additions and 43 deletions

View file

@ -188,7 +188,6 @@ class Config
} elseif (is_array($source[$target_key]) && is_array($target_value)) {
// Both are arrays, deep merge them
self::deepMerge($source[$target_key], $target_value);
} elseif (is_array($source[$target_key])) {
// Source is the array, push target value
$source[$target_key][] = $target_value;

View file

@ -2,7 +2,8 @@
namespace b8\Http;
use b8\Application, b8\Config;
use b8\Application;
use b8\Config;
class Router
{

View file

@ -7,6 +7,7 @@ use b8\View;
class Template extends View
{
public static $templateFunctions = [];
protected static $extension = 'html';
public function __construct($viewCode)
@ -222,10 +223,19 @@ class Template extends View
{
$matches = [];
if (preg_match('/([a-zA-Z0-9_\-\(\):\s.\"]+)\s+?([\!\=\<\>]+)?\s+?([a-zA-Z0-9\(\)_\-:\s.\"]+)?/', $condition,
$matches)) {
$left = is_numeric($matches[1]) ? intval($matches[1]) : $this->processVariableName($matches[1]);
$right = is_numeric($matches[3]) ? intval($matches[3]) : $this->processVariableName($matches[3]);
if (preg_match(
'/([a-zA-Z0-9_\-\(\):\s.\"]+)\s+?([\!\=\<\>]+)?\s+?([a-zA-Z0-9\(\)_\-:\s.\"]+)?/',
$condition,
$matches
)) {
$left = is_numeric($matches[1])
? intval($matches[1])
: $this->processVariableName($matches[1]);
$right = is_numeric($matches[3])
? intval($matches[3])
: $this->processVariableName($matches[3]);
$operator = $matches[2];
switch ($operator) {
@ -374,7 +384,6 @@ class Template extends View
{
// Case one - Test for function calls:
if (substr($varName, 0, 1) == '(' && substr($varName, -1) == ')') {
$functionCall = substr($varName, 1, -1);
$parts = explode(' ', $functionCall, 2);
$functionName = $parts[0];
@ -469,7 +478,8 @@ class Template extends View
{
if (array_key_exists($function, self::$templateFunctions)) {
$handler = self::$templateFunctions[$function];
$args = $this->processFunctionArguments($args);
$args = $this->processFunctionArguments($args);
return $handler($args, $this);
}
@ -478,15 +488,13 @@ class Template extends View
protected function processFunctionArguments($args)
{
$rtn = [];
$rtn = [];
$args = explode(';', $args);
foreach ($args as $arg) {
$arg = explode(':', $arg);
if (count($arg) == 2) {
$key = trim($arg[0]);
$val = trim($arg[1]);
@ -516,7 +524,6 @@ class Template extends View
}
foreach ($args['variables'] as $variable) {
$variable = explode('=>', $variable);
$variable = array_map('trim', $variable);
@ -533,7 +540,7 @@ class Template extends View
protected function callHelperFunction($args)
{
$helper = $args['helper'];
$helper = $args['helper'];
$function = $args['method'];
return $this->{$helper}()->{$function}();

View file

@ -13,7 +13,7 @@ use Symfony\Component\Console\Question\Question;
/**
* Create admin command - creates an admin user
*
*
* @author Wogan May (@woganmay)
*/
class CreateAdminCommand extends Command
@ -38,9 +38,9 @@ class CreateAdminCommand extends Command
$this
->setName('php-censor:create-admin')
->addOption('admin-name', null, InputOption::VALUE_OPTIONAL, 'Admin name')
->addOption('admin-name', null, InputOption::VALUE_OPTIONAL, 'Admin name')
->addOption('admin-password', null, InputOption::VALUE_OPTIONAL, 'Admin password')
->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'Admin email')
->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'Admin email')
->setDescription('Create an admin user');
}

View file

@ -47,12 +47,14 @@ class CreateBuildCommand extends Command
{
$this
->setName('php-censor:create-build')
->setDescription('Create a build for a project')
->addArgument('projectId', InputArgument::REQUIRED, 'A project ID')
->addOption('commit', null, InputOption::VALUE_OPTIONAL, 'Commit ID to build')
->addOption('branch', null, InputOption::VALUE_OPTIONAL, 'Branch to build')
->addOption('email', null, InputOption::VALUE_OPTIONAL, 'Committer email')
->addOption('message', null, InputOption::VALUE_OPTIONAL, 'Commit message');
->addOption('message', null, InputOption::VALUE_OPTIONAL, 'Commit message')
->setDescription('Create a build for a project');
}
/**

View file

@ -37,19 +37,19 @@ class InstallCommand extends Command
$this
->setName('php-censor:install')
->addOption('url', null, InputOption::VALUE_OPTIONAL, 'PHP Censor installation URL')
->addOption('db-type', null, InputOption::VALUE_OPTIONAL, 'Database type')
->addOption('db-host', null, InputOption::VALUE_OPTIONAL, 'Database host')
->addOption('db-port', null, InputOption::VALUE_OPTIONAL, 'Database port')
->addOption('db-name', null, InputOption::VALUE_OPTIONAL, 'Database name')
->addOption('db-user', null, InputOption::VALUE_OPTIONAL, 'Database user')
->addOption('db-password', null, InputOption::VALUE_OPTIONAL, 'Database password')
->addOption('admin-name', null, InputOption::VALUE_OPTIONAL, 'Admin name')
->addOption('admin-password', null, InputOption::VALUE_OPTIONAL, 'Admin password')
->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'Admin email')
->addOption('queue-use', null, InputOption::VALUE_OPTIONAL, 'Don\'t ask for queue details', true)
->addOption('queue-host', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue server hostname')
->addOption('queue-name', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue name')
->addOption('url', null, InputOption::VALUE_OPTIONAL, 'PHP Censor installation URL')
->addOption('db-type', null, InputOption::VALUE_OPTIONAL, 'Database type')
->addOption('db-host', null, InputOption::VALUE_OPTIONAL, 'Database host')
->addOption('db-port', null, InputOption::VALUE_OPTIONAL, 'Database port')
->addOption('db-name', null, InputOption::VALUE_OPTIONAL, 'Database name')
->addOption('db-user', null, InputOption::VALUE_OPTIONAL, 'Database user')
->addOption('db-password', null, InputOption::VALUE_OPTIONAL, 'Database password')
->addOption('admin-name', null, InputOption::VALUE_OPTIONAL, 'Admin name')
->addOption('admin-password', null, InputOption::VALUE_OPTIONAL, 'Admin password')
->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'Admin email')
->addOption('queue-use', null, InputOption::VALUE_OPTIONAL, 'Don\'t ask for queue details', true)
->addOption('queue-host', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue server hostname')
->addOption('queue-name', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue name')
->addOption('config-from-file', null, InputOption::VALUE_OPTIONAL, 'Take config from file and ignore options', false)
->setDescription('Install PHP Censor');
@ -467,7 +467,6 @@ class InstallCommand extends Command
unset($pdo);
return true;
} catch (Exception $ex) {
$output->writeln('<error>PHP Censor could not connect to database with the details provided. Please try again.</error>');
$output->writeln('<error>' . $ex->getMessage() . '</error>');

View file

@ -18,7 +18,7 @@ use PHPCensor\Model\Build;
/**
* Run console command - Runs any pending builds.
*
*
* @author Dan Cryer <dan@block8.co.uk>
*/
class RunCommand extends Command
@ -52,8 +52,10 @@ class RunCommand extends Command
{
$this
->setName('php-censor:run-builds')
->setDescription('Run all pending PHP Censor builds')
->addOption('debug', null, null, 'Run PHP Censor in debug mode');
->addOption('debug', null, null, 'Run PHP Censor in debug mode')
->setDescription('Run all pending PHP Censor builds');
}
/**
@ -81,7 +83,7 @@ class RunCommand extends Command
$this->logger->pushProcessor(new LoggedBuildContextTidier());
$this->logger->addInfo('Finding builds to process');
/** @var BuildStore $buildStore */
$buildStore = Factory::getStore('Build');
$result = $buildStore->getByStatus(Build::STATUS_PENDING, $this->maxBuilds);

View file

@ -55,8 +55,10 @@ class ScheduleBuildCommand extends Command
{
$this
->setName('php-censor:schedule-build')
->setDescription('Schedules a build for active projects which have not been ran by X days')
->addArgument('days', InputArgument::REQUIRED, 'Since specified days');
->addArgument('days', InputArgument::REQUIRED, 'Since specified days')
->setDescription('Schedules a build for active projects which have not been ran by X days');
}
/**

View file

@ -41,8 +41,10 @@ class WorkerCommand extends Command
{
$this
->setName('php-censor:worker')
->setDescription('Runs the PHP Censor build worker.')
->addOption('debug', null, null, 'Run PHP Censor in Debug Mode');
->addOption('debug', null, null, 'Run PHP Censor in Debug Mode')
->setDescription('Runs the PHP Censor build worker.');
}
protected function execute(InputInterface $input, OutputInterface $output)

View file

@ -274,8 +274,8 @@ class BuildStore extends Store
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$projects = [];
$latest = [];
foreach($res as $item) {
$latest = [];
foreach ($res as $item) {
$project_id = $item['project_id'];
$environment = $item['environment'];
if (empty($projects[$project_id])) {
@ -312,11 +312,13 @@ class BuildStore extends Store
$projects[$project_id][$environment]['failed'] = $build;
}
}
foreach($projects as $idx => $project) {
foreach ($projects as $idx => $project) {
$projects[$idx] = array_filter($project, function($val) {
return ($val['latest'][0]->getStatus() != Build::STATUS_SUCCESS);
});
}
$projects = array_filter($projects);
return ['projects' => $projects, 'latest' => $latest];