| 1 | <?php |
||
| 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 = []) |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @param CommandInterface $command |
||
| 55 | * |
||
| 56 | * @return array |
||
| 57 | */ |
||
| 58 | 2 | protected function getValues(CommandInterface $command) |
|
| 62 | } |
||
| 63 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.