Completed
Push — master ( cd535a...da42ba )
by Vladimir
02:31
created

Interaction::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 3
eloc 10
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation;
6
7
use FondBot\Bot;
8
use FondBot\Traits\Loggable;
9
use FondBot\Conversation\Traits\Transitions;
10
use FondBot\Conversation\Traits\SendsMessages;
11
use FondBot\Contracts\Conversation\Conversable;
12
use FondBot\Conversation\Traits\InteractsWithContext;
13
use FondBot\Contracts\Conversation\Interaction as InteractionContract;
14
15
abstract class Interaction implements InteractionContract, Conversable
16
{
17
    use InteractsWithContext,
18
        SendsMessages,
19
        Transitions,
20
        Loggable;
21
22
    /**
23
     * Handle interaction.
24
     *
25
     * @param Bot $bot
26
     */
27
    final public function handle(Bot $bot): void
28
    {
29
        $this->bot = $bot;
30
        $context = $this->bot->getContext();
31
32
        if ($context->getInteraction() instanceof $this) {
33
            $this->process($context->getMessage());
34
35
            if (!$this->transitioned) {
36
                $this->bot->clearContext();
37
            }
38
        } else {
39
            $this->bot->getContext()->setInteraction($this);
40
            $this->run();
41
        }
42
    }
43
}
44