ClientConfig   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 11
c 1
b 0
f 0
dl 0
loc 46
ccs 18
cts 18
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setLanguage() 0 3 1
A getLanguage() 0 3 1
A init() 0 10 6
A getApiKey() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
namespace kalanis\google_maps;
4
5
6
/**
7
 * Configuration class
8
 */
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
53
    {
54 2
        $this->language = $language;
55
    }
56
}
57