Passed
Push — feature/support-certificate-an... ( 2971d0...02294b )
by Darío
02:33
created

ClientRequest::setHeaders()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
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 9
    public function __construct(string $method, string $uri)
21
    {
22 9
        $this->method  = $method;
23 9
        $this->uri     = $uri;
24
    }
25
26 9
    public function getMethod(): string
27
    {
28 9
        return $this->method;
29
    }
30
31 9
    public function getUri(): string
32
    {
33 9
        return $this->uri;
34
    }
35
36 1
    public function getHeader(string $key)
37
    {
38 1
        return $this->headers[$key] ?? null;
39
    }
40
41 1
    public function getHeaders(): array
42
    {
43 1
        return $this->headers;
44
    }
45
46 1
    public function getJson(): array
47
    {
48 1
        return $this->json;
49
    }
50
51 1
    public function getQuery(): array
52
    {
53 1
        return $this->query;
54
    }
55
56 1
    public function getTimeout(): int
57
    {
58 1
        return $this->timeout;
59
    }
60
61
    public function getSecurityContext(): ?HttpRequestSecurity
62
    {
63
        return $this->securityContext;
64
    }
65
66 1
    public function getBasicAuth(): array
67
    {
68 1
        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 1
    public function setMethod(string $method): self
92
    {
93 1
        $this->method = $method;
94
95 1
        return $this;
96
    }
97
98 1
    public function setUri(string $uri): self
99
    {
100 1
        $this->uri = $uri;
101
102 1
        return $this;
103
    }
104
105 1
    public function setHeader(string $key, string $value): self
106
    {
107 1
        $this->headers[$key] = $value;
108
109 1
        return $this;
110
    }
111
112 1
    public function setHeaders(array $headers): self
113
    {
114 1
        foreach ($headers as $key => $value) {
115 1
            $this->setHeader($key, $value);
116
        }
117
118 1
        return $this;
119
    }
120
121 1
    public function setJson(array $json): self
122
    {
123 1
        $this->json = $json;
124
125 1
        return $this;
126
    }
127
128 1
    public function setQuery(array $query): self
129
    {
130 1
        $this->query = $query;
131
132 1
        return $this;
133
    }
134
135 1
    public function setTimeout(int $timeout): self
136
    {
137 1
        $this->timeout = $timeout;
138
139 1
        return $this;
140
    }
141
142
    public function setSecurityContext(HttpRequestSecurity $securityContext): self
143
    {
144
        $this->securityContext = $securityContext;
145
146
        return $this;
147
    }
148
149 1
    public function setBasicAuth(string $username, string $password): self
150
    {
151 1
        $this->basicAuth = [$username, $password];
152
153 1
        return $this;
154
    }
155
156
    public function ssl(bool $ssl): self
157
    {
158
        $this->ssl = $ssl;
159
160
        return $this;
161
    }
162
163
    public function isSSL(): bool
164
    {
165
        return $this->ssl;
166
    }
167
}
168