Fix false child acceptance criteria sync
linter / quality (pull_request) Successful in 1m20s
tests / ci (8.4) (pull_request) Successful in 1m31s

This commit is contained in:
2026-05-20 13:46:50 +00:00
parent 2bc7745e53
commit 31c5025185
3 changed files with 134 additions and 31 deletions
@@ -35,9 +35,7 @@ class AcceptanceCriteriaChecklistMapper
public static function normalize(mixed $value): array
{
if (is_array($value)) {
return self::syncDescendantCheckedState(
self::normalizeFromArray($value),
);
return self::normalizeFromArray($value);
}
return [];
@@ -168,28 +166,6 @@ class AcceptanceCriteriaChecklistMapper
return max(0, min(self::MAX_INDENT_LEVEL, $indent));
}
/**
* @param array<int, array{id?: int, checked: bool, indent: int, text: string}> $items
* @return array<int, array{id?: int, checked: bool, indent: int, text: string}>
*/
private static function syncDescendantCheckedState(array $items): array
{
$checkedStateByIndent = [];
foreach ($items as $index => $item) {
$indent = $item['indent'];
if ($indent > 0 && array_key_exists($indent - 1, $checkedStateByIndent)) {
$items[$index]['checked'] = $checkedStateByIndent[$indent - 1];
}
$checkedStateByIndent[$indent] = $items[$index]['checked'];
$checkedStateByIndent = array_slice($checkedStateByIndent, 0, $indent + 1, true);
}
return $items;
}
/**
* @param iterable<AcceptanceCriterion> $criteria
* @return array<int, array{id?: int, checked: bool, indent: int, text: string}>