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:49
created

Service   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 110
Duplicated Lines 10 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 16
c 0
b 0
f 0
lcom 2
cbo 2
dl 11
loc 110
rs 10
ccs 24
cts 24
cp 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getAlias() 11 11 2
A create() 0 5 1
A retrieve() 0 5 1
A update() 0 5 1
A delete() 0 4 1
A nameMatches() 0 4 2
A typeMatches() 0 4 2
B getUrl() 0 14 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
    protected static function getAlias(): Alias
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43 1
    {
44
        $alias = parent::getAlias();
45 1
46 1
        if (!$alias->hasAliases(self::class)) {
47
            $alias
48
                ->add(self::class, 'endpoints', 'endpoints', Endpoint::class, true);
49
        }
50
51
        return $alias;
52 1
    }
53
54 1
    /**
55 1
     * {@inheritDoc}
56
     *
57
     * @param array $data {@see \OpenStack\Identity\v3\Api::postServices}
58
     */
59
    public function create(array $data): Creatable
60
    {
61 1
        $response = $this->execute($this->api->postServices(), $data);
62
        return $this->populateFromResponse($response);
63 1
    }
64 1
65
    /**
66
     * {@inheritDoc}
67
     */
68
    public function retrieve()
69
    {
70 1
        $response = $this->executeWithState($this->api->getService());
71
        $this->populateFromResponse($response);
72 1
    }
73 1
74
    /**
75 4
     * {@inheritDoc}
76
     */
77 4
    public function update()
78
    {
79
        $response = $this->executeWithState($this->api->patchService());
80 2
        $this->populateFromResponse($response);
81
    }
82 2
83
    /**
84
     * {@inheritDoc}
85
     */
86
    public function delete()
87
    {
88
        $this->executeWithState($this->api->deleteService());
89
    }
90
91
    private function nameMatches(string $value): bool
92
    {
93
        return $this->name && $this->name == $value;
94
    }
95 4
96
    private function typeMatches(string $value): bool
97 4
    {
98 2
        return $this->type && $this->type = $value;
99
    }
100
101 2
    /**
102 2
     * Retrieve the base URL for a service.
103 2
     *
104
     * @param string $name      The name of the service as it appears in the catalog.
105 1
     * @param string $type      The type of the service as it appears in the catalog.
106
     * @param string $region    The region of the service as it appears in the catalog.
107 1
     * @param string $interface The interface of the service as it appears in the catalog.
108
     *
109
     * @return string|false
110
     */
111
    public function getUrl(string $name, string $type, string $region, string $interface)
112
    {
113
        if (!$this->nameMatches($name) || !$this->typeMatches($type)) {
114
            return false;
115
        }
116
117
        foreach ($this->endpoints as $endpoint) {
118
            if ($endpoint->regionMatches($region) && $endpoint->interfaceMatches($interface)) {
119
                return $endpoint->url;
120
            }
121
        }
122
123
        return false;
124
    }
125
}
126