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

SendsMessages   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 35.19 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 19
loc 54
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A reply() 0 10 1
A sendAttachment() 9 9 1
A sendRequest() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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