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
[email protected] committed Oct 1, 2024
1 parent d96b0ce commit 8f36a3c
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 71 deletions.
30 changes: 15 additions & 15 deletions app/Commands/ConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,21 @@ 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 (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);
Expand Down
208 changes: 152 additions & 56 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8f36a3c

Please sign in to comment.