Completed
Push — master ( dae18f...dc2daf )
by José
01:20
created

DockerRegistryManifestsRepository::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Josepostiga\DockerRegistry\Repositories;
4
5
use Josepostiga\DockerRegistry\Objects\Manifest;
6
use Josepostiga\DockerRegistry\Contracts\DockerRegistryClientInterface;
7
8
final class DockerRegistryManifestsRepository
9
{
10
    /**
11
     * @var DockerRegistryClientInterface
12
     */
13
    private $client;
14
15
    /**
16
     * Image name.
17
     *
18
     * @var string
19
     */
20
    private $image;
21
22
    /**
23
     * Tag name.
24
     *
25
     * @var string
26
     */
27
    private $tag;
28
29
    /**
30
     * DockerRegistryManifestsRepository constructor.
31
     *
32
     * @param DockerRegistryClientInterface $client
33
     * @param string $image
34
     * @param string $tag
35
     */
36
    public function __construct(DockerRegistryClientInterface $client, string $image, string $tag)
37
    {
38
        $this->client = $client;
39
        $this->image = $image;
40
        $this->tag = $tag;
41
    }
42
43
    /**
44
     * Gets image name.
45
     *
46
     * @return string
47
     */
48
    public function getImage(): string
49
    {
50
        return $this->image;
51
    }
52
53
    /**
54
     * Gets tag name.
55
     *
56
     * @return string
57
     */
58
    public function getTag(): string
59
    {
60
        return $this->tag;
61
    }
62
63
    /**
64
     * Get available tag details.
65
     *
66
     * @return Manifest
67
     */
68
    public function get(): Manifest
69
    {
70
        $request = $this->client->call($this->getImage().'/manifests/'.$this->getTag());
71
72
        $response = json_decode($request->getBody(), true);
73
74
        return new Manifest(
75
            $response['schemaVersion'],
76
            $response['name'],
77
            $response['tag'],
78
            $response['architecture'],
79
            $response['fsLayers'],
80
            $response['history'],
81
            $response['signatures']
82
        );
83
    }
84
}
85