Total Complexity | 7 |
Total Lines | 68 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
9 | class Config |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $baseUrl; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $version; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $apiKey; |
||
25 | |||
26 | 6 | protected function __construct(string $baseUrl, string $version, string $apiKey) |
|
31 | 6 | } |
|
32 | |||
33 | 2 | public static function fromEnvironment(): self |
|
34 | { |
||
35 | 2 | $baseUrl = getenv('AIRTABLE_BASE_URL'); |
|
36 | 2 | $version = getenv('AIRTABLE_API_VERSION'); |
|
37 | 2 | $apiKey = getenv('AIRTABLE_API_KEY'); |
|
38 | |||
39 | 2 | return self::fromValues($baseUrl, $version, $apiKey); |
|
40 | } |
||
41 | |||
42 | 10 | public static function fromValues(string $baseUrl, string $version, string $apiKey): self |
|
47 | } |
||
48 | |||
49 | 10 | protected static function validateValues(string $baseUrl, string $version, string $apiKey): bool |
|
50 | { |
||
51 | 10 | Assert::that($baseUrl) |
|
52 | 10 | ->notBlank('baseUrl was blank/empty') |
|
53 | 9 | ->url('baseUrl was not a valid url'); |
|
54 | |||
55 | 8 | Assert::that($version) |
|
56 | 8 | ->regex('/v\d+/', 'Version did not match expected pattern'); |
|
57 | |||
58 | 7 | Assert::that($apiKey) |
|
59 | 7 | ->notBlank('apiKey was blank/empty'); |
|
60 | |||
61 | 6 | return true; |
|
62 | } |
||
63 | |||
64 | 6 | public function getBaseUrl(): string |
|
67 | } |
||
68 | |||
69 | 6 | public function getVersion(): string |
|
70 | { |
||
71 | 6 | return $this->version; |
|
72 | } |
||
73 | |||
74 | 6 | public function getApiKey(): string |
|
77 | } |
||
78 | } |
||
79 |