QueryParams   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 36.36%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 37
ccs 4
cts 11
cp 0.3636
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 3 1
A withParam() 0 5 1
A create() 0 3 1
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\ValueObjects\Transporter;
6
7
/**
8
 * @internal
9
 */
10
final class QueryParams
11
{
12
    /**
13
     * Creates a new Query Params value object.
14
     *
15
     * @param  array<string, string|int>  $params
16
     */
17 20
    private function __construct(private readonly array $params)
18
    {
19
        // ..
20 20
    }
21
22
    /**
23
     * Creates a new Query Params value object
24
     */
25 20
    public static function create(): self
26
    {
27 20
        return new self([]);
28
    }
29
30
    /**
31
     * Creates a new Query Params value object, with the newly added param, and the existing params.
32
     */
33
    public function withParam(string $name, string | int $value): self
34
    {
35
        return new self([
36
            ...$this->params,
37
            $name => $value,
38
        ]);
39
    }
40
41
    /**
42
     * @return array<string, string|int>
43
     */
44
    public function toArray(): array
45
    {
46
        return $this->params;
47
    }
48
}
49