From d813fdbc0935c7e5be8ff22017fec66ba4ff7b73 Mon Sep 17 00:00:00 2001 From: David Maicher Date: Tue, 30 Jul 2024 18:41:34 +0200 Subject: [PATCH] prevent calling ->end() on root node (#45) --- src/Node/Node.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Node/Node.php b/src/Node/Node.php index a28809e..4415ced 100644 --- a/src/Node/Node.php +++ b/src/Node/Node.php @@ -152,8 +152,12 @@ public function child(?string $label = null): self return $child; } - public function end(): ?self + public function end(): self { + if ($this->parent === null) { + throw new \LogicException('Cannot call end() on root node'); + } + return $this->parent; }