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