Completed
Push — master ( 087735...e90d9e )
by Vladimir
03:03
created

Session::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
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;
6
7
use FondBot\Drivers\Chat;
8
use FondBot\Drivers\User;
9
use FondBot\Channels\Channel;
10
use FondBot\Drivers\ReceivedMessage;
11
12
class Session
13
{
14
    private $channel;
15
    private $chat;
16
    private $user;
17
    private $message;
18
    private $intent;
19
    private $interaction;
20
    private $context;
21
22 9
    public function __construct(
23
        Channel $channel,
24
        Chat $chat,
25
        User $user,
26
        ReceivedMessage $message,
27
        Intent $intent = null,
28
        Interaction $interaction = null,
29
        array $context = []
30
    ) {
31 9
        $this->channel = $channel;
32 9
        $this->chat = $chat;
33 9
        $this->user = $user;
34 9
        $this->message = $message;
35 9
        $this->intent = $intent;
36 9
        $this->interaction = $interaction;
37 9
        $this->context = $context;
38 9
    }
39
40
    /**
41
     * Get channel name.
42
     *
43
     * @return Channel
44
     */
45 1
    public function getChannel(): Channel
46
    {
47 1
        return $this->channel;
48
    }
49
50
    /**
51
     * Get chat.
52
     *
53
     * @return Chat
54
     */
55 1
    public function getChat(): Chat
56
    {
57 1
        return $this->chat;
58
    }
59
60
    /**
61
     * Get user.
62
     *
63
     * @return User
64
     */
65 1
    public function getUser(): User
66
    {
67 1
        return $this->user;
68
    }
69
70
    /**
71
     * Get message received from user.
72
     *
73
     * @return ReceivedMessage
74
     */
75 1
    public function getMessage(): ReceivedMessage
76
    {
77 1
        return $this->message;
78
    }
79
80
    /**
81
     * Get current intent.
82
     *
83
     * @return Intent|Conversable|null
84
     */
85 1
    public function getIntent(): ?Intent
86
    {
87 1
        return $this->intent;
88
    }
89
90
    /**
91
     * Set intent.
92
     *
93
     * @param Intent $intent
94
     */
95 1
    public function setIntent(Intent $intent): void
96
    {
97 1
        $this->intent = $intent;
98 1
    }
99
100
    /**
101
     * Get interaction.
102
     *
103
     * @return Interaction|Conversable|null
104
     */
105 1
    public function getInteraction(): ?Interaction
106
    {
107 1
        return $this->interaction;
108
    }
109
110
    /**
111
     * Set interaction.
112
     *
113
     * @param Interaction|null $interaction
114
     */
115 1
    public function setInteraction(?Interaction $interaction): void
116
    {
117 1
        $this->interaction = $interaction;
118 1
    }
119
120
    /**
121
     * Get context.
122
     *
123
     * @return array
124
     */
125 1
    public function getContext(): array
126
    {
127 1
        return $this->context;
128
    }
129
130
    /**
131
     * Set context.
132
     *
133
     * @param array $context
134
     */
135 1
    public function setContext(array $context): void
136
    {
137 1
        $this->context = $context;
138 1
    }
139
140
    /**
141
     * Set single value.
142
     *
143
     * @param string $key
144
     * @param mixed  $value
145
     */
146 1
    public function setContextValue(string $key, $value): void
147
    {
148 1
        $this->context[$key] = $value;
149 1
    }
150
151
    /**
152
     * Get the instance as an array.
153
     *
154
     * @return array
155
     */
156 1
    public function toArray(): array
157
    {
158
        return [
159 1
            'intent' => $this->intent !== null ? get_class($this->intent) : null,
160 1
            'interaction' => $this->interaction !== null ? get_class($this->interaction) : null,
161 1
            'context' => $this->context,
162
        ];
163
    }
164
}
165