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 ( 407913...68b4fb )
by Yong
04:17
created

AcsTrait::endpointSuffix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AlibabaCloud\Client\Request\Traits;
4
5
use AlibabaCloud\Client\SDK;
6
use AlibabaCloud\Client\AlibabaCloud;
7
use AlibabaCloud\Client\Request\Request;
8
use AlibabaCloud\Client\Filter\ApiFilter;
9
use AlibabaCloud\Client\Regions\LocationService;
10
use AlibabaCloud\Client\Exception\ClientException;
11
use AlibabaCloud\Client\Exception\ServerException;
12
13
/**
14
 * Trait AcsTrait
15
 *
16
 * @package   AlibabaCloud\Client\Request\Traits
17
 *
18
 * @mixin     Request
19
 */
20
trait AcsTrait
21
{
22
    /**
23
     * @var string
24
     */
25
    public $version;
26
27
    /**
28
     * @var string
29
     */
30
    public $product;
31
32
    /**
33
     * @var string
34
     */
35
    public $action;
36
37
    /**
38
     * @var string
39
     */
40
    public $serviceCode = '';
41
42
    /**
43
     * @var string
44
     */
45
    public $endpointType = 'openAPI';
46
47
    /**
48
     * @var string|null
49
     */
50
    public $network = 'public';
51
52
    /**
53
     * @var array|null
54
     */
55
    public $endpointMap;
56
57
    /**
58
     * @var string|null
59
     */
60
    public $endpointRegional;
61
62
    /**
63
     * @var string
64
     */
65
    public $endpointSuffix = '';
66
67
    /**
68
     * @param string $action
69
     *
70
     * @return $this
71
     * @throws ClientException
72
     */
73 70
    public function action($action)
74
    {
75 70
        $this->action = ApiFilter::action($action);
76
77 68
        return $this;
78
    }
79
80
    /**
81
     * @codeCoverageIgnore
82
     *
83
     * @param string $endpointSuffix
84
     *
85
     * @return AcsTrait
86
     * @throws ClientException
87
     */
88
    public function endpointSuffix($endpointSuffix)
89
    {
90
        $this->endpointSuffix = ApiFilter::endpointSuffix($endpointSuffix);
91
92
        return $this;
93
    }
94
95
    /**
96
     * @param string $network
97
     */
98
    public function network($network)
99
    {
100
        $this->network = ApiFilter::network($network);
101
102
        return $this;
103
    }
104
105
    /**
106
     * @param string $version
107
     *
108
     * @return $this
109
     * @throws ClientException
110
     */
111 74
    public function version($version)
112
    {
113 74
        $this->version = ApiFilter::version($version);
114
115 72
        return $this;
116
    }
117
118
    /**
119
     * @param string $product
120
     *
121
     * @return $this
122
     * @throws ClientException
123
     */
124 79
    public function product($product)
125
    {
126 79
        $this->product = ApiFilter::product($product);
127
128 77
        return $this;
129
    }
130
131
    /**
132
     * @param string $endpointType
133
     *
134
     * @return $this
135
     * @throws ClientException
136
     */
137 9
    public function endpointType($endpointType)
138
    {
139 9
        $this->endpointType = ApiFilter::endpointType($endpointType);
140
141 7
        return $this;
142
    }
143
144
    /**
145
     * @param string $serviceCode
146
     *
147
     * @return $this
148
     * @throws ClientException
149
     */
150 11
    public function serviceCode($serviceCode)
151
    {
152 11
        $this->serviceCode = ApiFilter::serviceCode($serviceCode);
153
154 9
        return $this;
155
    }
156
157
    /**
158
     * Resolve Host.
159
     *
160
     * @throws ClientException
161
     * @throws ServerException
162
     */
163 76
    public function resolveHost()
164
    {
165
        // Return if specified
166 76
        if ($this->uri->getHost() !== 'localhost') {
167 25
            return;
168
        }
169
170 57
        $region_id = $this->realRegionId();
171 57
        $host      = '';
172
173
        // 1. Find host by map.
174 57
        if ($this->network === 'public' && isset($this->endpointMap[$region_id])) {
175 1
            $host = $this->endpointMap[$region_id];
176 1
        }
177
178
        // 2. Find host by rules.
179 57
        if (!$host && $this->endpointRegional !== null) {
180 3
            $host = AlibabaCloud::resolveHostByRule($this, $region_id);
0 ignored issues
show
Unused Code introduced by
The call to AlibabaCloud\Client\Alib...ud::resolveHostByRule() has too many arguments starting with $region_id. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

180
            /** @scrutinizer ignore-call */ 
181
            $host = AlibabaCloud::resolveHostByRule($this, $region_id);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
181 2
        }
182
183
        // 3. Find in the local array file.
184 56
        if (!$host) {
185 54
            $host = AlibabaCloud::resolveHost($this->product, $region_id);
186 51
        }
187
188
        // 4. Find in the Location service.
189 53
        if (!$host && $this->serviceCode) {
190 2
            $host = LocationService::resolveHost($this);
191 2
        }
192
193 53
        if (!$host) {
194 1
            throw new ClientException(
195 1
                "No host found for {$this->product} in the {$region_id}, you can specify host by host() method. " .
196 1
                'Like $request->host(\'xxx.xxx.aliyuncs.com\')',
197
                SDK::HOST_NOT_FOUND
198 1
            );
199
        }
200
201 52
        $this->uri = $this->uri->withHost($host);
0 ignored issues
show
Bug Best Practice introduced by
The property uri does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
202 52
    }
203
204
    /**
205
     * @return string
206
     * @throws ClientException
207
     */
208 96
    public function realRegionId()
209
    {
210 96
        if ($this->regionId !== null) {
211 40
            return $this->regionId;
212
        }
213
214 64
        if ($this->httpClient()->regionId !== null) {
0 ignored issues
show
Bug introduced by
It seems like httpClient() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

214
        if ($this->/** @scrutinizer ignore-call */ httpClient()->regionId !== null) {
Loading history...
215 59
            return $this->httpClient()->regionId;
216
        }
217
218 5
        if (AlibabaCloud::getDefaultRegionId() !== null) {
219 4
            return AlibabaCloud::getDefaultRegionId();
220
        }
221
222 1
        throw new ClientException("Missing required 'RegionId' for Request", SDK::INVALID_REGION_ID);
223
    }
224
}
225