Passed
Push — master ( 98541d...d359a0 )
by
unknown
08:18
created

SendsMessages::sendMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
ccs 5
cts 5
cp 1
crap 1
rs 9.6666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Traits;
6
7
use FondBot\Contracts\Template;
8
use FondBot\Templates\Attachment;
9
use Illuminate\Container\Container;
10
use Illuminate\Contracts\Bus\Dispatcher;
11
use FondBot\Foundation\Commands\SendMessage;
12
use FondBot\Foundation\Commands\SendRequest;
13
use FondBot\Foundation\Commands\SendAttachment;
14
15
trait SendsMessages
16
{
17
    /**
18
     * Send message to user.
19
     *
20
     * @param string|null   $text
21
     * @param Template|null $template
22
     * @param int           $delay
23
     */
24 3
    protected function sendMessage(string $text = null, Template $template = null, int $delay = 0): void
25
    {
26
        /** @var Dispatcher $dispatcher */
27 3
        $dispatcher = Container::getInstance()->make(Dispatcher::class);
28
29 3
        $dispatcher->dispatch(
30 3
            (new SendMessage(session()->getChat(), session()->getUser(), $text, $template))->delay($delay)
31
        );
32 3
    }
33
34
    /**
35
     * Send attachment to user.
36
     *
37
     * @param Attachment $attachment
38
     * @param int        $delay
39
     */
40 2 View Code Duplication
    protected function sendAttachment(Attachment $attachment, int $delay = 0): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        /** @var Dispatcher $dispatcher */
43 2
        $dispatcher = Container::getInstance()->make(Dispatcher::class);
44
45 2
        $dispatcher->dispatch(
46 2
            (new SendAttachment(session()->getChat(), session()->getUser(), $attachment))->delay($delay)
47
        );
48 2
    }
49
50
    /**
51
     * Send request to the messaging service.
52
     *
53
     * @param string $endpoint
54
     * @param array  $parameters
55
     * @param int    $delay
56
     */
57 1 View Code Duplication
    protected function sendRequest(string $endpoint, array $parameters = [], int $delay = 0): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        /** @var Dispatcher $dispatcher */
60 1
        $dispatcher = Container::getInstance()->make(Dispatcher::class);
61
62 1
        $dispatcher->dispatch(
63 1
            (new SendRequest(session()->getChat(), session()->getUser(), $endpoint, $parameters))->delay($delay)
64
        );
65 1
    }
66
}
67