Passed
Pull Request — master (#34)
by Darío
04:15 queued 02:10
created

ClientRequest::setHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 5
rs 10
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
3
namespace EasyHttp\LayerContracts\Common;
4
5
use EasyHttp\LayerContracts\Contracts\HttpClientRequest;
6
use EasyHttp\LayerContracts\Contracts\Request\HttpRequestSecurity;
7
8
class ClientRequest implements HttpClientRequest
9
{
10
    protected string $method;
11
    protected string $uri;
12
    protected array $headers = [];
13
    protected array $json = [];
14
    protected array $query = [];
15
    protected ?HttpRequestSecurity $securityContext = null;
16
    protected int $timeout = 10;
17
    protected array $basicAuth = [];
18
    protected bool $ssl = false;
19
20 7
    public function __construct(string $method, string $uri)
21
    {
22 7
        $this->method  = $method;
23 7
        $this->uri     = $uri;
24
    }
25
26 7
    public function getMethod(): string
27
    {
28 7
        return $this->method;
29
    }
30
31 7
    public function getUri(): string
32
    {
33 7
        return $this->uri;
34
    }
35
36
    public function getHeader(string $key)
37
    {
38
        return $this->headers[$key] ?? null;
39
    }
40
41
    public function getHeaders(): array
42
    {
43
        return $this->headers;
44
    }
45
46
    public function getJson(): array
47
    {
48
        return $this->json;
49
    }
50
51
    public function getQuery(): array
52
    {
53
        return $this->query;
54
    }
55
56
    public function getTimeout(): int
57
    {
58
        return $this->timeout;
59
    }
60
61
    public function getSecurityContext(): ?HttpRequestSecurity
62
    {
63
        return $this->securityContext;
64
    }
65
66
    public function getBasicAuth(): array
67
    {
68
        return $this->basicAuth;
69
    }
70
71
    public function hasJson(): bool
72
    {
73
        return !empty($this->json);
74
    }
75
76
    public function hasQuery(): bool
77
    {
78
        return !empty($this->query);
79
    }
80
81
    public function hasHeaders(): bool
82
    {
83
        return !empty($this->headers);
84
    }
85
86
    public function hasSecurityContext(): bool
87
    {
88
        return !is_null($this->getSecurityContext());
89
    }
90
91
    public function setMethod(string $method): self
92
    {
93
        $this->method = $method;
94
95
        return $this;
96
    }
97
98
    public function setUri(string $uri): self
99
    {
100
        $this->uri = $uri;
101
102
        return $this;
103
    }
104
105
    public function setHeader(string $key, string $value): self
106
    {
107
        $this->headers[$key] = $value;
108
109
        return $this;
110
    }
111
112
    public function setJson(array $json): self
113
    {
114
        $this->json = $json;
115
116
        return $this;
117
    }
118
119
    public function setQuery(array $query): self
120
    {
121
        $this->query = $query;
122
123
        return $this;
124
    }
125
126
    public function setTimeout(int $timeout): self
127
    {
128
        $this->timeout = $timeout;
129
130
        return $this;
131
    }
132
133
    public function setSecurityContext(HttpRequestSecurity $securityContext): self
134
    {
135
        $this->securityContext = $securityContext;
136
137
        return $this;
138
    }
139
140
    public function setBasicAuth(string $username, string $password): self
141
    {
142
        $this->basicAuth = [$username, $password];
143
144
        return $this;
145
    }
146
147
    public function ssl(bool $ssl): self
148
    {
149
        $this->ssl = $ssl;
150
151
        return $this;
152
    }
153
154
    public function isSSL(): bool
155
    {
156
        return $this->ssl;
157
    }
158
}
159