From ccd81f17296e25e4483728c2dfd2e71e700b8f78 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Tue, 4 Dec 2018 11:50:10 +0100 Subject: [PATCH] Always store received env variables in .env file Optimize code --- Dotenv.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Dotenv.php b/Dotenv.php index 6a666ab..986e60e 100644 --- a/Dotenv.php +++ b/Dotenv.php @@ -72,11 +72,12 @@ final class Dotenv { if ($this->io->isInteractive()) { $value = $this->io->ask($prompt . ': '); } + /** @noinspection NotOptimalIfConditionsInspection */ if (empty($value)) { $value = $default; } - $this->put($key, $value); } + $this->put($key, $value); return $value; } @@ -91,6 +92,7 @@ final class Dotenv { * The name of the environment variable. * @param string $value * The value of the environment variable. + * @param bool $overwrite */ public function put($key, $value, $overwrite = FALSE) { $envContent = file_exists('.env') ? file_get_contents('.env') : ''; @@ -101,8 +103,8 @@ final class Dotenv { } $data[$key] = $value; $envContent = ''; - foreach ($data as $key => $value) { - $envContent .= $key . '=' . $value . PHP_EOL; + foreach ($data as $k => $v) { + $envContent .= $k . '=' . $v . PHP_EOL; } file_put_contents('.env', $envContent); $this->load(); @@ -132,6 +134,7 @@ final class Dotenv { * @param string $key */ private function findEnvironmentVariables(&$item, &$key) { + /** @noinspection NotOptimalRegularExpressionsInspection */ $pattern = '@\{\$env:([A-Za-z0-9_]*)\}@i'; preg_match_all($pattern, $item, $item_matches); preg_match_all($pattern, $key, $key_matches); -- GitLab