Passed
Push — master ( 64171d...4510f4 )
by Vladimir
10:35
created

Context   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 77
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 1

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getChannel() 0 4 1
A getChat() 0 4 1
A getUser() 0 4 1
A getIntent() 0 4 1
A setIntent() 0 6 1
A getInteraction() 0 4 1
A setInteraction() 0 6 1
A get() 0 4 1
A set() 0 6 1
A toArray() 0 8 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation;
6
7
use FondBot\Channels\Chat;
8
use FondBot\Channels\User;
9
use FondBot\Channels\Channel;
10
use Illuminate\Contracts\Support\Arrayable;
11
12
class Context implements Arrayable
13
{
14
    private $channel;
15
    private $chat;
16
    private $user;
17
    private $intent;
18
    private $interaction;
19
    private $items;
20
21 8
    public function __construct(Channel $channel, Chat $chat, User $user, array $items = [])
22
    {
23 8
        $this->channel = $channel;
24 8
        $this->chat = $chat;
25 8
        $this->user = $user;
26 8
        $this->items = collect($items);
27 8
    }
28
29 4
    public function getChannel(): Channel
30
    {
31 4
        return $this->channel;
32
    }
33
34 4
    public function getChat(): Chat
35
    {
36 4
        return $this->chat;
37
    }
38
39 4
    public function getUser(): User
40
    {
41 4
        return $this->user;
42
    }
43
44 2
    public function getIntent(): ?Intent
45
    {
46 2
        return $this->intent;
47
    }
48
49 2
    public function setIntent(Intent $intent): Context
50
    {
51 2
        $this->intent = $intent;
52
53 2
        return $this;
54
    }
55
56 2
    public function getInteraction(): ?Interaction
57
    {
58 2
        return $this->interaction;
59
    }
60
61 2
    public function setInteraction(?Interaction $interaction): Context
62
    {
63 2
        $this->interaction = $interaction;
64
65 2
        return $this;
66
    }
67
68 4
    public function get(string $key, $default = null)
69
    {
70 4
        return $this->items->get($key, $default);
71
    }
72
73 2
    public function set(string $key, $value): Context
74
    {
75 2
        $this->items->put($key, $value);
76
77 2
        return $this;
78
    }
79
80 2
    public function toArray(): array
81
    {
82
        return [
83 2
            'intent' => $this->intent ? get_class($this->intent) : null,
84 2
            'interaction' => $this->interaction ? get_class($this->interaction) : null,
85 2
            'items' => $this->items->toArray(),
86
        ];
87
    }
88
}
89