Completed
Push — master ( 2eb041...554cb3 )
by Vladimir
03:14
created

Driver::hasRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Contracts\Channels;
6
7
use FondBot\Helpers\Arr;
8
use FondBot\Traits\Loggable;
9
use FondBot\Contracts\Conversation\Keyboard;
10
use FondBot\Channels\Exceptions\InvalidChannelRequest;
11
12
abstract class Driver
13
{
14
    use Loggable;
15
16
    /** @var array */
17
    private $request = [];
18
19
    /** @var array */
20
    private $headers = [];
21
22
    /** @var array */
23
    private $parameters;
24
25
    /**
26
     * Set driver data.
27
     *
28
     * @param array $parameters
29
     * @param array $request
30
     * @param array $headers
31
     */
32 29
    public function fill(array $parameters, array $request = [], array $headers = []): void
33
    {
34 29
        $this->parameters = $parameters;
35 29
        $this->request = $request;
36 29
        $this->headers = $headers;
37 29
    }
38
39
    /**
40
     * Get request value.
41
     *
42
     * @param string|null $key
43
     *
44
     * @return mixed
45
     */
46 19
    public function getRequest(string $key = null)
47
    {
48 19
        return Arr::get($this->request, $key);
49
    }
50
51
    /**
52
     * If request has key.
53
     *
54
     * @param string $key
55
     *
56
     * @return bool
57
     */
58 7
    public function hasRequest(string $key): bool
59
    {
60 7
        return Arr::has($this->request, [$key]);
61
    }
62
63
    /**
64
     * Get all headers.
65
     *
66
     * @return array
67
     */
68
    public function getHeaders(): array
69
    {
70
        return $this->headers;
71
    }
72
73
    /**
74
     * Get header.
75
     *
76
     * @param string $name
77
     *
78
     * @return mixed
79
     */
80 5
    public function getHeader(string $name)
81
    {
82 5
        return Arr::get($this->headers, $name);
83
    }
84
85
    /**
86
     * Get parameter value.
87
     *
88
     * @param string $name
89
     *
90
     * @return mixed
91
     */
92 15
    public function getParameter(string $name)
93
    {
94 15
        return Arr::get($this->parameters, $name);
95
    }
96
97
    /**
98
     * Configuration parameters.
99
     *
100
     * @return array
101
     */
102
    abstract public function getConfig(): array;
103
104
    /**
105
     * Verify incoming request data.
106
     *
107
     * @throws InvalidChannelRequest
108
     */
109
    abstract public function verifyRequest(): void;
110
111
    /**
112
     * Get user.
113
     *
114
     * @return User
115
     */
116
    abstract public function getUser(): User;
117
118
    /**
119
     * Get message received from sender.
120
     *
121
     * @return ReceivedMessage
122
     */
123
    abstract public function getMessage(): ReceivedMessage;
124
125
    /**
126
     * Send reply to participant.
127
     *
128
     * @param User          $sender
129
     * @param string        $text
130
     * @param Keyboard|null $keyboard
131
     *
132
     * @return OutgoingMessage
133
     */
134
    abstract public function sendMessage(User $sender, string $text, Keyboard $keyboard = null): OutgoingMessage;
135
}
136