*/ private array $entries = []; /** @var list */ private array $touched = []; /** @var list */ private array $warnings = []; public function __construct(public readonly string $summary) { } /** * A node that still exists after the change: "inserted", "updated", "moved" or "duplicated". * Every action but "moved" counts for the quality warnings. */ public function record(Block $block, string $action): self { $this->entries[] = [ 'block' => $block, 'id' => null, 'type' => $block->name(), 'action' => $action, 'label' => NodeSummary::label($block), ]; if ($action !== 'moved') { $this->touched[] = $block; } return $this; } /** A node that is gone; $idBefore is its ID before the change. */ public function removed(string $idBefore, Block $block): self { $this->entries[] = [ 'block' => null, 'id' => $idBefore, 'type' => $block->name(), 'action' => 'deleted', 'label' => NodeSummary::label($block), ]; return $this; } public function warning(string $warning): self { $this->warnings[] = $warning; return $this; } /** @return list */ public function entries(): array { return $this->entries; } /** * Path ID of an entry in the tree after the change: a removed node keeps its ID from before * the removal; a surviving node is looked up in $index (null if it is not there). * * @param array{block: ?Block, id: ?string, type: string, action: string, label: string} $entry */ public static function idOf(array $entry, NodeIndex $index): ?string { return $entry['id'] ?? ($entry['block'] !== null ? $index->idOf($entry['block']) : null); } /** @return list */ public function touched(): array { return $this->touched; } /** @return list */ public function warnings(): array { return $this->warnings; } }