Passed
Push — master ( fe1e15...db667c )
by Daniel
27:04 queued 12:14
created

ResourceUri::upload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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
    private function __construct(private readonly string $uri)
18
    {
19
        // ..
20
    }
21
22
    /**
23
     * Creates a new ResourceUri value object that lists the given resource.
24
     */
25
    public static function list(string $resource): self
26
    {
27
        if (empty($resource)) {
28
            throw new \InvalidArgumentException();
29
        }
30
        return new self($resource);
31
    }
32
33
    /**
34
     * Creates a new ResourceUri value object that retrieves the given resource.
35
     */
36
    public static function retrieve(string $resource, string $id): self
37
    {
38
        if (empty($resource) || empty($id)) {
39
            throw new \InvalidArgumentException();
40
        }
41
        return new self("{$resource}/{$id}");
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function toString(): string
48
    {
49
        return $this->uri;
50
    }
51
}
52