Total Complexity | 8 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | class ApplicationEnv |
||
12 | { |
||
13 | protected string $env; |
||
14 | |||
15 | /** |
||
16 | * ApplicationEnv constructor. |
||
17 | */ |
||
18 | 12 | public function __construct(string $env) |
|
19 | { |
||
20 | 12 | $this->env = $env; |
|
21 | } |
||
22 | |||
23 | /** |
||
24 | * Cast object to a string |
||
25 | */ |
||
26 | 1 | public function __toString(): string |
|
27 | { |
||
28 | 1 | return $this->env; |
|
29 | } |
||
30 | |||
31 | |||
32 | /** |
||
33 | * Check if environment matches or is a parent. |
||
34 | */ |
||
35 | 1 | public function is(string $env): bool |
|
36 | { |
||
37 | 1 | return $this->env === $env || str_starts_with($this->env, "$env."); |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * Traverse through each level of the application env. |
||
42 | * |
||
43 | * @return array<mixed> |
||
44 | */ |
||
45 | 10 | public function getLevels(int $from = 1, ?int $to = null, ?callable $callback = null): array |
|
58 | } |
||
59 | } |
||
60 |