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 ( 8abfc1...a5d9e7 )
by Yong
04:39
created

EndpointTrait::resolveHostByRule()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 6
nop 1
dl 0
loc 18
ccs 12
cts 12
cp 1
crap 5
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace AlibabaCloud\Client\Traits;
4
5
use AlibabaCloud\Client\AlibabaCloud;
6
use AlibabaCloud\Client\Config\Config;
7
use AlibabaCloud\Client\Request\Request;
8
use AlibabaCloud\Client\Filter\ApiFilter;
9
use AlibabaCloud\Client\Filter\HttpFilter;
10
use AlibabaCloud\Client\Filter\ClientFilter;
11
use AlibabaCloud\Client\Regions\LocationService;
12
use AlibabaCloud\Client\Exception\ClientException;
13
use InvalidArgumentException;
14
15
/**
16
 * Help developers set up and get host.
17
 *
18
 * @package   AlibabaCloud\Client\Traits
19
 *
20
 * @mixin     AlibabaCloud
21
 */
22
trait EndpointTrait
23
{
24
    /**
25
     * @var array Host cache.
26
     */
27
    private static $hosts = [];
28
29
    /**
30
     * Resolve host based on product name and region.
31
     *
32
     * @param string $product
33
     * @param string $regionId
34
     *
35
     * @return string
36
     * @throws ClientException
37
     */
38 59
    public static function resolveHost($product, $regionId = LocationService::GLOBAL_REGION)
39
    {
40 59
        ApiFilter::product($product);
41 56
        ClientFilter::regionId($regionId);
42
43 56
        if (isset(self::$hosts[$product][$regionId])) {
44 2
            return self::$hosts[$product][$regionId];
45
        }
46
47 54
        $domain = Config::get("endpoints.{$product}.{$regionId}");
48 54
        if (!$domain) {
49 3
            $regionId = LocationService::GLOBAL_REGION;
50 3
            $domain   = Config::get("endpoints.{$product}.{$regionId}", '');
51 3
        }
52
53 54
        return $domain;
54
    }
55
56
    /**
57
     * Add host based on product name and region.
58
     *
59
     * @param string $product
60
     * @param string $host
61
     * @param string $regionId
62
     *
63
     * @return void
64
     * @throws ClientException
65
     */
66 8
    public static function addHost($product, $host, $regionId = LocationService::GLOBAL_REGION)
67
    {
68 8
        ApiFilter::product($product);
69
70 6
        HttpFilter::host($host);
71
72 4
        ClientFilter::regionId($regionId);
73
74 2
        self::$hosts[$product][$regionId] = $host;
75
76 2
        LocationService::addHost($product, $host, $regionId);
77 2
    }
78
79
    /**
80
     * @param Request $request
81
     *
82
     * @return string
83
     * @throws ClientException
84
     */
85 3
    public static function resolveHostByRule(Request $request)
86
    {
87 3
        $regionId = $request->realRegionId();
88 3
        $network  = $request->network ?: 'public';
89 3
        $suffix   = $request->endpointSuffix;
90 3
        if ($network === 'public') {
91 3
            $network = '';
92 3
        }
93
94 3
        if ($request->endpointRegional === 'regional') {
95 1
            return "{$request->product}{$suffix}{$network}.{$regionId}.aliyuncs.com";
96
        }
97
98 2
        if ($request->endpointRegional === 'central') {
99 1
            return "{$request->product}{$suffix}{$network}.aliyuncs.com";
100
        }
101
102 1
        throw new InvalidArgumentException('endpointRegional is invalid.');
103
    }
104
}
105