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.
Passed
Push — master ( 307cce...27531d )
by Jamie
04:17 queued 15s
created

Catalog::populateFromResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4286
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace OpenStack\Identity\v2\Models;
4
5
use OpenStack\Common\Resource\AbstractResource;
6
use OpenStack\Common\Transport\Utils;
7
use Psr\Http\Message\ResponseInterface;
8
9
/**
10
 * Represents an Identity v2 service catalog.
11
 *
12
 * @package OpenStack\Identity\v2\Models
13
 */
14
class Catalog extends AbstractResource implements \OpenStack\Common\Auth\Catalog
15
{
16
    const DEFAULT_URL_TYPE = 'publicURL';
17
18
    /**
19
     * The catalog entries
20
     *
21
     * @var []Entry
22
     */
23
    public $entries = [];
24
25
    /**
26
     * {@inheritDoc}
27
     */
28 1
    public function populateFromResponse(ResponseInterface $response)
29
    {
30 1
        $entries = Utils::jsonDecode($response)['access']['serviceCatalog'];
31
32 1
        foreach ($entries as $entry) {
33 1
            $this->entries[] = $this->model(Entry::class, $entry);
34 1
        }
35 1
    }
36
37 2
    public function getServiceUrl($serviceName, $serviceType, $region, $urlType = self::DEFAULT_URL_TYPE)
38
    {
39 2
        foreach ($this->entries as $entry) {
40 1
            if ($entry->matches($serviceName, $serviceType) && ($url = $entry->getEndpointUrl($region, $urlType))) {
41 1
                return $url;
42
            }
43 1
        }
44
45 1
        throw new \RuntimeException(sprintf(
46 1
            "Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s",
47 1
            $serviceName, $serviceType, $region, $urlType
48 1
        ));
49
    }
50
}
51