Lines 100.00% 4 / 4
Functions and Methods 100.00% 4 / 4
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
WorkerAppsFragment 100.00% 4 / 4 100.00% 4 / 4 4 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 fromCollection 100.00% 1 / 1 100.00% 1 / 1 1
 fromDecodedValue 100.00% 1 / 1 100.00% 1 / 1 1
 encodeToJson 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Ipc\Wire;
6
7use Stewart\Runtime\Ipc\Collection\WorkerAppCollection;
8use Stewart\Runtime\Ipc\WorkerApp;
9use Stewart\Runtime\Json\JsonFragment;
10use Stewart\Runtime\Json\WireMapper;
11
12final readonly class WorkerAppsFragment implements JsonFragment
13{
14    private function __construct(public WorkerAppCollection $collection) {}
15
16    public static function fromCollection(WorkerAppCollection $apps): self
17    {
18        return new self($apps);
19    }
20
21    public static function fromDecodedValue(mixed $value, string $path, WireMapper $mapper): static
22    {
23        return new self(WorkerAppCollection::fromList($mapper->decodeObjectList(WorkerApp::class, $value, $path)));
24    }
25
26    public function encodeToJson(WireMapper $mapper): string
27    {
28        return $mapper->encodeObjectList($this->collection->listValues());
29    }
30}