Skip to content

Commit d830051

Browse files
authored
[BetterPhpDocParser] Unique handling string on BracketsAwareUnionTypeNode (#7462)
1 parent 227fa7c commit d830051

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ public function __construct(
2525
*/
2626
public function __toString(): string
2727
{
28-
$this->types = array_unique($this->types, SORT_REGULAR);
28+
$types = [];
29+
30+
// get the actual strings first before array_unique
31+
// to avoid similar object but different printing to be treated as unique
32+
foreach ($this->types as $type) {
33+
$types[] = (string) $type;
34+
}
35+
36+
$types = array_unique($types);
2937
if (! $this->isWrappedInBrackets) {
30-
return implode('|', $this->types);
38+
return implode('|', $types);
3139
}
3240

33-
return '(' . implode('|', $this->types) . ')';
41+
return '(' . implode('|', $types) . ')';
3442
}
3543

3644
public function isWrappedInBrackets(): bool

0 commit comments

Comments
 (0)