Completed
Push — master ( 6adc83...44806f )
by Vladimir
02:38
created

PendingReply::__destruct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 21
ccs 17
cts 17
cp 1
crap 3
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Drivers;
6
7
use FondBot\Channels\Chat;
8
use FondBot\Channels\User;
9
use FondBot\Channels\Channel;
10
use FondBot\Contracts\Template;
11
use FondBot\Templates\Attachment;
12
use FondBot\Foundation\Commands\SendMessage;
13
use FondBot\Foundation\Commands\SendAttachment;
14
15
class PendingReply
16
{
17
    private $channel;
18
    private $chat;
19
    private $user;
20
    private $text;
21
    private $template;
22
    private $attachment;
23
    private $delay;
24
25 5
    public function __construct(Channel $channel, Chat $chat, User $user)
26
    {
27 5
        $this->channel = $channel;
28 5
        $this->chat = $chat;
29 5
        $this->user = $user;
30 5
    }
31
32
    /**
33
     * Set reply text.
34
     *
35
     * @param null|string $text
36
     *
37
     * @return static
38
     */
39 3
    public function text(?string $text)
40
    {
41 3
        $this->text = $text;
42
43 3
        return $this;
44
    }
45
46
    /**
47
     * Set template for reply.
48
     *
49
     * @param Template|null $template
50
     *
51
     * @return static
52
     */
53 2
    public function template(?Template $template)
54
    {
55 2
        $this->template = $template;
56
57 2
        return $this;
58
    }
59
60
    /**
61
     * Set attachment for send.
62
     *
63
     * @param Attachment $attachment
64
     *
65
     * @return static
66
     */
67 2
    public function attachment(Attachment $attachment)
68
    {
69 2
        $this->attachment = $attachment;
70
71 2
        return $this;
72
    }
73
74
    /**
75
     * Set the desired delay for the job.
76
     *
77
     * @param  \DateTime|int|null $delay
78
     *
79
     * @return static
80
     */
81 2
    public function delay($delay)
82
    {
83 2
        $this->delay = $delay;
84
85 2
        return $this;
86
    }
87
88 5
    public function __destruct()
89
    {
90 5
        if ($this->text) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->text of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
91 3
            SendMessage::dispatch(
92 3
                $this->channel,
93 3
                $this->chat,
94 3
                $this->user,
95 3
                $this->text,
96 3
                $this->template
97 3
            )->delay($this->delay);
98
        }
99
100 5
        if ($this->attachment) {
101 2
            SendAttachment::dispatch(
102 2
                $this->channel,
103 2
                $this->chat,
104 2
                $this->user,
105 2
                $this->attachment
106 2
            )->delay($this->delay);
107
        }
108 5
    }
109
}
110