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.

Catalog   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
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 53
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
     * @inheritdoc
28 1
     */
29
    protected function getAliases(): array
30 1
    {
31
        return parent::getAliases() + [
32 1
            'entries' => new Alias('entries', Entry::class, true)
33 1
        ];
34 1
    }
35 1
36
    /**
37 2
     * {@inheritDoc}
38
     */
39 2
    public function populateFromResponse(ResponseInterface $response): self
40 1
    {
41 1
        $entries = Utils::jsonDecode($response)['access']['serviceCatalog'];
42
43 1
        foreach ($entries as $entry) {
44
            $this->entries[] = $this->model(Entry::class, $entry);
45 1
        }
46 1
47 1
        return $this;
48 1
    }
49
50
    public function getServiceUrl(
51
        string $serviceName,
52
        string $serviceType,
53
        string $region,
54
        string $urlType = self::DEFAULT_URL_TYPE
55
    ): string {
56
        foreach ($this->entries as $entry) {
57
            if ($entry->matches($serviceName, $serviceType) && ($url = $entry->getEndpointUrl($region, $urlType))) {
58
                return $url;
59
            }
60
        }
61
62
        throw new \RuntimeException(sprintf(
63
            "Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s",
64
            $serviceName, $serviceType, $region, $urlType
65
        ));
66
    }
67
}
68