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

Transitions   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A jump() 0 14 2
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