Response   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
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 43
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 6 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
    public function getHeader(string $name, $default = null): mixed
16
    {
17
        return $this->headers[$name] ?? $default;
18
    }
19
20
    public function getHeaders(): array
21
    {
22
        return $this->headers;
23
    }
24
25
    public function hasHeader(string $name): bool
26
    {
27
        return isset($this->headers[$name]);
28
    }
29
30
    public function getBody(): array|string
31
    {
32
        return $this->body;
33
    }
34
35
    public function getRequestedUrl(): string
36
    {
37
        return $this->requestedUrl;
38
    }
39
40
    public function hasBody(): bool
41
    {
42
        return !empty($this->body);
43
    }
44
45
    public function getHttpResponseCode(): ?int
46
    {
47
        return $this->statusCode;
48
    }
49
}
50