@@ -35,7 +35,9 @@ public static function fromString(string $ltree): static
3535
3636 $ pathFromRoot = \explode ('. ' , $ ltree );
3737
38- return new static ($ pathFromRoot ); // @phpstan-ignore-line argument.type
38+ self ::assertListOfValidLtreeNodes ($ pathFromRoot );
39+
40+ return new static ($ pathFromRoot );
3941 }
4042
4143 #[\Override]
@@ -57,10 +59,9 @@ public function getParent(): static
5759 throw new \LogicException ('Empty ltree has no parent. ' );
5860 }
5961
60- $ parentBranch = \array_slice ($ this ->pathFromRoot , 0 , -1 );
61- self ::assertListOfValidLtreeNodes ($ parentBranch );
62+ $ parentPathFromRoot = \array_slice ($ this ->pathFromRoot , 0 , -1 );
6263
63- return new static ($ parentBranch );
64+ return new static ($ parentPathFromRoot );
6465 }
6566
6667 #[\Override]
@@ -92,7 +93,9 @@ public function isAncestorOf(LtreeInterface $ltree): bool
9293 return true ;
9394 }
9495
95- return \str_starts_with ((string ) $ ltree , \sprintf ('%s. ' , (string ) $ this ));
96+ $ prefix = \sprintf ('%s. ' , (string ) $ this );
97+
98+ return \str_starts_with ((string ) $ ltree , $ prefix );
9699 }
97100
98101 #[\Override]
@@ -106,7 +109,9 @@ public function isDescendantOf(LtreeInterface $ltree): bool
106109 return true ;
107110 }
108111
109- return \str_starts_with ((string ) $ this , \sprintf ('%s. ' , (string ) $ ltree ));
112+ $ prefix = \sprintf ('%s. ' , (string ) $ ltree );
113+
114+ return \str_starts_with ((string ) $ this , $ prefix );
110115 }
111116
112117 #[\Override]
@@ -162,10 +167,9 @@ protected static function assertListOfValidLtreeNodes(array $value): void
162167 throw new \InvalidArgumentException ('Branch must be a list of non-empty strings. ' );
163168 }
164169
165- \array_map (
166- self ::assertValidLtreeNode (...),
167- $ value ,
168- );
170+ foreach ($ value as $ node ) {
171+ self ::assertValidLtreeNode ($ node );
172+ }
169173 }
170174
171175 /**
0 commit comments