mtvbrianking /
laravel-airtel-money
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Bmatovu\AirtelMoney\Traits; |
||||||
| 4 | |||||||
| 5 | trait CommandUtils |
||||||
| 6 | { |
||||||
| 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')) { |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 12 | return; |
||||||
| 13 | } |
||||||
| 14 | |||||||
| 15 | $envPath = app()->basePath('.env'); |
||||||
|
0 ignored issues
–
show
The method
basePath() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 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 | } |
||||||
| 31 | |||||||
| 32 | protected function writeConfig( |
||||||
| 33 | string $key, |
||||||
| 34 | ?string $value = null, |
||||||
| 35 | string $config = 'airtel-money' |
||||||
| 36 | ): ?string { |
||||||
| 37 | $configKey = "{$config}.{$key}"; |
||||||
| 38 | |||||||
| 39 | $oldValue = $value ?? $this->laravel->make('config')->get($configKey); |
||||||
| 40 | |||||||
| 41 | $newValue = $this->ask($key, $oldValue); |
||||||
|
0 ignored issues
–
show
It seems like
ask() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 42 | |||||||
| 43 | $this->persistConfig($configKey, $newValue); |
||||||
| 44 | |||||||
| 45 | return $newValue; |
||||||
| 46 | } |
||||||
| 47 | } |
||||||
| 48 |