Passed
Pull Request — master (#1)
by David
02:54
created

RegistryClient   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getImageTagsOnDockerHub() 0 12 1
1
<?php
2
3
4
namespace TheAentMachine\Registry;
5
6
use GuzzleHttp\Client;
7
8
class RegistryClient
9
{
10
    /**
11
     * Returns the list of tags available for an image stored on Docker Hub.
12
     *
13
     * @return string[]
14
     */
15
    public function getImageTagsOnDockerHub(string $image): array
16
    {
17
        $client = new Client();
18
        $res = $client->request('GET', 'https://registry.hub.docker.com/v1/repositories/'.$image.'/tags');
19
20
        $response = \GuzzleHttp\json_decode($res->getBody(), true);
21
22
        $tags = \array_map(function (array $item) {
23
            return $item['name'];
24
        }, $response);
25
26
        return $tags;
27
    }
28
}
29