InteractsWithContext   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 6
dl 0
loc 54
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getChat() 0 3 1
A context() 0 3 1
A remember() 0 3 1
A getUser() 0 3 1
A getChannel() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Concerns;
6
7
use FondBot\Channels\Chat;
8
use FondBot\Channels\User;
9
use FondBot\Channels\Channel;
10
use FondBot\Conversation\Context;
11
12
trait InteractsWithContext
13
{
14
    /**
15
     * Get channel.
16
     *
17
     * @return Channel
18
     */
19 1
    protected function getChannel(): Channel
20
    {
21 1
        return $this->context()->getChannel();
22
    }
23
24
    /**
25
     * Get chat.
26
     *
27
     * @return Chat
28
     */
29 1
    protected function getChat(): Chat
30
    {
31 1
        return $this->context()->getChat();
32
    }
33
34
    /**
35
     * Get user.
36
     *
37
     * @return User
38
     */
39 1
    protected function getUser(): User
40
    {
41 1
        return $this->context()->getUser();
42
    }
43
44
    /**
45
     * Get the whole context or a single value.
46
     *
47
     * @param string|null $key
48
     * @param mixed       $default
49
     *
50
     * @return Context|mixed
51
     */
52 5
    protected function context(string $key = null, $default = null)
53
    {
54 5
        return context($key, $default);
55
    }
56
57
    /**
58
     * Remember value in context.
59
     *
60
     * @param string $key
61
     * @param mixed  $value
62
     */
63 1
    protected function remember(string $key, $value): void
64
    {
65 1
        context()->setItem($key, $value);
66 1
    }
67
}
68