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
Push — master ( a6e2fd...77480b )
by Jamie
12s
created

Service::getAliases()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace OpenStack\Identity\v3\Models;
4
5
use OpenStack\Common\Resource\Alias;
6
use OpenStack\Common\Resource\OperatorResource;
7
use OpenStack\Common\Resource\Creatable;
8
use OpenStack\Common\Resource\Deletable;
9
use OpenStack\Common\Resource\Listable;
10
use OpenStack\Common\Resource\Retrievable;
11
use OpenStack\Common\Resource\Updateable;
12
13
/**
14
 * @property \OpenStack\Identity\v3\Api $api
15
 */
16
class Service extends OperatorResource implements Creatable, Listable, Retrievable, Updateable, Deletable
17
{
18
    /** @var string */
19
    public $id;
20
21
    /** @var string */
22
    public $name;
23
24
    /** @var string */
25
    public $type;
26
27
    /** @var string */
28
    public $description;
29
30
    /** @var []Endpoint */
31
    public $endpoints;
32
33
    /** @var array */
34
    public $links;
35
36
    protected $resourceKey = 'service';
37
    protected $resourcesKey = 'services';
38
39
    /**
40
     * @inheritdoc
41
     */
42
    protected function getAliases(): array
43 1
    {
44
        return parent::getAliases() + [
45 1
            'endpoints' => new Alias('endpoints', Endpoint::class, true)
46 1
        ];
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     *
52 1
     * @param array $data {@see \OpenStack\Identity\v3\Api::postServices}
53
     */
54 1
    public function create(array $data): Creatable
55 1
    {
56
        $response = $this->execute($this->api->postServices(), $data);
57
        return $this->populateFromResponse($response);
58
    }
59
60
    /**
61 1
     * {@inheritDoc}
62
     */
63 1
    public function retrieve()
64 1
    {
65
        $response = $this->executeWithState($this->api->getService());
66
        $this->populateFromResponse($response);
67
    }
68
69
    /**
70 1
     * {@inheritDoc}
71
     */
72 1
    public function update()
73 1
    {
74
        $response = $this->executeWithState($this->api->patchService());
75 4
        $this->populateFromResponse($response);
76
    }
77 4
78
    /**
79
     * {@inheritDoc}
80 2
     */
81
    public function delete()
82 2
    {
83
        $this->executeWithState($this->api->deleteService());
84
    }
85
86
    private function nameMatches(string $value): bool
87
    {
88
        return $this->name && $this->name == $value;
89
    }
90
91
    private function typeMatches(string $value): bool
92
    {
93
        return $this->type && $this->type = $value;
94
    }
95 4
96
    /**
97 4
     * Retrieve the base URL for a service.
98 2
     *
99
     * @param string $name      The name of the service as it appears in the catalog.
100
     * @param string $type      The type of the service as it appears in the catalog.
101 2
     * @param string $region    The region of the service as it appears in the catalog.
102 2
     * @param string $interface The interface of the service as it appears in the catalog.
103 2
     *
104
     * @return string|false
105 1
     */
106
    public function getUrl(string $name, string $type, string $region, string $interface)
107 1
    {
108
        if (!$this->nameMatches($name) || !$this->typeMatches($type)) {
109
            return false;
110
        }
111
112
        foreach ($this->endpoints as $endpoint) {
113
            if ($endpoint->regionMatches($region) && $endpoint->interfaceMatches($interface)) {
114
                return $endpoint->url;
115
            }
116
        }
117
118
        return false;
119
    }
120
}
121