From e59e4a397fa54c47c1735f3fbb94cc19ec80768e Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Tue, 5 Dec 2017 20:57:53 +0700 Subject: [PATCH] Code style fixes. --- src/B8Framework/Config.php | 1 - src/B8Framework/Http/Router.php | 3 +- src/B8Framework/View/Template.php | 29 ++++++++++++------- src/PHPCensor/Command/CreateAdminCommand.php | 6 ++-- src/PHPCensor/Command/CreateBuildCommand.php | 6 ++-- src/PHPCensor/Command/InstallCommand.php | 27 +++++++++-------- src/PHPCensor/Command/RunCommand.php | 10 ++++--- .../Command/ScheduleBuildCommand.php | 6 ++-- src/PHPCensor/Command/WorkerCommand.php | 6 ++-- src/PHPCensor/Store/BuildStore.php | 8 +++-- 10 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/B8Framework/Config.php b/src/B8Framework/Config.php index 977abb0a..60ec8225 100644 --- a/src/B8Framework/Config.php +++ b/src/B8Framework/Config.php @@ -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; diff --git a/src/B8Framework/Http/Router.php b/src/B8Framework/Http/Router.php index aa651c55..d0653241 100644 --- a/src/B8Framework/Http/Router.php +++ b/src/B8Framework/Http/Router.php @@ -2,7 +2,8 @@ namespace b8\Http; -use b8\Application, b8\Config; +use b8\Application; +use b8\Config; class Router { diff --git a/src/B8Framework/View/Template.php b/src/B8Framework/View/Template.php index d58957cc..9735b928 100644 --- a/src/B8Framework/View/Template.php +++ b/src/B8Framework/View/Template.php @@ -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}(); diff --git a/src/PHPCensor/Command/CreateAdminCommand.php b/src/PHPCensor/Command/CreateAdminCommand.php index c723459f..113974bf 100644 --- a/src/PHPCensor/Command/CreateAdminCommand.php +++ b/src/PHPCensor/Command/CreateAdminCommand.php @@ -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'); } diff --git a/src/PHPCensor/Command/CreateBuildCommand.php b/src/PHPCensor/Command/CreateBuildCommand.php index 28b97592..237d85b3 100644 --- a/src/PHPCensor/Command/CreateBuildCommand.php +++ b/src/PHPCensor/Command/CreateBuildCommand.php @@ -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'); } /** diff --git a/src/PHPCensor/Command/InstallCommand.php b/src/PHPCensor/Command/InstallCommand.php index 10e30307..1f3b86e5 100644 --- a/src/PHPCensor/Command/InstallCommand.php +++ b/src/PHPCensor/Command/InstallCommand.php @@ -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('PHP Censor could not connect to database with the details provided. Please try again.'); $output->writeln('' . $ex->getMessage() . ''); diff --git a/src/PHPCensor/Command/RunCommand.php b/src/PHPCensor/Command/RunCommand.php index 2ff7f563..71b32e2d 100644 --- a/src/PHPCensor/Command/RunCommand.php +++ b/src/PHPCensor/Command/RunCommand.php @@ -18,7 +18,7 @@ use PHPCensor\Model\Build; /** * Run console command - Runs any pending builds. - * + * * @author Dan Cryer */ 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); diff --git a/src/PHPCensor/Command/ScheduleBuildCommand.php b/src/PHPCensor/Command/ScheduleBuildCommand.php index 57c02f9f..1c8b574a 100644 --- a/src/PHPCensor/Command/ScheduleBuildCommand.php +++ b/src/PHPCensor/Command/ScheduleBuildCommand.php @@ -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'); } /** diff --git a/src/PHPCensor/Command/WorkerCommand.php b/src/PHPCensor/Command/WorkerCommand.php index 3004c51b..644e9394 100644 --- a/src/PHPCensor/Command/WorkerCommand.php +++ b/src/PHPCensor/Command/WorkerCommand.php @@ -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) diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index 868249e6..be3ad4e8 100644 --- a/src/PHPCensor/Store/BuildStore.php +++ b/src/PHPCensor/Store/BuildStore.php @@ -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];