Ai::getChannel()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
namespace Interfaces\Gitter;
3
4
use Domains\User;
5
use Domains\Message;
6
use Interfaces\Gitter\Ai\UserChannel;
7
8
/**
9
 * Class Ai
10
 */
11
class Ai
12
{
13
    /**
14
     * @var array|UserChannel[]
15
     */
16
    protected $channels = [];
17
18
    /**
19
     * @param Message $message
20
     */
21
    public function handle(Message $message)
22
    {
23
        $this
24
            ->getChannel($message->user)
25
            ->handle($message);
26
    }
27
28
    /**
29
     * @param User $user
30
     * @return UserChannel
31
     */
32
    protected function getChannel(User $user)
33
    {
34
        $key = $user->gitter_id;
35
        if (!array_key_exists($key, $this->channels)) {
36
            $this->channels[$key] = new UserChannel($user);
37
        }
38
        return $this->channels[$key];
39
    }
40
}