Skip to content

Commit

Permalink
Update artisan commands
Browse files Browse the repository at this point in the history
- Change method declaration location (stringToType).
- Fixed input argument conversion for set-key command.
  • Loading branch information
JackieDo committed Feb 19, 2023
1 parent a55eecf commit bc8c7bc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 156 deletions.
31 changes: 0 additions & 31 deletions src/Console/Commands/DotenvBackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
31 changes: 0 additions & 31 deletions src/Console/Commands/DotenvDeleteKeyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
31 changes: 0 additions & 31 deletions src/Console/Commands/DotenvGetKeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
31 changes: 0 additions & 31 deletions src/Console/Commands/DotenvRestoreCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
33 changes: 1 addition & 32 deletions src/Console/Commands/DotenvSetKeyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
31 changes: 31 additions & 0 deletions src/Console/Traits/CreateCommandInstanceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit bc8c7bc

Please sign in to comment.