Total Complexity | 7 |
Total Lines | 74 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
7 | class VersionResolver |
||
8 | { |
||
9 | /** |
||
10 | * @var bool |
||
11 | */ |
||
12 | protected $static = false; |
||
13 | |||
14 | /** |
||
15 | * Version Resolver constructor. |
||
16 | * |
||
17 | * @param bool $static |
||
18 | */ |
||
19 | 86 | public function __construct($static = false) |
|
20 | { |
||
21 | 86 | $this->static = $static; |
|
22 | 86 | } |
|
23 | |||
24 | /** |
||
25 | * @param string $name |
||
26 | * @param array $arguments |
||
27 | * |
||
28 | * @return mixed |
||
29 | */ |
||
30 | 1 | public static function __callStatic($name, $arguments) |
|
31 | { |
||
32 | 1 | return (new static(true))->__call($name, $arguments); |
|
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param string $version |
||
37 | * @param array $arguments |
||
38 | * |
||
39 | * @return mixed |
||
40 | * @throws ClientException |
||
41 | */ |
||
42 | 84 | public function __call($version, $arguments) |
|
43 | { |
||
44 | 84 | $serviceName = $this->getServiceName(\get_class($this)); |
|
45 | |||
46 | 84 | $version = \ucfirst($version); |
|
47 | |||
48 | 84 | if ($this->static === true) { |
|
49 | 1 | $serviceName = \str_replace('Version', '', $serviceName); |
|
50 | 1 | } |
|
51 | |||
52 | 84 | $class = "AlibabaCloud\\{$serviceName}\\$version\\{$serviceName}ApiResolver"; |
|
53 | |||
54 | 84 | if (\class_exists($class)) { |
|
55 | 83 | return new $class(); |
|
56 | } |
||
57 | |||
58 | 1 | throw new ClientException( |
|
59 | 1 | "$serviceName Versions contains no {$version}", |
|
60 | 'SDK.VersionNotFound' |
||
61 | 1 | ); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * @param string $class |
||
66 | * |
||
67 | * @return mixed |
||
68 | * @throws ClientException |
||
69 | */ |
||
70 | 86 | protected function getServiceName($class) |
|
81 | 1 | ); |
|
82 | } |
||
83 | } |
||
84 |