Passed
Branch 1.0 (f7255b)
by Vladimir
06:00
created

Driver::getHeaders()   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 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Drivers;
6
7
use FondBot\Helpers\Arr;
8
use FondBot\Queue\SerializableForQueue;
9
use FondBot\Drivers\Exceptions\InvalidRequest;
10
11
abstract class Driver implements SerializableForQueue
12
{
13
    /** @var array */
14
    protected $request = [];
15
16
    /** @var array */
17
    protected $headers = [];
18
19
    /** @var array */
20
    protected $parameters;
21
22
    /**
23
     * Set driver data.
24
     *
25
     * @param array $parameters
26
     * @param array $request
27
     * @param array $headers
28
     */
29 3
    public function fill(array $parameters, array $request = [], array $headers = []): void
30
    {
31 3
        $this->parameters = $parameters;
32 3
        $this->request = $request;
33 3
        $this->headers = $headers;
34 3
    }
35
36
    /**
37
     * Get request value.
38
     *
39
     * @param string|null $key
40
     * @param null        $default
41
     *
42
     * @return mixed
43
     */
44 1
    public function getRequest(string $key = null, $default = null)
45
    {
46 1
        return Arr::get($this->request, $key, $default);
47
    }
48
49
    /**
50
     * If request has key.
51
     *
52
     * @param string $key
53
     *
54
     * @return bool
55
     */
56 1
    public function hasRequest(string $key): bool
57
    {
58 1
        return Arr::has($this->request, [$key]);
59
    }
60
61
    /**
62
     * Get header.
63
     *
64
     * @param string $name
65
     * @param null   $default
66
     *
67
     * @return mixed
68
     */
69 1
    public function getHeader(string $name = null, $default = null)
70
    {
71 1
        return Arr::get($this->headers, $name, $default);
72
    }
73
74
    /**
75
     * Get parameter value.
76
     *
77
     * @param string $name
78
     * @param null   $default
79
     *
80
     * @return mixed
81
     */
82 1
    public function getParameter(string $name, $default = null)
83
    {
84 1
        return Arr::get($this->parameters, $name, $default);
85
    }
86
87
    /**
88
     * Verify incoming request data.
89
     *
90
     * @throws InvalidRequest
91
     */
92
    abstract public function verifyRequest(): void;
93
94
    /**
95
     * Get current chat.
96
     *
97
     * @return Chat
98
     */
99
    abstract public function getChat(): Chat;
100
101
    /**
102
     * Get current user.
103
     *
104
     * @return User
105
     */
106
    abstract public function getUser(): User;
107
108
    /**
109
     * Get message received from sender.
110
     *
111
     * @return ReceivedMessage
112
     */
113
    abstract public function getMessage(): ReceivedMessage;
114
115
    /**
116
     * Handle command.
117
     *
118
     * @param Command $command
119
     */
120
    abstract public function handle(Command $command): void;
121
}
122