ExpressionBot::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Crummy\Phlack\Bot;
4
5
use Crummy\Phlack\Common\Matcher\CommandMatcher;
6
use Crummy\Phlack\WebHook\CommandInterface;
7
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
8
use Symfony\Component\ExpressionLanguage\SyntaxError;
9
10
class ExpressionBot extends AbstractBot
11
{
12
    /** @var \Symfony\Component\ExpressionLanguage\ExpressionLanguage */
13
    protected $language;
14
15
    /**
16
     * @param string             $commandName
17
     * @param ExpressionLanguage $language
18
     */
19 3
    public function __construct($commandName = '/expr', ExpressionLanguage $language = null)
20
    {
21 3
        $this->language = $language ?: new ExpressionLanguage();
22
23 3
        parent::__construct(new CommandMatcher($commandName));
24 3
    }
25
26
    /**
27
     * @param CommandInterface $command
28
     *
29
     * @return \Crummy\Phlack\WebHook\Reply\Reply
30
     */
31 2
    public function execute(CommandInterface $command)
32
    {
33
        try {
34 2
            $response = (string) $this->evaluate($command, $this->getValues($command));
35 2
        } catch (SyntaxError $badSyntax) {
36 1
            $response = $badSyntax->getMessage();
37
        }
38
39 2
        return $this->say($response);
40
    }
41
42
    /**
43
     * @param CommandInterface $command
44
     * @param array            $values
45
     *
46
     * @return string
47
     */
48 2
    protected function evaluate(CommandInterface $command, $values = [])
49
    {
50 2
        return $this->language->evaluate($command['text'], $values);
51
    }
52
53
    /**
54
     * @param CommandInterface $command
55
     *
56
     * @return array
57
     */
58 2
    protected function getValues(CommandInterface $command)
0 ignored issues
show
Unused Code introduced by
The parameter $command is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
    {
60 2
        return [];
61
    }
62
}
63