Skip to content

Commit

Permalink
Simplify parseArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorejb committed Dec 11, 2024
1 parent 8fc9b70 commit f63d9c1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Handlebars/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,19 +583,21 @@ private function extractSlice(string $string): array
*/
private function parseArgs(Context $context, string $args): array
{
$args = preg_replace('/\s+/', ' ', trim($args));
$eles = explode(' ', $args);
foreach ($eles as $key => $ele) {
if (in_array(substr($ele, 0, 1), ['\'', '"'])) {
$val = trim($ele, '\'"');
} else if (is_numeric($ele)) {
$val = $ele;
$args = preg_split('/\s+/', trim($args));

foreach ($args as $idx => $el) {
if (in_array(substr($el, 0, 1), ["'", '"'])) {
$val = trim($el, '\'"');
} elseif (is_numeric($el)) {
$val = $el;
} else {
$val = $context->get($ele);
/** @var scalar|null $val */
$val = $context->get($el);
}
$eles[$key] = $val;

$args[$idx] = $val;
}

return $eles;
return $args;
}
}

0 comments on commit f63d9c1

Please sign in to comment.