Passed
Push — develop ( a6f0fe...5308a3 )
by Daniel
24:47 queued 09:44
created

ResourceUri::retrieve()   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 3
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 creates the given resource.
24
     */
25
    public static function create(string $resource): self
26
    {
27
        return new self($resource);
28
    }
29
30
    /**
31
     * Creates a new ResourceUri value object that uploads to the given resource.
32
     */
33
    public static function upload(string $resource): self
34
    {
35
        return new self($resource);
36
    }
37
38
    /**
39
     * Creates a new ResourceUri value object that lists the given resource.
40
     */
41
    public static function list(string $resource): self
42
    {
43
        //         if (empty($parameters)) {
44
        //             return new self($resource);
45
        //         }
46
47
        //         $resource = $resource . '?' . array_reduce(array_keys($parameters), function($carry, $key) use ($parameters) {
48
        //             $value = urlencode($parameters[$key]);
49
        //             return $carry . ($carry ? '&' : '') . urlencode($key) . '=' . $value;
50
        //         });
51
52
        return new self($resource);
53
    }
54
55
    /**
56
     * Creates a new ResourceUri value object that retrieves the given resource.
57
     */
58
    public static function retrieve(string $resource, string $id, string $suffix): self
59
    {
60
        return new self("{$resource}/{$id}{$suffix}");
61
    }
62
63
    /**
64
     * Creates a new ResourceUri value object that retrieves the given resource content.
65
     */
66
    public static function retrieveContent(string $resource, string $id): self
67
    {
68
        return new self("{$resource}/{$id}/content");
69
    }
70
71
    /**
72
     * Creates a new ResourceUri value object that cancels the given resource.
73
     */
74
    public static function cancel(string $resource, string $id): self
75
    {
76
        return new self("{$resource}/{$id}/cancel");
77
    }
78
79
    /**
80
     * Creates a new ResourceUri value object that deletes the given resource.
81
     */
82
    public static function delete(string $resource, string $id): self
83
    {
84
        return new self("{$resource}/{$id}");
85
    }
86
87
    /**
88
     * {@inheritDoc}
89
     */
90
    public function toString(): string
91
    {
92
        return $this->uri;
93
    }
94
}
95