Completed
Push — master ( f3e44e...1f022d )
by Vladimir
02:48
created

SendsMessages::reply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 10
ccs 9
cts 9
cp 1
crap 1
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Concerns;
6
7
use FondBot\Contracts\Template;
8
use FondBot\Templates\Attachment;
9
use FondBot\Foundation\Commands\SendMessage;
10
use FondBot\Foundation\Commands\SendRequest;
11
use FondBot\Foundation\Commands\SendAttachment;
12
13
trait SendsMessages
14
{
15
    /**
16
     * Reply to user.
17
     *
18
     * @param string|null   $text
19
     * @param Template|null $template
20
     * @param int           $delay
21
     */
22 3
    protected function reply(string $text = null, Template $template = null, int $delay = 0): void
23
    {
24 3
        SendMessage::dispatch(
25 3
            context()->getChannel(),
26 3
            context()->getChat(),
27 3
            context()->getUser(),
28 3
            $text,
29 3
            $template
30 3
        )->delay($delay);
31 3
    }
32
33
    /**
34
     * Send attachment to user.
35
     *
36
     * @param Attachment $attachment
37
     * @param int        $delay
38
     */
39 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...
40
    {
41 2
        SendAttachment::dispatch(
42 2
            context()->getChannel(),
43 2
            context()->getChat(),
44 2
            context()->getUser(),
45 2
            $attachment
46 2
        )->delay($delay);
47 2
    }
48
49
    /**
50
     * Send request to the messaging service.
51
     *
52
     * @param string $endpoint
53
     * @param array  $parameters
54
     * @param int    $delay
55
     */
56 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...
57
    {
58 1
        SendRequest::dispatch(
59 1
            context()->getChannel(),
60 1
            context()->getChat(),
61 1
            context()->getUser(),
62 1
            $endpoint,
63 1
            $parameters
64 1
        )->delay($delay);
65 1
    }
66
}
67