Completed
Push — master ( ad5c5d...817c3d )
by Vladimir
03:24
created

Driver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 122
ccs 5
cts 15
cp 0.3333
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A fill() 0 6 1
A getHeaders() 0 4 1
getConfig() 0 1 ?
verifyRequest() 0 1 ?
getUser() 0 1 ?
getMessage() 0 1 ?
sendMessage() 0 1 ?
A hasRequest() 0 4 1
A getHeader() 0 4 1
A getRequest() 0 4 1
A getParameter() 0 4 1
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 1
    public function fill(array $parameters, array $request = [], array $headers = []): void
30
    {
31 1
        $this->parameters = $parameters;
32 1
        $this->request = $request;
33 1
        $this->headers = $headers;
34 1
    }
35
36
    /**
37
     * Get request value.
38
     *
39
     * @param string|null $key
40
     *
41
     * @return mixed
42
     */
43
    public function getRequest(string $key = null)
44
    {
45
        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
    public function getParameter(string $name)
90
    {
91
        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