Lines 100.00% 11 / 11
Methods 100.00% 1 / 1
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 readRemovedEntityIds 100.00% 11 / 11 100.00% 1 / 1 6
12final class ReconcileResultReader
13{
14    /**
15     * @param array<array-key, mixed> $result
16     * @throws HaClientException
17     */
18    public static function readRemovedEntityIds(array $result): EntityIdCollection
19    {
20        $removed = $result['removed'] ?? null;
21
22        if (!\is_array($removed) || !array_is_list($removed)) {
23            throw HaClientException::protocolViolation('a stewart/entity/reconcile result without removed');
24        }
25
26        $entityIds = [];
27
28        foreach ($removed as $entityId) {
29            if (!\is_string($entityId)) {
30                throw HaClientException::protocolViolation('a stewart/entity/reconcile result with a non-string entity id');
31            }
32
33            try {
34                $entityIds[] = new EntityId($entityId);
35            } catch (IdentifierException $e) {
36                throw HaClientException::protocolViolation('a stewart/entity/reconcile result with an invalid entity id', $e);
37            }
38        }
39
40        return EntityIdCollection::fromList($entityIds);
41    }
42}