fix(routing): defensive fallback, between bounds check, condition key guard

main
boban 2026-05-16 01:02:37 +02:00
parent e06db03320
commit 7d47222591
1 changed files with 6 additions and 2 deletions

View File

@ -15,7 +15,7 @@ class SmartRoutingEngine
} }
} }
return $config['fallback']; return $config['fallback'] ?? '';
} }
private function ruleMatches(array $rule, array $context): bool private function ruleMatches(array $rule, array $context): bool
@ -39,6 +39,10 @@ class SmartRoutingEngine
private function evaluateCondition(array $condition, array $context): bool private function evaluateCondition(array $condition, array $context): bool
{ {
if (! isset($condition['field'], $condition['op'], $condition['value'])) {
return false;
}
$field = $condition['field']; $field = $condition['field'];
$op = $condition['op']; $op = $condition['op'];
$expected = $condition['value']; $expected = $condition['value'];
@ -51,7 +55,7 @@ class SmartRoutingEngine
'not_in' => ! in_array($actual, (array) $expected, true), 'not_in' => ! in_array($actual, (array) $expected, true),
'contains' => str_contains((string) $actual, (string) $expected), 'contains' => str_contains((string) $actual, (string) $expected),
'starts_with' => str_starts_with((string) $actual, (string) $expected), 'starts_with' => str_starts_with((string) $actual, (string) $expected),
'between' => $actual >= $expected[0] && $actual <= $expected[1], 'between' => is_array($expected) && count($expected) === 2 && $actual >= $expected[0] && $actual <= $expected[1],
'greater_than' => $actual > $expected, 'greater_than' => $actual > $expected,
'less_than' => $actual < $expected, 'less_than' => $actual < $expected,
default => false, default => false,