Completed
Push — master ( afce1d...f8221d )
by Vladimir
09:37
created

SendsMessages::sendRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 10
loc 10
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Traits;
6
7
use FondBot\Drivers\Chat;
8
use FondBot\Drivers\User;
9
use FondBot\Contracts\Template;
10
use FondBot\Templates\Attachment;
11
use FondBot\Drivers\Commands\SendMessage;
12
use FondBot\Drivers\Commands\SendRequest;
13
use FondBot\Drivers\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 3
        $command = new SendMessage($this->getChat(), $this->getUser(), $text, $template);
27
28 3
        if ($delay > 0) {
29 1
            $command->delay($delay);
30
        }
31
32 3
        kernel()->dispatch($command);
33 3
    }
34
35
    /**
36
     * Send attachment to user.
37
     *
38
     * @param Attachment $attachment
39
     * @param int        $delay
40
     */
41 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...
42
    {
43 2
        $command = new SendAttachment($this->getChat(), $this->getUser(), $attachment);
44
45 2
        if ($delay > 0) {
46 1
            $command->delay($delay);
47
        }
48
49 2
        kernel()->dispatch($command);
50 2
    }
51
52
    /**
53
     * Send request to the messaging service.
54
     *
55
     * @param string $endpoint
56
     * @param array  $parameters
57
     * @param int    $delay
58
     */
59 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...
60
    {
61 1
        $command = new SendRequest($this->getChat(), $this->getUser(), $endpoint, $parameters);
62
63 1
        if ($delay > 0) {
64
            $command->delay($delay);
65
        }
66
67 1
        kernel()->dispatch($command);
68 1
    }
69
70
    /**
71
     * Get chat.
72
     *
73
     * @return Chat
74
     */
75
    abstract protected function getChat(): Chat;
76
77
    /**
78
     * Get user.
79
     *
80
     * @return User
81
     */
82
    abstract protected function getUser(): User;
83
}
84