Completed
Push — master ( 6b3205...83e537 )
by José
57s
created

LocalDockerRegistryClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 85
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getUrl() 0 4 1
A getPort() 0 4 1
A getVersion() 0 4 1
A getClient() 0 4 1
A call() 0 4 1
1
<?php
2
3
namespace Josepostiga\DockerRegistry\Services;
4
5
use GuzzleHttp\Client;
6
use Josepostiga\DockerRegistry\Contracts\DockerRegistryClientInterface;
7
8
class LocalDockerRegistryClient implements DockerRegistryClientInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    private $url;
14
15
    /**
16
     * @var int
17
     */
18
    private $port;
19
20
    /**
21
     * @var Client
22
     */
23
    private $client;
24
25
    /**
26
     * @var string
27
     */
28
    private $version;
29
30
    /**
31
     * DockerRegistryApiClient constructor.
32
     *
33
     * @param string $url
34
     * @param int $port
35
     * @param string $version
36
     */
37
    public function __construct(string $url, int $port, string $version)
38
    {
39
        $this->url = $url;
40
        $this->port = $port;
41
        $this->version = $version;
42
43
        $this->client = new Client([
44
            'base_uri' => "{$this->getUrl()}:{$this->getPort()}/{$this->getVersion()}",
45
        ]);
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getUrl(): string
52
    {
53
        return $this->url;
54
    }
55
56
    /**
57
     * @return int
58
     */
59
    public function getPort(): int
60
    {
61
        return $this->port;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getVersion(): string
68
    {
69
        return $this->version;
70
    }
71
72
    /**
73
     * @return Client
74
     */
75
    public function getClient(): Client
76
    {
77
        return $this->client;
78
    }
79
80
    /**
81
     * Proxies method calls to the Http client instance.
82
     *
83
     * @param $resource
84
     * @param $arguments
85
     *
86
     * @return mixed
87
     */
88
    public function call($resource, $arguments = null)
89
    {
90
        return $this->getClient()->$resource(...$arguments);
91
    }
92
}
93