Total Complexity | 5 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | class Client |
||
20 | { |
||
21 | private const MODELS_MAP = [ |
||
22 | 'address' => Address::class |
||
23 | ]; |
||
24 | |||
25 | private string $apiKey; |
||
26 | private Connection $connection; |
||
27 | |||
28 | /** |
||
29 | * @param string $apiKey |
||
30 | */ |
||
31 | 2 | public function __construct(string $apiKey) |
|
34 | } |
||
35 | |||
36 | 2 | public function __get(string $property): ModelInterface |
|
37 | { |
||
38 | 2 | if (!array_key_exists($property, self::MODELS_MAP)) { |
|
39 | 1 | throw new Exception(sprintf('Model `%s` not supported by Nova Poshta API Client', $property)); |
|
40 | } |
||
41 | 1 | $class = self::MODELS_MAP[$property]; |
|
42 | 1 | $this->$property = new $class($this->getConnection()); |
|
43 | 1 | return $this->$property; |
|
44 | } |
||
45 | |||
46 | 1 | private function getConnection(): Connection |
|
52 | } |
||
53 | } |
||
54 |