Completed
Push — master ( c010a4...803e6e )
by Vladimir
06:15 queued 03:25
created

SendMessage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 64.29%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 3
A handle() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation\Commands;
6
7
use FondBot\Channels\Chat;
8
use FondBot\Channels\User;
9
use FondBot\Channels\Channel;
10
use Illuminate\Bus\Queueable;
11
use InvalidArgumentException;
12
use FondBot\Contracts\Template;
13
use Illuminate\Queue\InteractsWithQueue;
14
use Illuminate\Contracts\Queue\ShouldQueue;
15
use Illuminate\Foundation\Bus\Dispatchable;
16
17
class SendMessage implements ShouldQueue
18
{
19
    use InteractsWithQueue, Queueable, Dispatchable;
20
21
    private $channel;
22
    private $chat;
23
    private $recipient;
24
    private $text;
25
    private $template;
26
27 5
    public function __construct(
28
        Channel $channel,
29
        Chat $chat,
30
        User $recipient,
31
        string $text = null,
32
        Template $template = null
33
    ) {
34 5
        if ($text === null && $template === null) {
35 1
            throw new InvalidArgumentException('Either text or template should be set.');
36
        }
37
38 4
        $this->channel = $channel;
39 4
        $this->chat = $chat;
40 4
        $this->recipient = $recipient;
41 4
        $this->text = $text;
42 4
        $this->template = $template;
43 4
    }
44
45
    public function handle(): void
46
    {
47
        logger('SendMessage.handle');
48
        $driver = $this->channel->getDriver();
49
        $driver->sendMessage($this->chat, $this->recipient, $this->text, $this->template);
50
    }
51
}
52