Skip to content

Commit

Permalink
reduce the function line
Browse files Browse the repository at this point in the history
  • Loading branch information
iranianpep committed Jul 18, 2017
1 parent 8c1e13e commit f464078
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/Botonomous/CommandExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Botonomous\utility\MessageUtility;
use NlpTools\Stemmers\PorterStemmer;
use NlpTools\Tokenizers\WhitespaceAndPunctuationTokenizer;
use NlpTools\Tokenizers\WhitespaceTokenizer;

/**
* Class CommandExtractor.
Expand Down Expand Up @@ -88,7 +89,7 @@ private function commandKeywordOccurrence(Command $command, $message)
/**
* @param $message
*
* @return Command|void
* @return string
*/
private function getCommandObjectByMessage($message)
{
Expand All @@ -100,24 +101,38 @@ private function getCommandObjectByMessage($message)
// check command name
if (empty($command)) {
// get the default command if no command is find in the message
$command = $this->getConfig()->get('defaultCommand');

if (empty($command)) {
$this->setError($this->getDictionary()->get('generic-messages')['noCommandMessage']);
return;
}
$command = $this->checkDefaultCommand();
}

return $this->getCommandObjectByCommand($command);
}

/**
* @return mixed|void
*/
private function checkDefaultCommand()
{
$command = $this->getConfig()->get('defaultCommand');

if (empty($command)) {
$this->setError($this->getDictionary()->get('generic-messages')['noCommandMessage']);
return;
}

return $command;
}

/**
* @param $command
*
* @return Command|void
*/
private function getCommandObjectByCommand($command)
{
if (empty($command)) {
return;
}

$commandObject = $this->getCommandContainer()->getAsObject($command);

if ($this->validateCommandObject($commandObject) !== true) {
Expand Down

0 comments on commit f464078

Please sign in to comment.