From adcc3ddb25d10184de7008be07cb47176a9a1626 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 07:48:08 +0700 Subject: [PATCH] [BetterPhpDocParser] Unique handling string on BracketsAwareUnionTypeNode --- .../Type/BracketsAwareUnionTypeNode.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php b/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php index 15cdcc4252a..6d8d8e617ae 100644 --- a/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php +++ b/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php @@ -25,12 +25,20 @@ public function __construct( */ public function __toString(): string { - $this->types = array_unique($this->types, SORT_REGULAR); + $types = []; + + // get the actual strings first before array_unique + // to avoid similar object but different printing to be treated as unique + foreach ($this->types as $type) { + $types[] = (string) $type; + } + + $types = array_unique($types); if (! $this->isWrappedInBrackets) { - return implode('|', $this->types); + return implode('|', $types); } - return '(' . implode('|', $this->types) . ')'; + return '(' . implode('|', $types) . ')'; } public function isWrappedInBrackets(): bool