Skip to content

Commit bb85727

Browse files
authored
Merge pull request #80 from boesing/qa/hardening-type-safety
qa: hardening type-safety for `JsonSerializable` implementation
2 parents 23d5c2a + 49bcef1 commit bb85727

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/Map.php

+1-1
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

+5
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

+5
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)