Skip to content

Commit

Permalink
Merge pull request #2 from prestaconcept/fix-adapters-function-expres…
Browse files Browse the repository at this point in the history
…sion-matcher

Adapters FunctionExpressionMatcher should return as is if nothing mat…
  • Loading branch information
J-Ben87 committed May 19, 2024
2 parents 877bac8 + 2947e85 commit bb20afd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Adapter/ConstantAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ public function __invoke(mixed $value): mixed

$match = new FunctionExpressionMatcher();

foreach ($match('constant', $value) as $expression) {
$expressions = $match('constant', $value);
if ([] === $expressions) {
return $value;
}

foreach ($expressions as $expression) {
$evaluated = $this->expressionLanguage->evaluate($expression);

// the evaluation did not end up with a transformation
Expand Down
7 changes: 6 additions & 1 deletion src/Adapter/DateTimeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public function __invoke(mixed $value): mixed

$match = new FunctionExpressionMatcher();

foreach ($match('datetime(_immutable)?', $value) as $expression) {
$expressions = $match('datetime(_immutable)?', $value);
if ([] === $expressions) {
return $value;
}

foreach ($expressions as $expression) {
// surround named parameters arguments by double quotes
// so that the named parameter part is not interpreted by the expression language
// ex. 'format: "Y-m-d"' will be transformed to '"format: \"Y-m-d\""'
Expand Down
7 changes: 6 additions & 1 deletion src/Adapter/EnumAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ public function __invoke(mixed $value): mixed

$match = new FunctionExpressionMatcher();

foreach ($match('enum', $value) as $expression) {
$expressions = $match('enum', $value);
if ([] === $expressions) {
return $value;
}

foreach ($expressions as $expression) {
try {
$evaluated = $this->expressionLanguage->evaluate($expression);
} catch (\Throwable $exception) {
Expand Down
7 changes: 6 additions & 1 deletion src/Adapter/FactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public function __invoke(mixed $value): mixed

$match = new FunctionExpressionMatcher();

foreach ($match('factory', $value) as $expression) {
$expressions = $match('factory', $value);
if ([] === $expressions) {
return $value;
}

foreach ($expressions as $expression) {
$evaluated = $this->expressionLanguage->evaluate($expression);
if ("<$expression>" === $value) {
return $evaluated;
Expand Down

0 comments on commit bb20afd

Please sign in to comment.