Passed
Push — master ( 236a58...055c31 )
by Vladimir
07:58
created

Context::getUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation;
6
7
use FondBot\Drivers\Chat;
8
use FondBot\Drivers\User;
9
use FondBot\Channels\Channel;
10
use FondBot\Contracts\Arrayable;
11
12
class Context implements Arrayable
13
{
14
    private $channel;
15
    private $chat;
16
    private $user;
17
    private $items;
18
19 3
    public function __construct(Channel $channel, Chat $chat, User $user, array $items = [])
20
    {
21 3
        $this->channel = $channel;
22 3
        $this->chat = $chat;
23 3
        $this->user = $user;
24 3
        $this->items = collect($items);
25 3
    }
26
27
    /**
28
     * Get channel.
29
     *
30
     * @return Channel
31
     */
32 1
    public function getChannel(): Channel
33
    {
34 1
        return $this->channel;
35
    }
36
37
    /**
38
     * Get chat.
39
     *
40
     * @return Chat
41
     */
42 1
    public function getChat(): Chat
43
    {
44 1
        return $this->chat;
45
    }
46
47
    /**
48
     * Get user.
49
     *
50
     * @return User
51
     */
52 1
    public function getUser(): User
53
    {
54 1
        return $this->user;
55
    }
56
57
    /**
58
     * Get item.
59
     *
60
     * @param string $key
61
     * @param null   $default
62
     *
63
     * @return mixed
64
     */
65 3
    public function get(string $key, $default = null)
66
    {
67 3
        return $this->items->get($key, $default);
68
    }
69
70
    /**
71
     * Set item.
72
     *
73
     * @param string $key
74
     * @param mixed  $value
75
     */
76 2
    public function set(string $key, $value): void
77
    {
78 2
        $this->items->put($key, $value);
79 2
    }
80
81
    /**
82
     * Get the instance as an array.
83
     *
84
     * @return array
85
     */
86 1
    public function toArray(): array
87
    {
88 1
        return $this->items->toArray();
89
    }
90
}
91