Skip to content

Commit

Permalink
Merge pull request #80 from boesing/qa/hardening-type-safety
Browse files Browse the repository at this point in the history
qa: hardening type-safety for `JsonSerializable` implementation
  • Loading branch information
boesing committed Jul 16, 2021
2 parents 23d5c2a + 49bcef1 commit bb85727
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function slice(int $length): MapInterface

public function jsonSerialize(): ?array
{
if ($this->isEmpty()) {
if ($this->data === []) {
return null;
}

Expand Down
5 changes: 5 additions & 0 deletions src/MapInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,9 @@ public function join(string $separator = ''): string;
* @throws RuntimeException if a new key is being generated more than once.
*/
public function keyExchange(callable $keyGenerator): MapInterface;

/**
* @psalm-return non-empty-array<TKey,TValue>|null
*/
public function jsonSerialize(): ?array;
}
5 changes: 5 additions & 0 deletions src/OrderedListInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,9 @@ public function join(string $separator = ''): string;
* @psalm-return list<TValue>
*/
public function toNativeArray(): array;

/**
* @psalm-return list<TValue>
*/
public function jsonSerialize(): array;
}

0 comments on commit bb85727

Please sign in to comment.