Skip to content

Commit

Permalink
Fallback if unit or operator not set
Browse files Browse the repository at this point in the history
  • Loading branch information
florisbosch committed Jul 25, 2024
1 parent bf39bf0 commit 3a8f0c4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rules/Carbon/NodeFactory/CarbonCallFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ public function createFromDateTimeString(FullyQualified $carbonFullyQualified, S
'day', 'days' => 'days',
'week', 'weeks' => 'weeks',
'month', 'months' => 'months',
default => null,
};

$methodName = match((string) $match['operator']) {
$operator = match((string) $match['operator']) {
'+' => 'add',
'-' => 'sub',
} . ucfirst($unit);
default => null,
};

if ($unit === null || $operator === null) {
return new StaticCall($carbonFullyQualified, new Identifier('parse'), [new Arg($string)]);
}

$methodName = $operator . ucfirst($unit);

return new MethodCall($carbonCall, new Identifier($methodName), [new Arg($countLNumber)]);
}
Expand Down

0 comments on commit 3a8f0c4

Please sign in to comment.