CommandPool   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setGameService() 0 5 1
B findAction() 0 24 4
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