CommandPool::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: chrl
5
 * Date: 27/10/16
6
 * Time: 10:53
7
 */
8
9
namespace Chrl\AppBundle\GameAction;
10
11
use Chrl\AppBundle\BuktopuhaBotApi;
12
use Chrl\AppBundle\Service\GameService;
13
14
class CommandPool
15
{
16
17
    public $gameService;
18
    public $botApi;
19
20
    public function __construct(BuktopuhaBotApi $botApi)
21
    {
22
        $this->botApi = $botApi;
23
    }
24
25
    public function setGameService(GameService $gameService)
26
    {
27
        $this->gameService = $gameService;
28
        return $this;
29
    }
30
31
    public function findAction($message)
32
    {
33
        $text = trim($message['text']);
34
35
        if (false !== strpos($text, ' ')) {
36
            return false;
37
        }
38
39
        $text = str_replace('/', '', $text);
40
        $text = str_replace('@'.$this->botApi->getBotName(), '', $text);
41
        $text = 'Chrl\AppBundle\GameAction\\'.ucfirst(strtolower($text)).'Action';
42
43
        if (class_exists($text, true)) {
44
45
            /** @var BaseGameAction $gameAction */
46
47
            $gameAction = new $text($this->gameService, $this->botApi);
48
49
            if ($gameAction instanceof GameActionInterface) {
50
                return $gameAction;
51
            }
52
        }
53
        return $text;
54
    }
55
}
56