SendMessage::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 16
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 10
cc 3
nc 2
nop 5
crap 3
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
        $driver = $this->channel->getDriver();
48
        $driver->sendMessage($this->chat, $this->recipient, $this->text, $this->template);
49
    }
50
}
51