QueryParams::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
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