Skip to content

Commit 227fa7c

Browse files
authored
[TypeDeclarationDocblocks] Handle repeated item type on DocblockReturnArrayFromDirectArrayInstanceRector (#7459)
* [TypeDeclarationDocblocks] Handle repeated item type on DocblockReturnArrayFromDirectArrayInstanceRector * fix
1 parent 47693a2 commit 227fa7c

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockReturnArrayFromDirectArrayInstanceRector\Fixture;
4+
5+
final class RepeatedItemType
6+
{
7+
public function __construct(
8+
public readonly string $collectionName,
9+
public readonly ?string $partitionName = null,
10+
public readonly ?int $replicaNumber = null,
11+
public readonly ?int $timeout = null,
12+
) {}
13+
14+
public function toRequestPayload(): array
15+
{
16+
$params = [
17+
'partition_name' => $this->partitionName,
18+
'replica_number' => $this->replicaNumber,
19+
'timeout' => $this->timeout,
20+
];
21+
22+
$params = array_filter($params);
23+
24+
return [
25+
'collection_name' => $this->collectionName,
26+
'params' => $params,
27+
];
28+
}
29+
}
30+
31+
?>
32+
-----
33+
<?php
34+
35+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockReturnArrayFromDirectArrayInstanceRector\Fixture;
36+
37+
final class RepeatedItemType
38+
{
39+
public function __construct(
40+
public readonly string $collectionName,
41+
public readonly ?string $partitionName = null,
42+
public readonly ?int $replicaNumber = null,
43+
public readonly ?int $timeout = null,
44+
) {}
45+
46+
/**
47+
* @return array<string, string|array<string, int|string>>
48+
*/
49+
public function toRequestPayload(): array
50+
{
51+
$params = [
52+
'partition_name' => $this->partitionName,
53+
'replica_number' => $this->replicaNumber,
54+
'timeout' => $this->timeout,
55+
];
56+
57+
$params = array_filter($params);
58+
59+
return [
60+
'collection_name' => $this->collectionName,
61+
'params' => $params,
62+
];
63+
}
64+
}
65+
66+
?>

src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function __construct(
2525
*/
2626
public function __toString(): string
2727
{
28+
$this->types = array_unique($this->types, SORT_REGULAR);
2829
if (! $this->isWrappedInBrackets) {
2930
return implode('|', $this->types);
3031
}

0 commit comments

Comments
 (0)