Completed
Push — master ( f3fb69...091fb5 )
by Vladimir
02:37
created

Converse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation\Commands;
6
7
use FondBot\Conversation\Intent;
8
use FondBot\Events\MessageReceived;
9
use FondBot\Conversation\Interaction;
10
use Illuminate\Foundation\Bus\Dispatchable;
11
use FondBot\Contracts\Conversation\Conversable;
12
13
class Converse
14
{
15
    use Dispatchable;
16
17
    private $conversable;
18
    private $messageReceived;
19
20 1
    public function __construct(Conversable $conversable, MessageReceived $messageReceived)
21
    {
22 1
        $this->conversable = $conversable;
23 1
        $this->messageReceived = $messageReceived;
24 1
    }
25
26 1
    public function handle(): void
27
    {
28 1
        if ($this->conversable instanceof Intent) {
29 1
            context()->setIntent($this->conversable)->setInteraction(null);
30
31 1
            $this->conversable->handle($this->messageReceived);
32
        } elseif ($this->conversable instanceof Interaction) {
33
            $this->conversable->handle($this->messageReceived);
34
        } else {
35
            $this->conversable->handle($this->messageReceived);
36
        }
37 1
    }
38
}
39