• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tochka-developers / jsonrpc / 4135501466

pending completion
4135501466

push

github

darkdarin
Merge remote-tracking branch 'origin/v5.0'

209 of 813 new or added lines in 51 files covered. (25.71%)

233 of 1307 relevant lines covered (17.83%)

1.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/DTO/JsonRpcResponseCollection.php
1
<?php
2

3
namespace Tochka\JsonRpc\DTO;
4

5
use Illuminate\Contracts\Support\Arrayable;
6
use Illuminate\Contracts\Support\Jsonable;
7
use Tochka\JsonRpc\Standard\DTO\JsonRpcResponse;
8

9
/**
10
 * @psalm-api
11
 * @psalm-import-type JsonRpcResponseArray from JsonRpcResponse
12
 * @psalm-suppress MissingTemplateParam
13
 */
14
class JsonRpcResponseCollection implements Jsonable, Arrayable, \JsonSerializable
15
{
16
    /** @var array<JsonRpcResponse> */
17
    public array $items = [];
18

19
    public function add(JsonRpcResponse $response): void
20
    {
21
        $this->items[] = $response;
×
22
    }
23

24
    public function empty(): bool
25
    {
26
        return empty($this->items);
×
27
    }
28

29
    /**
30
     * @inheritDoc
31
     * @throws \JsonException
32
     */
33
    public function toJson($options = 0): string
34
    {
35
        return json_encode($this->toArray(), JSON_THROW_ON_ERROR | $options | JSON_UNESCAPED_UNICODE);
×
36
    }
37

38
    /**
39
     * @return array<int, JsonRpcResponseArray>|JsonRpcResponseArray
40
     */
41
    public function toArray(): array
42
    {
43
        if (count($this->items) === 1) {
×
44
            $response = array_shift($this->items);
×
45

46
            return $response->toArray();
×
47
        }
48

49
        return array_map(
×
NEW
50
            static fn (JsonRpcResponse $item) => $item->toArray(),
×
NEW
51
            $this->items
×
NEW
52
        );
×
53
    }
54

55
    public function jsonSerialize(): array
56
    {
NEW
57
        if (count($this->items) === 1) {
×
NEW
58
            $response = array_shift($this->items);
×
59

NEW
60
            return $response->toArray();
×
61
        }
62

NEW
63
        return array_map(
×
NEW
64
            static fn (JsonRpcResponse $item) => $item->jsonSerialize(),
×
65
            $this->items
×
66
        );
×
67
    }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc