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
Pull Request — master (#185)
by Yong
03:45
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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
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 $version
97
     *
98
     * @return $this
99
     * @throws ClientException
100
     */
101 74
    public function version($version)
102
    {
103 74
        $this->version = ApiFilter::version($version);
104
105 72
        return $this;
106
    }
107
108
    /**
109
     * @param string $product
110
     *
111
     * @return $this
112
     * @throws ClientException
113
     */
114 79
    public function product($product)
115
    {
116 79
        $this->product = ApiFilter::product($product);
117
118 77
        return $this;
119
    }
120
121
    /**
122
     * @param string $endpointType
123
     *
124
     * @return $this
125
     * @throws ClientException
126
     */
127 9
    public function endpointType($endpointType)
128
    {
129 9
        $this->endpointType = ApiFilter::endpointType($endpointType);
130
131 7
        return $this;
132
    }
133
134
    /**
135
     * @param string $serviceCode
136
     *
137
     * @return $this
138
     * @throws ClientException
139
     */
140 11
    public function serviceCode($serviceCode)
141
    {
142 11
        $this->serviceCode = ApiFilter::serviceCode($serviceCode);
143
144 9
        return $this;
145
    }
146
147
    /**
148
     * Resolve Host.
149
     *
150
     * @throws ClientException
151
     * @throws ServerException
152
     */
153 76
    public function resolveHost()
154
    {
155
        // Return if specified
156 76
        if ($this->uri->getHost() !== 'localhost') {
157 25
            return;
158
        }
159
160 57
        $region_id = $this->realRegionId();
161 57
        $host      = '';
162
163
        // 1. Find host by map.
164 57
        if ($this->network === 'public' && isset($this->endpointMap[$region_id])) {
165 1
            $host = $this->endpointMap[$region_id];
166 1
        }
167
168
        // 2. Find host by rules.
169 57
        if (!$host && $this->endpointRegional !== null) {
170 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

170
            /** @scrutinizer ignore-call */ 
171
            $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...
171 2
        }
172
173
        // 3. Find in the local array file.
174 56
        if (!$host) {
175 54
            $host = AlibabaCloud::resolveHost($this->product, $region_id);
176 51
        }
177
178
        // 4. Find in the Location service.
179 53
        if (!$host && $this->serviceCode) {
180 2
            $host = LocationService::resolveHost($this);
181 2
        }
182
183 53
        if (!$host) {
184 1
            throw new ClientException(
185 1
                "No host found for {$this->product} in the {$region_id}, you can specify host by host() method. " .
186 1
                'Like $request->host(\'xxx.xxx.aliyuncs.com\')',
187
                SDK::HOST_NOT_FOUND
188 1
            );
189
        }
190
191 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...
192 52
    }
193
194
    /**
195
     * @return string
196
     * @throws ClientException
197
     */
198 96
    public function realRegionId()
199
    {
200 96
        if ($this->regionId !== null) {
201 40
            return $this->regionId;
202
        }
203
204 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

204
        if ($this->/** @scrutinizer ignore-call */ httpClient()->regionId !== null) {
Loading history...
205 59
            return $this->httpClient()->regionId;
206
        }
207
208 5
        if (AlibabaCloud::getDefaultRegionId() !== null) {
209 4
            return AlibabaCloud::getDefaultRegionId();
210
        }
211
212 1
        throw new ClientException("Missing required 'RegionId' for Request", SDK::INVALID_REGION_ID);
213
    }
214
}
215