fix(routing): defensive fallback, between bounds check, condition key guard
parent
e06db03320
commit
7d47222591
|
|
@ -15,7 +15,7 @@ class SmartRoutingEngine
|
|||
}
|
||||
}
|
||||
|
||||
return $config['fallback'];
|
||||
return $config['fallback'] ?? '';
|
||||
}
|
||||
|
||||
private function ruleMatches(array $rule, array $context): bool
|
||||
|
|
@ -39,6 +39,10 @@ class SmartRoutingEngine
|
|||
|
||||
private function evaluateCondition(array $condition, array $context): bool
|
||||
{
|
||||
if (! isset($condition['field'], $condition['op'], $condition['value'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$field = $condition['field'];
|
||||
$op = $condition['op'];
|
||||
$expected = $condition['value'];
|
||||
|
|
@ -51,7 +55,7 @@ class SmartRoutingEngine
|
|||
'not_in' => ! in_array($actual, (array) $expected, true),
|
||||
'contains' => str_contains((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,
|
||||
'less_than' => $actual < $expected,
|
||||
default => false,
|
||||
|
|
|
|||
Loading…
Reference in New Issue