diff --git a/Dotenv.php b/Dotenv.php
index 6a666abda81e59fae6a68392092cbeb633c62f1a..986e60ebb238bd1e93fa5956474f426cca390431 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);