|
| 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 | +?> |
0 commit comments