|
14 | 14 | namespace Laudis\Neo4j\Databags; |
15 | 15 |
|
16 | 16 | use InvalidArgumentException; |
| 17 | +use Laudis\Neo4j\Types\AbstractCypherObject; |
17 | 18 |
|
18 | | -final class Notification |
| 19 | +/** |
| 20 | + * @psalm-immutable |
| 21 | + * |
| 22 | + * @template-extends AbstractCypherObject<string, string|Position> |
| 23 | + */ |
| 24 | +final class Notification extends AbstractCypherObject |
19 | 25 | { |
20 | 26 | public function __construct( |
21 | | - private string $severity, |
22 | | - private string $description, |
23 | | - private string $code, |
24 | | - private Position $position, |
25 | | - private string $title, |
26 | | - private string $category, |
| 27 | + private readonly string $severity, |
| 28 | + private readonly string $description, |
| 29 | + private readonly string $code, |
| 30 | + private readonly Position $position, |
| 31 | + private readonly string $title, |
| 32 | + private readonly string $category, |
27 | 33 | ) { |
28 | 34 | } |
29 | 35 |
|
@@ -92,9 +98,38 @@ public function getCategory(): string |
92 | 98 | } |
93 | 99 |
|
94 | 100 | /** |
| 101 | + * Matches inherited return type: array<string, string|Position>. |
| 102 | + * |
95 | 103 | * @psalm-external-mutation-free |
| 104 | + * |
| 105 | + * @return array<string, string|Position> |
96 | 106 | */ |
97 | 107 | public function toArray(): array |
| 108 | + { |
| 109 | + return [ |
| 110 | + 'severity' => $this->severity, |
| 111 | + 'description' => $this->description, |
| 112 | + 'code' => $this->code, |
| 113 | + 'position' => $this->position, |
| 114 | + 'title' => $this->title, |
| 115 | + 'category' => $this->category, |
| 116 | + ]; |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * If you still want a version with the position converted to array, |
| 121 | + * use this custom method instead of overriding toArray(). |
| 122 | + * |
| 123 | + * @return array{ |
| 124 | + * severity: string, |
| 125 | + * description: string, |
| 126 | + * code: string, |
| 127 | + * position: array<string, float|int|null|string>, |
| 128 | + * title: string, |
| 129 | + * category: string |
| 130 | + * } |
| 131 | + */ |
| 132 | + public function toSerializedArray(): array |
98 | 133 | { |
99 | 134 | return [ |
100 | 135 | 'severity' => $this->severity, |
|
0 commit comments