In EachHandler there are 2 returns without restoring in context parent Each's key.
$originalEachKey = $context->getParameter(Each::PARAMETER_EACH_KEY); // <== storing parent key
foreach ($value as $index => $item) {
if (!is_int($index) && !is_string($index)) {
return (new Result())->addError($rule->getIncorrectInputKeyMessage(), [ // <== bug, return without restoring parent key
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
'type' => get_debug_type($index),
]);
}
$context->setParameter(Each::PARAMETER_EACH_KEY, $index);
$itemResult = $context->validate($item, $rules);
if ($itemResult->isValid()) {
continue;
}
foreach ($itemResult->getErrors() as $error) {
$result->addErrorWithoutPostProcessing(
$error->getMessage(),
$error->getParameters(),
$error->getValuePath() === [] ? [$index] : [$index, ...$error->getValuePath()],
);
}
if ($rule->stopOnError) {
return $result; // <== bug, return without restoring parent key
}
}
$context->setParameter(Each::PARAMETER_EACH_KEY, $originalEachKey); // <== restoring parent key
return $result;
Description
In EachHandler there are 2 returns without restoring in context parent Each's key.
Code in question:
Package version
No response
PHP version
No response