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

SendsMessages   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 34.62 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 18
loc 52
c 0
b 0
f 0
ccs 15
cts 15
cp 1
rs 10
wmc 3
lcom 0
cbo 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sendMessage() 0 9 1
A sendAttachment() 9 9 1
A sendRequest() 9 9 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\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