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