From bc8c7bcf1ef2d88f1d30bb312ba788a62b7d7291 Mon Sep 17 00:00:00 2001 From: JackieDo Date: Sun, 19 Feb 2023 07:27:09 +0700 Subject: [PATCH] Update artisan commands - Change method declaration location (stringToType). - Fixed input argument conversion for set-key command. --- src/Console/Commands/DotenvBackupCommand.php | 31 ----------------- .../Commands/DotenvDeleteKeyCommand.php | 31 ----------------- src/Console/Commands/DotenvGetKeysCommand.php | 31 ----------------- src/Console/Commands/DotenvRestoreCommand.php | 31 ----------------- src/Console/Commands/DotenvSetKeyCommand.php | 33 +------------------ .../Traits/CreateCommandInstanceTrait.php | 31 +++++++++++++++++ 6 files changed, 32 insertions(+), 156 deletions(-) diff --git a/src/Console/Commands/DotenvBackupCommand.php b/src/Console/Commands/DotenvBackupCommand.php index 6d0df60..8a40f36 100644 --- a/src/Console/Commands/DotenvBackupCommand.php +++ b/src/Console/Commands/DotenvBackupCommand.php @@ -48,37 +48,6 @@ public function fire() $this->info("Your file was backed up successfully at path [{$backup['filepath']}]."); } - /** - * Convert string to corresponding type. - * - * @param string $string - * - * @return mixed - */ - protected function stringToType($string) - { - if (is_string($string)) { - switch (true) { - case 'null' == $string || 'NULL' == $string: - $string = null; - break; - - case 'true' == $string || 'TRUE' == $string: - $string = true; - break; - - case 'false' == $string || 'FALSE' == $string: - $string = false; - break; - - default: - break; - } - } - - return $string; - } - /** * Get the console command arguments. * diff --git a/src/Console/Commands/DotenvDeleteKeyCommand.php b/src/Console/Commands/DotenvDeleteKeyCommand.php index f2212ac..d155be5 100644 --- a/src/Console/Commands/DotenvDeleteKeyCommand.php +++ b/src/Console/Commands/DotenvDeleteKeyCommand.php @@ -72,37 +72,6 @@ protected function transferInputsToProperties() $this->key = $this->argument('key'); } - /** - * Convert string to corresponding type. - * - * @param string $string - * - * @return mixed - */ - protected function stringToType($string) - { - if (is_string($string)) { - switch (true) { - case 'null' == $string || 'NULL' == $string: - $string = null; - break; - - case 'true' == $string || 'TRUE' == $string: - $string = true; - break; - - case 'false' == $string || 'FALSE' == $string: - $string = false; - break; - - default: - break; - } - } - - return $string; - } - /** * Get the console command arguments. * diff --git a/src/Console/Commands/DotenvGetKeysCommand.php b/src/Console/Commands/DotenvGetKeysCommand.php index 1248da2..530ebcb 100644 --- a/src/Console/Commands/DotenvGetKeysCommand.php +++ b/src/Console/Commands/DotenvGetKeysCommand.php @@ -65,37 +65,6 @@ public function fire() $this->info("You have total {$total} keys in your file"); } - /** - * Convert string to corresponding type. - * - * @param string $string - * - * @return mixed - */ - protected function stringToType($string) - { - if (is_string($string)) { - switch (true) { - case 'null' == $string || 'NULL' == $string: - $string = null; - break; - - case 'true' == $string || 'TRUE' == $string: - $string = true; - break; - - case 'false' == $string || 'FALSE' == $string: - $string = false; - break; - - default: - break; - } - } - - return $string; - } - /** * Get the console command arguments. * diff --git a/src/Console/Commands/DotenvRestoreCommand.php b/src/Console/Commands/DotenvRestoreCommand.php index 3657a7b..3e21373 100644 --- a/src/Console/Commands/DotenvRestoreCommand.php +++ b/src/Console/Commands/DotenvRestoreCommand.php @@ -72,37 +72,6 @@ protected function transferInputsToProperties() $this->restorePath = (is_string($restorePath)) ? base_path($restorePath) : null; } - /** - * Convert string to corresponding type. - * - * @param string $string - * - * @return mixed - */ - protected function stringToType($string) - { - if (is_string($string)) { - switch (true) { - case 'null' == $string || 'NULL' == $string: - $string = null; - break; - - case 'true' == $string || 'TRUE' == $string: - $string = true; - break; - - case 'false' == $string || 'FALSE' == $string: - $string = false; - break; - - default: - break; - } - } - - return $string; - } - /** * Get the console command arguments. * diff --git a/src/Console/Commands/DotenvSetKeyCommand.php b/src/Console/Commands/DotenvSetKeyCommand.php index 013674d..654a146 100644 --- a/src/Console/Commands/DotenvSetKeyCommand.php +++ b/src/Console/Commands/DotenvSetKeyCommand.php @@ -114,42 +114,11 @@ protected function transferInputsToProperties() $this->restorePath = (is_string($restorePath)) ? base_path($restorePath) : null; $this->key = $this->argument('key'); - $this->value = $this->stringToType($this->argument('value')); + $this->value = $this->argument('value'); $this->comment = $this->stringToType($this->argument('comment')); $this->exportKey = $this->option('export-key'); } - /** - * Convert string to corresponding type. - * - * @param string $string - * - * @return mixed - */ - protected function stringToType($string) - { - if (is_string($string)) { - switch (true) { - case 'null' == $string || 'NULL' == $string: - $string = null; - break; - - case 'true' == $string || 'TRUE' == $string: - $string = true; - break; - - case 'false' == $string || 'FALSE' == $string: - $string = false; - break; - - default: - break; - } - } - - return $string; - } - /** * Get the console command arguments. * diff --git a/src/Console/Traits/CreateCommandInstanceTrait.php b/src/Console/Traits/CreateCommandInstanceTrait.php index 5606960..55086e1 100644 --- a/src/Console/Traits/CreateCommandInstanceTrait.php +++ b/src/Console/Traits/CreateCommandInstanceTrait.php @@ -36,4 +36,35 @@ public function handle() { return $this->fire(); } + + /** + * Convert string to corresponding type. + * + * @param string $string + * + * @return mixed + */ + protected function stringToType($string) + { + if (is_string($string)) { + switch (true) { + case 'null' == $string || 'NULL' == $string: + $string = null; + break; + + case 'true' == $string || 'TRUE' == $string: + $string = true; + break; + + case 'false' == $string || 'FALSE' == $string: + $string = false; + break; + + default: + break; + } + } + + return $string; + } }