Completed
Push — master ( 832bbc...8568db )
by Vladimir
03:10
created

Transitions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A jump() 0 12 2
A restart() 0 4 1
A conversationManager() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Traits;
6
7
use InvalidArgumentException;
8
use FondBot\Conversation\Interaction;
9
use FondBot\Conversation\ConversationManager;
10
11
trait Transitions
12
{
13
    /**
14
     * Jump to another interaction.
15
     *
16
     * @param string $interaction
17
     *
18
     * @throws \InvalidArgumentException
19
     */
20 3
    protected function jump(string $interaction): void
21
    {
22
        /** @var Interaction $instance */
23 3
        $instance = resolve($interaction);
24
25 2
        if (!$instance instanceof Interaction) {
26 1
            throw new InvalidArgumentException('Invalid interaction `'.$interaction.'`');
27
        }
28
29
        // Run interaction
30 1
        $this->conversationManager()->converse($instance);
31 1
    }
32
33
    /**
34
     * Restart current intent or interaction.
35
     */
36 2
    protected function restart(): void
37
    {
38 2
        $this->conversationManager()->restart($this);
39 2
    }
40
41 3
    private function conversationManager(): ConversationManager
42
    {
43 3
        return resolve(ConversationManager::class);
44
    }
45
}
46