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

LoadBalancerPool::getAliases()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace OpenStack\Networking\v2\Models;
4
5
use OpenStack\Common\Resource\Alias;
6
use OpenStack\Common\Resource\Creatable;
7
use OpenStack\Common\Resource\Deletable;
8
use OpenStack\Common\Resource\OperatorResource;
9
use OpenStack\Common\Resource\Retrievable;
10
use OpenStack\Common\Resource\Updateable;
11
use OpenStack\Networking\v2\Api;
12
13
/**
14
 * Represents a Neutron v2 LoadBalancer pool
15
 *
16
 * @property Api $api
17
 */
18
class LoadBalancerPool extends OperatorResource implements Creatable, Retrievable, Updateable, Deletable
19
{
20
    /**
21
     * @var string
22
     */
23
    public $name;
24
25
    /**
26
     * @var string
27
     */
28
    public $description;
29
30
    /**
31
     * @var string
32
     */
33
    public $id;
34
35
    /**
36
     * @var string
37
     */
38
    public $tenantId;
39
40
    /**
41
     * @var string
42
     */
43
    public $protocol;
44
45
    /**
46
     * @var string
47
     */
48
    public $lbAlgorithm;
49
50
    /**
51
     * @var array
52
     */
53
    public $sessionPersistence;
54
55
    /**
56
     * @var boolean
57
     */
58
    public $adminStateUp;
59
60
    /**
61
     * @var LoadBalancerListener[]
62
     */
63
    public $listeners;
64
65
    /**
66
     * @var LoadBalancerMember[]
67
     */
68
    public $members;
69
70
    /**
71
     * @var LoadBalancerHealthMonitor[]
72
     */
73
    public $healthmonitors;
74
75
    /**
76
     * @var string
77
     */
78
    public $healthmonitorId;
79
80
    /**
81
     * @var string
82
     */
83
    public $operatingStatus;
84
85
    /**
86
     * @var string
87
     */
88
    public $provisioningStatus;
89
90
    protected $resourcesKey = 'pools';
91
    protected $resourceKey = 'pool';
92
93
    protected $aliases = [
94
        'tenant_id'           => 'tenantId',
95
        'admin_state_up'      => 'adminStateUp',
96
        'lb_algorithm'        => 'lbAlgorithm',
97
        'session_persistence' => 'sessionPersistence',
98
        'healthmonitor_id'    => 'healthmonitorId',
99
        'loadbalancer_id'     => 'loadbalancerId',
100
        'operating_status'    => 'operatingStatus',
101
        'provisioning_status' => 'provisioningStatus',
102
    ];
103
104
    /**
105
     * @inheritdoc
106
     */
107
    protected function getAliases(): array
108
    {
109
        return parent::getAliases() + [
110
            'listeners'      => new Alias('listeners', LoadBalancerListener::class, true),
111
            'members'        => new Alias('members', LoadBalancerMember::class, true),
112
            'healthmonitors' => new Alias('healthmonitors', LoadBalancerHealthMonitor::class, true)
113
        ];
114
    }
115
116
    /**
117
     * {@inheritDoc}
118
     */
119
    public function create(array $userOptions): Creatable
120
    {
121
        $response = $this->execute($this->api->postLoadBalancerPool(), $userOptions);
122
        return $this->populateFromResponse($response);
123
    }
124
125
    /**
126
     * {@inheritDoc}
127
     */
128
    public function retrieve()
129
    {
130
        $response = $this->execute($this->api->getLoadBalancerPool(), ['id' => (string)$this->id]);
131
        $this->populateFromResponse($response);
132
    }
133
134
    /**
135
     * {@inheritDoc}
136
     */
137
    public function update()
138
    {
139
        $response = $this->executeWithState($this->api->putLoadBalancerPool());
140
        $this->populateFromResponse($response);
141
    }
142
143
    /**
144
     * {@inheritDoc}
145
     */
146
    public function delete()
147
    {
148
        $this->executeWithState($this->api->deleteLoadBalancerPool());
149
    }
150
151
    /**
152
     * Add a member to this pool
153
     *
154
     * @param array $userOptions
155
     */
156
    public function addMember(array $userOptions = []): LoadBalancerMember
157
    {
158
        $userOptions = array_merge(['poolId' => $this->id], $userOptions);
159
        return $this->model(LoadBalancerMember::class)->create($userOptions);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface OpenStack\Common\Resource\ResourceInterface as the method create() does only exist in the following implementations of said interface: OpenStack\BlockStorage\v2\Models\Snapshot, OpenStack\BlockStorage\v2\Models\Volume, OpenStack\BlockStorage\v2\Models\VolumeType, OpenStack\Compute\v2\Models\Flavor, OpenStack\Compute\v2\Models\Keypair, OpenStack\Compute\v2\Models\Server, OpenStack\Identity\v3\Models\Credential, OpenStack\Identity\v3\Models\Domain, OpenStack\Identity\v3\Models\Endpoint, OpenStack\Identity\v3\Models\Group, OpenStack\Identity\v3\Models\Policy, OpenStack\Identity\v3\Models\Project, OpenStack\Identity\v3\Models\Role, OpenStack\Identity\v3\Models\Service, OpenStack\Identity\v3\Models\Token, OpenStack\Identity\v3\Models\User, OpenStack\Images\v2\Models\Image, OpenStack\Images\v2\Models\Member, OpenStack\Networking\v2\...ayer3\Models\FloatingIp, OpenStack\Networking\v2\...ns\Layer3\Models\Router, OpenStack\Networking\v2\...ps\Models\SecurityGroup, OpenStack\Networking\v2\...odels\SecurityGroupRule, OpenStack\Networking\v2\Models\LoadBalancer, OpenStack\Networking\v2\...adBalancerHealthMonitor, OpenStack\Networking\v2\...ls\LoadBalancerListener, OpenStack\Networking\v2\Models\LoadBalancerMember, OpenStack\Networking\v2\Models\LoadBalancerPool, OpenStack\Networking\v2\Models\Network, OpenStack\Networking\v2\Models\Port, OpenStack\Networking\v2\Models\Subnet, OpenStack\ObjectStore\v1\Models\Container, OpenStack\ObjectStore\v1\Models\Object.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
160
    }
161
162
    /**
163
     * Get an instance of a member
164
     *
165
     * @param string $memberId
166
     * @return LoadBalancerMember
167
     */
168
    public function getMember(string $memberId): LoadBalancerMember
169
    {
170
        return $this->model(LoadBalancerMember::class, ['poolId' => $this->id, 'id' => $memberId]);
171
    }
172
173
    /**
174
     * Delete a member
175
     *
176
     * @param string $memberId
177
     */
178
    public function deleteMember(string $memberId)
179
    {
180
        $this->model(LoadBalancerMember::class, ['poolId' => $this->id, 'id' => $memberId])->delete();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface OpenStack\Common\Resource\ResourceInterface as the method delete() does only exist in the following implementations of said interface: OpenStack\BlockStorage\v2\Models\QuotaSet, OpenStack\BlockStorage\v2\Models\Snapshot, OpenStack\BlockStorage\v2\Models\Volume, OpenStack\BlockStorage\v2\Models\VolumeType, OpenStack\Compute\v2\Models\Flavor, OpenStack\Compute\v2\Models\Image, OpenStack\Compute\v2\Models\Keypair, OpenStack\Compute\v2\Models\QuotaSet, OpenStack\Compute\v2\Models\Server, OpenStack\Identity\v3\Models\Credential, OpenStack\Identity\v3\Models\Domain, OpenStack\Identity\v3\Models\Endpoint, OpenStack\Identity\v3\Models\Group, OpenStack\Identity\v3\Models\Policy, OpenStack\Identity\v3\Models\Project, OpenStack\Identity\v3\Models\Role, OpenStack\Identity\v3\Models\Service, OpenStack\Identity\v3\Models\User, OpenStack\Images\v2\Models\Image, OpenStack\Images\v2\Models\Member, OpenStack\Networking\v2\...ayer3\Models\FloatingIp, OpenStack\Networking\v2\...ns\Layer3\Models\Router, OpenStack\Networking\v2\...ps\Models\SecurityGroup, OpenStack\Networking\v2\...odels\SecurityGroupRule, OpenStack\Networking\v2\Models\LoadBalancer, OpenStack\Networking\v2\...adBalancerHealthMonitor, OpenStack\Networking\v2\...ls\LoadBalancerListener, OpenStack\Networking\v2\Models\LoadBalancerMember, OpenStack\Networking\v2\Models\LoadBalancerPool, OpenStack\Networking\v2\Models\Network, OpenStack\Networking\v2\Models\Port, OpenStack\Networking\v2\Models\Quota, OpenStack\Networking\v2\Models\Subnet, OpenStack\ObjectStore\v1\Models\Container, OpenStack\ObjectStore\v1\Models\Object.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
181
    }
182
183
    /**
184
     * Add a healthmonitor to this load balancer pool
185
     *
186
     * @param array $userOptions
187
     * @return LoadBalancerHealthMonitor
188
     */
189
    public function addHealthMonitor(array $userOptions = []): LoadBalancerHealthMonitor
190
    {
191
        $userOptions = array_merge(['poolId' => $this->id], $userOptions);
192
        return $this->model(LoadBalancerHealthMonitor::class)->create($userOptions);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface OpenStack\Common\Resource\ResourceInterface as the method create() does only exist in the following implementations of said interface: OpenStack\BlockStorage\v2\Models\Snapshot, OpenStack\BlockStorage\v2\Models\Volume, OpenStack\BlockStorage\v2\Models\VolumeType, OpenStack\Compute\v2\Models\Flavor, OpenStack\Compute\v2\Models\Keypair, OpenStack\Compute\v2\Models\Server, OpenStack\Identity\v3\Models\Credential, OpenStack\Identity\v3\Models\Domain, OpenStack\Identity\v3\Models\Endpoint, OpenStack\Identity\v3\Models\Group, OpenStack\Identity\v3\Models\Policy, OpenStack\Identity\v3\Models\Project, OpenStack\Identity\v3\Models\Role, OpenStack\Identity\v3\Models\Service, OpenStack\Identity\v3\Models\Token, OpenStack\Identity\v3\Models\User, OpenStack\Images\v2\Models\Image, OpenStack\Images\v2\Models\Member, OpenStack\Networking\v2\...ayer3\Models\FloatingIp, OpenStack\Networking\v2\...ns\Layer3\Models\Router, OpenStack\Networking\v2\...ps\Models\SecurityGroup, OpenStack\Networking\v2\...odels\SecurityGroupRule, OpenStack\Networking\v2\Models\LoadBalancer, OpenStack\Networking\v2\...adBalancerHealthMonitor, OpenStack\Networking\v2\...ls\LoadBalancerListener, OpenStack\Networking\v2\Models\LoadBalancerMember, OpenStack\Networking\v2\Models\LoadBalancerPool, OpenStack\Networking\v2\Models\Network, OpenStack\Networking\v2\Models\Port, OpenStack\Networking\v2\Models\Subnet, OpenStack\ObjectStore\v1\Models\Container, OpenStack\ObjectStore\v1\Models\Object.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
193
    }
194
}
195