| Conditions | 3 |
| Paths | 3 |
| Total Lines | 23 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | protected function persistConfig(string $configKey, ?string $value): void |
||
| 8 | { |
||
| 9 | $this->laravel->make('config')->set([$configKey => $value]); |
||
| 10 | |||
| 11 | if ($this->option('no-write')) { |
||
|
|
|||
| 12 | return; |
||
| 13 | } |
||
| 14 | |||
| 15 | $envPath = app()->basePath('.env'); |
||
| 16 | |||
| 17 | $envKey = strtoupper(preg_replace('/[^A-Za-z0-9]+/', '_', $configKey)); |
||
| 18 | |||
| 19 | $pattern = '/^'.preg_quote($envKey, '/').'=["\']?.*/m'; |
||
| 20 | |||
| 21 | $contents = file_get_contents($envPath); |
||
| 22 | |||
| 23 | if (preg_match($pattern, $contents)) { |
||
| 24 | $contents = preg_replace($pattern, "{$envKey}=\"{$value}\"", $contents); |
||
| 25 | } else { |
||
| 26 | $contents .= PHP_EOL."{$envKey}=\"{$value}\""; |
||
| 27 | } |
||
| 28 | |||
| 29 | file_put_contents($envPath, $contents); |
||
| 30 | } |
||
| 48 |