Skip to content

Commit

Permalink
enhance the code
Browse files Browse the repository at this point in the history
  • Loading branch information
iranianpep committed Dec 18, 2017
1 parent 9ce859a commit f1f3924
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ engines:
enabled: false
php:S1117:
enabled: false
php:S1448:
enabled: false
ratings:
paths:
- "src/**/*"
Expand Down
11 changes: 6 additions & 5 deletions src/Botonomous/CommandContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class CommandContainer extends AbstractCommandContainer
{
const HEALTH_CHECK_PLUGIN_DESCRIPTION = 'Use as a health check';
const PLUGIN_KEY = 'plugin';

/**
* Multiple commands can refer to the same plugin,
Expand All @@ -18,29 +19,29 @@ class CommandContainer extends AbstractCommandContainer
*/
protected static $commands = [
'ping' => [
'plugin' => 'Ping',
self::PLUGIN_KEY => 'Ping',
'description' => self::HEALTH_CHECK_PLUGIN_DESCRIPTION,
],
'pong' => [
'plugin' => 'Ping',
self::PLUGIN_KEY => 'Ping',
'action' => 'pong',
'description' => self::HEALTH_CHECK_PLUGIN_DESCRIPTION,
],
'commandWithoutFunctionForTest' => [
'plugin' => 'Ping',
self::PLUGIN_KEY => 'Ping',
'action' => 'commandWithoutFunctionForTest',
'description' => self::HEALTH_CHECK_PLUGIN_DESCRIPTION,
],
'help' => [
'plugin' => 'Help',
self::PLUGIN_KEY => 'Help',
'description' => 'List all the available commands',
'keywords' => [
'help',
'ask',
],
],
'qa' => [
'plugin' => 'QA',
self::PLUGIN_KEY => 'QA',
'description' => 'Answer questions',
],
];
Expand Down
5 changes: 4 additions & 1 deletion src/Botonomous/client/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,10 @@ public function filterArguments(string $method, array $arguments): array
$validArguments[self::OPTIONAL_ARGUMENTS_KEY] = [];
}

$extractedArguments = array_merge($validArguments[self::REQUIRED_ARGUMENTS_KEY], $validArguments[self::OPTIONAL_ARGUMENTS_KEY]);
$extractedArguments = array_merge(
$validArguments[self::REQUIRED_ARGUMENTS_KEY],
$validArguments[self::OPTIONAL_ARGUMENTS_KEY]
);

return $this->getArrayUtility()->filterArray($arguments, $extractedArguments);
}
Expand Down
15 changes: 8 additions & 7 deletions src/Botonomous/utility/LoggerUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class LoggerUtility extends AbstractUtility
const ALERT = 'alert';
const EMERGENCY = 'emergency';

const HANDLERS_KEY = 'handlers';

public static $levels = [
self::DEBUG,
self::INFO,
Expand Down Expand Up @@ -68,7 +70,7 @@ private function initLogger()

$logger = new Logger($monologConfig['channel']);

foreach (array_keys($monologConfig['handlers']) as $value) {
foreach (array_keys($monologConfig[self::HANDLERS_KEY]) as $value) {
$logger = $this->pushMonologHandler($logger, $value);
}

Expand All @@ -95,10 +97,9 @@ private function pushMonologHandler(Logger $logger, string $handlerKey): Logger
{
$activeHandlers = [];

switch ($handlerKey) {
case 'file':
$activeHandlers[] = new StreamHandler($this->getLogFilePath());
break;
// if there are more $handlerKey, use switch
if ($handlerKey === 'file') {
$activeHandlers[] = new StreamHandler($this->getLogFilePath());
}

if (!empty($activeHandlers)) {
Expand Down Expand Up @@ -130,8 +131,8 @@ private function getMonologConfigFileName()
{
$monologConfig = $this->getMonologConfig();

if (isset($monologConfig['handlers']['file']['fileName'])) {
return $monologConfig['handlers']['file']['fileName'];
if (isset($monologConfig[self::HANDLERS_KEY]['file']['fileName'])) {
return $monologConfig[self::HANDLERS_KEY]['file']['fileName'];
}
}

Expand Down

0 comments on commit f1f3924

Please sign in to comment.