Skip to content

Commit

Permalink
refactor(ConfigCommand): simplify argToValue function
Browse files Browse the repository at this point in the history
- Remove unnecessary conditional checks for 'null', 'true', 'false', and numeric values.
- Retain the JSON decoding functionality for valid JSON strings.
- Return the decoded value or the original argument if not a valid JSON.
  • Loading branch information
ityaozm@gmail.com committed Oct 1, 2024
1 parent d96b0ce commit 624fa8c
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions app/Commands/ConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,27 +214,29 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
*/
private function argToValue(string $arg)
{
if (0 === strncasecmp($arg, 'null', 4)) {
return;
}

if (0 === strncasecmp($arg, 'true', 4)) {
return true;
}

if (0 === strncasecmp($arg, 'false', 5)) {
return false;
}

if (is_numeric($arg)) {
return str_contains($arg, '.') ? (float) $arg : (int) $arg;
}

if (str($arg)->jsonValidate()) {
return json_decode($arg, true, 512, JSON_THROW_ON_ERROR);
}
// if (0 === strncasecmp($arg, 'null', 4)) {
// return;
// }
//
// if (0 === strncasecmp($arg, 'true', 4)) {
// return true;
// }
//
// if (0 === strncasecmp($arg, 'false', 5)) {
// return false;
// }
//
// if (is_numeric($arg)) {
// return str_contains($arg, '.') ? (float) $arg : (int) $arg;
// }
//
// if (str($arg)->jsonValidate()) {
// return json_decode($arg, true, 512, JSON_THROW_ON_ERROR);
// }
//
// return $arg;

return $arg;
return json_decode($arg, true, 512, JSON_THROW_ON_ERROR);
}

/**
Expand Down

0 comments on commit 624fa8c

Please sign in to comment.