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

Transitions::move()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Traits;
6
7
use FondBot\Bot;
8
use InvalidArgumentException;
9
use FondBot\Conversation\Interaction;
10
11
trait Transitions
12
{
13
    /** @var Bot */
14
    protected $bot;
15
16
    /**
17
     * Whether any transition run.
18
     *
19
     * @var bool
20
     */
21
    protected $transitioned = false;
22
23
    /**
24
     * Jump to another interaction.
25
     *
26
     * @param string $interaction
27
     *
28
     * @throws \InvalidArgumentException
29
     */
30
    protected function jump(string $interaction): void
31
    {
32
        /** @var Interaction $instance */
33
        $instance = $this->bot->get($interaction);
34
35
        if (!$instance instanceof Interaction) {
36
            throw new InvalidArgumentException('Invalid interaction `'.$interaction.'`');
37
        }
38
39
        // Run interaction
40
        $this->bot->converse($instance);
41
42
        $this->transitioned = true;
43
    }
44
}
45