EmptiedSetResolver
in package
FinalYes
Resolves which sales sets disappear together with a deleted product: those that would be left empty after removing the deleted items.
Contract:
- the sales card of a deleted variant (set of type
PRODUCT) always disappears, it contains only that variant; - a set composed of other sets (
BUNDLE) disappears only when all its items are deleted after the removal (recursively, a bundle in a bundle); - a bundle that also contains another item stays and only loses the item of the deleted product.
Pure function without I/O: the caller supplies set parents through $parentsOf of resolve().
Table of Contents
Constants
- MAX_DEPTH : int = 10
- Guard against a cycle in the data (`SetCompositionService::MAX_DEPTH`); more levels almost certainly mean bad data.
Methods
-
resolve()
: array{doomed: list
, survivingParents: list } - allDoomed() : bool
Constants
MAX_DEPTH
Guard against a cycle in the data (`SetCompositionService::MAX_DEPTH`); more levels almost certainly mean bad data.
private
int
MAX_DEPTH
= 10
Methods
resolve()
public
resolve(array<int, int> $leafSetIds, callable(array<int, int>): array<int, array<int, int>> $parentsOf) : array{doomed: list, survivingParents: list}
Parameters
- $leafSetIds : array<int, int>
-
cards of deleted variants (sets of type
PRODUCT) that always disappear - $parentsOf : callable(array<int, int>): array<int, array<int, int>>
-
returns the parent bundles of the given sets:
parentId => all ids of its items(the complete list, not only the deleted ones)
Return values
array{doomed: listdoomed = sets that disappear; survivingParents = bundles that stay but lose an item
allDoomed()
private
allDoomed(array<int, int> $childIds, array<int, true> $doomed) : bool
Parameters
- $childIds : array<int, int>
- $doomed : array<int, true>