Completed
Push — master ( 3147c9...abfbd6 )
by Vladimir
03:05
created

InteractsWithContext::getChannel()   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
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Traits;
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 1
    protected function getChannel(): Channel
15
    {
16 1
        return $this->context()->getChannel();
17
    }
18
19
    /**
20
     * Get chat.
21
     *
22
     * @return Chat
23
     */
24 1
    protected function getChat(): Chat
25
    {
26 1
        return $this->context()->getChat();
27
    }
28
29
    /**
30
     * Get user.
31
     *
32
     * @return User
33
     */
34 1
    protected function getUser(): User
35
    {
36 1
        return $this->context()->getUser();
37
    }
38
39
    /**
40
     * Get the whole context or a single value.
41
     *
42
     * @param string|null $key
43
     * @param mixed       $default
44
     *
45
     * @return Context|mixed
46
     */
47 5
    protected function context(string $key = null, $default = null)
48
    {
49 5
        return context($key, $default);
50
    }
51
52
    /**
53
     * Remember value in context.
54
     *
55
     * @param string $key
56
     * @param mixed  $value
57
     */
58 1
    protected function remember(string $key, $value): void
59
    {
60 1
        context()->set($key, $value);
61 1
    }
62
}
63