Passed
Pull Request — master (#35)
by
unknown
03:59 queued 02:21
created

Response   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
eloc 8
c 1
b 1
f 0
dl 0
loc 44
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeaders() 0 3 1
A getBody() 0 3 1
A hasBody() 0 3 1
A getHeader() 0 3 1
A hasHeader() 0 3 1
A getHttpResponseCode() 0 3 1
A __construct() 0 7 1
A getRequestedUrl() 0 3 1
1
<?php
2
3
namespace Rogierw\RwAcme\Http;
4
5
class Response
6
{
7
    public function __construct(
8
        private readonly array        $headers,
9
        private readonly string       $requestedUrl,
10
        private readonly ?int         $statusCode,
11
        private readonly array|string $body,
12
    )
13
    {
14
    }
15
16
    public function getHeader(string $name, $default = null): mixed
17
    {
18
        return $this->headers[$name] ?? $default;
19
    }
20
21
    public function getHeaders(): array
22
    {
23
        return $this->headers;
24
    }
25
26
    public function hasHeader(string $name): bool
27
    {
28
        return isset($this->headers[$name]);
29
    }
30
31
    public function getBody(): array|string
32
    {
33
        return $this->body;
34
    }
35
36
    public function getRequestedUrl(): string
37
    {
38
        return $this->requestedUrl;
39
    }
40
41
    public function hasBody(): bool
42
    {
43
        return !empty($this->body);
44
    }
45
46
    public function getHttpResponseCode(): ?int
47
    {
48
        return $this->statusCode;
49
    }
50
}
51