subject = $subject; } public function getSubject(): EntityPointer { return $this->subject; } public function getHead(): EntityPointerLink { $head = $this; while ($head->ancestor !== null) { $head = $head->ancestor; } return $head; } public function getAncestor(): ?EntityPointerLink { return $this->ancestor; } public function withAncestor(EntityPointerLink $ancestor): self { if ($this->ancestor === $ancestor) { return $this; } $target = clone $this; $target->ancestor = $ancestor; return $target; } }