| Total Complexity | 10 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class ClientConfig |
||
| 10 | { |
||
| 11 | 62 | public function __construct( |
|
| 12 | protected readonly string $apiKey, |
||
| 13 | protected string|null $language = null, |
||
| 14 | ) |
||
| 15 | { |
||
| 16 | 62 | } |
|
| 17 | |||
| 18 | /** |
||
| 19 | * Initialize configuration |
||
| 20 | * @param string|array{ |
||
| 21 | * key: string, |
||
| 22 | * language: string|null, |
||
| 23 | * } $optParams |
||
| 24 | * key: Google API Key, |
||
| 25 | * language: Default language |
||
| 26 | * @throws ServiceException |
||
| 27 | * @return self |
||
| 28 | */ |
||
| 29 | 47 | public static function init(string|array $optParams): ClientConfig |
|
| 30 | { |
||
| 31 | 47 | return new self( |
|
| 32 | 47 | is_array($optParams) && (isset($optParams['key'])) |
|
| 33 | 2 | ? strval($optParams['key']) |
|
| 34 | 45 | : (is_string($optParams) |
|
| 35 | 44 | ? $optParams |
|
| 36 | 47 | : throw new ServiceException('Unable to set Client credential due to your wrong params', 400) |
|
| 37 | 47 | ), |
|
| 38 | 47 | is_array($optParams) && (isset($optParams['language'])) ? strval($optParams['language']) : null, |
|
| 39 | 47 | ); |
|
| 40 | } |
||
| 41 | |||
| 42 | 43 | public function getApiKey(): string |
|
| 43 | { |
||
| 44 | 43 | return $this->apiKey; |
|
| 45 | } |
||
| 46 | |||
| 47 | 41 | public function getLanguage(): ?string |
|
| 48 | { |
||
| 49 | 41 | return $this->language; |
|
| 50 | } |
||
| 51 | |||
| 52 | 2 | public function setLanguage(?string $language): void |
|
| 55 | } |
||
| 56 | } |
||
| 57 |