Total Complexity | 12 |
Total Lines | 63 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | class Config |
||
6 | { |
||
7 | /** @var string */ |
||
8 | private $preset; |
||
9 | |||
10 | 14 | public function __construct($preset) |
|
21 | 12 | } |
|
22 | |||
23 | 12 | private function getConfig(string $key, $default) |
|
24 | { |
||
25 | 12 | return config('db-rebuild.presets.' . $this->preset . '.' . $key, $default); |
|
26 | } |
||
27 | |||
28 | 9 | private function getArrayConfig(string $key, array $default = []): array |
|
29 | { |
||
30 | 9 | $data = $this->getConfig($key, $default); |
|
31 | |||
32 | 9 | if (\is_array($data)) { |
|
33 | 8 | return $data; |
|
34 | } |
||
35 | |||
36 | 3 | throw new \RuntimeException("db-rebuild.presets.{$this->preset}.{$key} should be an array"); |
|
37 | } |
||
38 | |||
39 | 12 | private function getStringConfig(string $key, string $default): string |
|
40 | { |
||
41 | 12 | $data = $this->getConfig($key, $default); |
|
42 | |||
43 | 12 | if (\is_string($data)) { |
|
44 | 11 | return $data; |
|
45 | } |
||
46 | |||
47 | 1 | throw new \RuntimeException("db-rebuild.presets.{$this->preset}.{$key} should be a string"); |
|
48 | } |
||
49 | |||
50 | 12 | public function getDatabase(): string |
|
51 | { |
||
52 | 12 | return $this->getStringConfig('database', config('database.connections.' . config('database.default') . '.database')); |
|
53 | } |
||
54 | |||
55 | 8 | public function getCommands(): array |
|
56 | { |
||
57 | 8 | return $this->getArrayConfig('commands'); |
|
58 | } |
||
59 | |||
60 | 9 | public function getBackup(): array |
|
61 | { |
||
62 | 9 | return $this->getArrayConfig('backup'); |
|
63 | } |
||
64 | |||
65 | 7 | public function getSeeds(): array |
|
68 | } |
||
69 | } |
||
70 |