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 (#136)
by Frank
02:07 queued 10s
created

LoadbalancerPool::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace OpenStack\Networking\v2\Models;
4
5
use OpenStack\Common\Resource\Creatable;
6
use OpenStack\Common\Resource\Deletable;
7
use OpenStack\Common\Resource\OperatorResource;
8
use OpenStack\Common\Resource\Retrievable;
9
use OpenStack\Common\Resource\Updateable;
10
use OpenStack\Networking\v2\Api;
11
12
/**
13
 * Represents a Neutron v2 Loadbalancer pool
14
 *
15
 * @property Api $api
16
 */
17
class LoadbalancerPool extends OperatorResource implements Creatable, Retrievable, Updateable, Deletable
18
{
19
    /**
20
     * @var string
21
     */
22
    public $name;
23
24
    /**
25
     * @var string
26
     */
27
    public $description;
28
29
    /**
30
     * @var string
31
     */
32
    public $id;
33
34
    /**
35
     * @var string
36
     */
37
    public $tenantId;
38
39
    /**
40
     * @var string
41
     */
42
    public $protocol;
43
44
    /**
45
     * @var string
46
     */
47
    public $lbAlgorithm;
48
49
    /**
50
     * @var array
51
     */
52
    public $sessionPersistence;
53
54
    /**
55
     * @var boolean
56
     */
57
    public $adminStateUp;
58
59
    /**
60
     * @var []LoadbalancerListener
61
     */
62
    public $listeners;
63
64
    /**
65
     * @var []LoadbalancerMember
66
     */
67
    public $members;
68
69
    /**
70
     * @var []LoadbalancerHealthmonitor
71
     */
72
    public $healthmonitors;
73
74
    /**
75
     * @var string
76
     */
77
    public $healthmonitorId;
78
79
    /**
80
     * @var string
81
     */
82
    public $operatingStatus;
83
84
    /**
85
     * @var string
86
     */
87
    public $provisioningStatus;
88
89
    protected $resourcesKey = 'pools';
90
    protected $resourceKey = 'pool';
91
92
    protected $aliases = [
93
        'tenant_id'           => 'tenantId',
94
        'admin_state_up'      => 'adminStateUp',
95
        'lb_algorithm'        => 'lbAlgorithm',
96
        'session_persistence' => 'sessionPersistence',
97
        'healthmonitor_id'    => 'healthmonitorId',
98
        'loadbalancer_id'     => 'loadbalancerId',
99
        'operating_status'    => 'operatingStatus',
100
        'provisioning_status' => 'provisioningStatus'
101
    ];
102
103
    /**
104
     * {@inheritDoc}
105
     */
106
    public function create(array $userOptions): Creatable
107
    {
108
        $response = $this->execute($this->api->postLoadbalancerPool(), $userOptions);
109
        return $this->populateFromResponse($response);
110
    }
111
112
    /**
113
     * {@inheritDoc}
114
     */
115
    public function retrieve()
116
    {
117
        $response = $this->execute($this->api->getLoadbalancerPool(), ['id' => (string)$this->id]);
118
        $this->populateFromResponse($response);
119
    }
120
121
    /**
122
     * {@inheritDoc}
123
     */
124
    public function update()
125
    {
126
        $response = $this->executeWithState($this->api->putLoadbalancerPool());
127
        $this->populateFromResponse($response);
128
    }
129
130
    /**
131
     * {@inheritDoc}
132
     */
133
    public function delete()
134
    {
135
        $this->executeWithState($this->api->deleteLoadbalancerPool());
136
    }
137
138
    /**
139
     * Add a member to this pool
140
     *
141
     * @param array $userOptions
142
     */
143
    public function addMember(array $userOptions = []): LoadbalancerMember
144
    {
145
        $userOptions = array_merge(['poolId' => $this->id], $userOptions);
146
        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...
147
    }
148
149
    /**
150
     * Get an instance of a member
151
     *
152
     * @param string $member_id
153
     * @return LoadbalancerMember
154
     */
155
    public function getMember(string $member_id): LoadbalancerMember
156
    {
157
        return $this->model(LoadbalancerMember::class, ['poolId' => $this->id, 'id' => $member_id]);
158
    }
159
160
    /**
161
     * Delete a member
162
     *
163
     * @param string $member_id
164
     */
165
    public function deleteMember(string $member_id)
166
    {
167
        $this->model(LoadbalancerMember::class, ['poolId' => $this->id, 'id' => $member_id])->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...
168
    }
169
170
    /**
171
     * Add a healthmonitor to this load balancer pool
172
     *
173
     * @param array $userOptions
174
     * @return LoadbalancerHealthmonitor
175
     */
176
    public function addHealthmonitor(array $userOptions = []): LoadbalancerHealthmonitor
177
    {
178
        $userOptions = array_merge(['poolId' => $this->id], $userOptions);
179
        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...
180
    }
181
}
182