*/ protected array $changes = []; public function add(Entity $oldEntity, Entity $newEntity): void { $this->changes[] = [$oldEntity, $newEntity]; } /** * Get all the new entities from the changes. */ public function getNewEntities(): array { return array_column($this->changes, 1); } /** * Get all the old entities from the changes. */ public function getOldEntities(): array { return array_column($this->changes, 0); } public function getNewForOld(Entity $oldEntity): ?Entity { foreach ($this->changes as [$old, $new]) { if ($old->id === $oldEntity->id && $old->type === $oldEntity->type) { return $new; } } return null; } }