Passed
Push — master ( 43d842...ad5c5d )
by Vladimir
03:44
created

Driver::getHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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