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

PendingRequest::endpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
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\Foundation\Commands\SendRequest;
11
12
class PendingRequest
13
{
14
    private $channel;
15
    private $chat;
16
    private $user;
17
    private $endpoint;
18
    private $parameters;
19
    private $delay;
20
21 2
    public function __construct(Channel $channel, Chat $chat, User $user)
22
    {
23 2
        $this->channel = $channel;
24 2
        $this->chat = $chat;
25 2
        $this->user = $user;
26 2
    }
27
28
    /**
29
     * Set request endpoint.
30
     *
31
     * @param string $endpoint
32
     *
33
     * @return static
34
     */
35 2
    public function endpoint(string $endpoint)
36
    {
37 2
        $this->endpoint = $endpoint;
38
39 2
        return $this;
40
    }
41
42
    /**
43
     * Set request parameters.
44
     *
45
     * @param $parameters
46
     *
47
     * @return static
48
     */
49 2
    public function parameters($parameters)
50
    {
51 2
        $this->parameters = $parameters;
52
53 2
        return $this;
54
    }
55
56
    /**
57
     * Set the desired delay for the job.
58
     *
59
     * @param  \DateTime|int|null $delay
60
     *
61
     * @return static
62
     */
63 1
    public function delay($delay)
64
    {
65 1
        $this->delay = $delay;
66
67 1
        return $this;
68
    }
69
70 2
    public function __destruct()
71
    {
72 2
        if ($this->endpoint) {
73 2
            SendRequest::dispatch(
74 2
                $this->channel,
75 2
                $this->chat,
76 2
                $this->user,
77 2
                $this->endpoint,
78 2
                $this->parameters
79 2
            )->delay($this->delay);
80
        }
81 2
    }
82
}
83