Headers   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 47
ccs 10
cts 15
cp 0.6667
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A withContentType() 0 5 1
A __construct() 0 2 1
A withAuthorization() 0 4 1
A create() 0 3 1
A toArray() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\ValueObjects\Transporter;
6
7
use InShore\Bookwhen\ValueObjects\ApiKey;
8
9
/**
10
 * @internal
11
 */
12
final class Headers
13
{
14
    /**
15
     * Creates a new Headers value object.
16
     *
17
     * @param  array<string, string>  $headers
18
     */
19 20
    private function __construct(private readonly array $headers)
20
    {
21
        // ..
22 20
    }
23
24
    /**
25
     * Creates a new Headers value object
26
     */
27 20
    public static function create(): self
28
    {
29 20
        return new self([]);
30
    }
31
32
    /**
33
     * Creates a new Headers value object with the given API token.
34
     */
35 20
    public static function withAuthorization(ApiKey $apiKey): self
36
    {
37 20
        return new self([
38 20
            'Authorization' => 'Basic ' . base64_encode($apiKey->toString() . ':')
39 20
        ]);
40
    }
41
42
    /**
43
     * Creates a new Headers value object, with the given content type, and the existing headers.
44
     */
45
    public function withContentType(): self
46
    {
47
        return new self([
48
            ...$this->headers,
49
            'Content-Type' => 'application/json',
50
        ]);
51
    }
52
53
    /**
54
     * @return array<string, string> $headers
55
     */
56 11
    public function toArray(): array
57
    {
58 11
        return $this->headers;
59
    }
60
}
61