GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#159)
by Roman
01:51
created

Catalog   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 58
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAliases() 0 6 1
A populateFromResponse() 0 10 2
A getServiceUrl() 0 17 4
1
<?php declare(strict_types=1);
2
3
namespace OpenStack\Identity\v2\Models;
4
5
use OpenStack\Common\Resource\Alias;
6
use OpenStack\Common\Resource\OperatorResource;
7
use OpenStack\Common\Transport\Utils;
8
use Psr\Http\Message\ResponseInterface;
9
10
/**
11
 * Represents an Identity v2 service catalog.
12
 *
13
 * @package OpenStack\Identity\v2\Models
14
 */
15
class Catalog extends OperatorResource implements \OpenStack\Common\Auth\Catalog
16
{
17
    const DEFAULT_URL_TYPE = 'publicURL';
18
19
    /**
20
     * The catalog entries
21
     *
22
     * @var []Entry
23
     */
24
    public $entries = [];
25
26
    /**
27
     * @var array
28 1
     */
29
    protected $aliases = [];
30 1
31
    /**
32 1
     * @inheritdoc
33 1
     */
34 1
    protected function getAliases(): array
35 1
    {
36
        $aliases = parent::getAliases();
37 2
        $aliases['entries'] = new Alias('entries', Entry::class, true);
38
        return $aliases;
39 2
    }
40 1
41 1
    /**
42
     * {@inheritDoc}
43 1
     */
44
    public function populateFromResponse(ResponseInterface $response): self
45 1
    {
46 1
        $entries = Utils::jsonDecode($response)['access']['serviceCatalog'];
47 1
48 1
        foreach ($entries as $entry) {
49
            $this->entries[] = $this->model(Entry::class, $entry);
50
        }
51
52
        return $this;
53
    }
54
55
    public function getServiceUrl(
56
        string $serviceName,
57
        string $serviceType,
58
        string $region,
59
        string $urlType = self::DEFAULT_URL_TYPE
60
    ): string {
61
        foreach ($this->entries as $entry) {
62
            if ($entry->matches($serviceName, $serviceType) && ($url = $entry->getEndpointUrl($region, $urlType))) {
63
                return $url;
64
            }
65
        }
66
67
        throw new \RuntimeException(sprintf(
68
            "Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s",
69
            $serviceName, $serviceType, $region, $urlType
70
        ));
71
    }
72
}
73