Skip to content

Commit 49bcef1

Browse files
committed
qa: hardening type-safety for JsonSerializable implementation
Signed-off-by: Maximilian Bösing <[email protected]>
1 parent 3ba0be6 commit 49bcef1

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/Map.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public function slice(int $length): MapInterface
384384

385385
public function jsonSerialize(): ?array
386386
{
387-
if ($this->isEmpty()) {
387+
if ($this->data === []) {
388388
return null;
389389
}
390390

src/MapInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,9 @@ public function join(string $separator = ''): string;
183183
* @throws RuntimeException if a new key is being generated more than once.
184184
*/
185185
public function keyExchange(callable $keyGenerator): MapInterface;
186+
187+
/**
188+
* @psalm-return non-empty-array<TKey,TValue>|null
189+
*/
190+
public function jsonSerialize(): ?array;
186191
}

src/OrderedListInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,9 @@ public function join(string $separator = ''): string;
150150
* @psalm-return list<TValue>
151151
*/
152152
public function toNativeArray(): array;
153+
154+
/**
155+
* @psalm-return list<TValue>
156+
*/
157+
public function jsonSerialize(): array;
153158
}

0 commit comments

Comments
 (0)