ResourceUri   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 38
ccs 12
cts 12
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A list() 0 6 2
A toString() 0 3 1
A retrieve() 0 6 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\ValueObjects;
6
7
use InShore\Bookwhen\Contracts\StringableContract;
8
9
/**
10
 * @internal
11
 */
12
final class ResourceUri implements StringableContract
13
{
14
    /**
15
     * Creates a new ResourceUri value object.
16
     */
17 13
    private function __construct(private readonly string $uri)
18
    {
19
        // ..
20 13
    }
21
22
    /**
23
     * Creates a new ResourceUri value object that lists the given resource.
24
     */
25 7
    public static function list(string $resource): self
26
    {
27 7
        if (empty($resource)) {
28 1
            throw new \InvalidArgumentException();
29
        }
30 6
        return new self($resource);
31
    }
32
33
    /**
34
     * Creates a new ResourceUri value object that retrieves the given resource.
35
     */
36 8
    public static function retrieve(string $resource, string $id): self
37
    {
38 8
        if (empty($resource) || empty($id)) {
39 1
            throw new \InvalidArgumentException();
40
        }
41 7
        return new self("{$resource}/{$id}");
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47 13
    public function toString(): string
48
    {
49 13
        return $this->uri;
50
    }
51
}
52