Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
62.50% covered (warning)
62.50%
5 / 8
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SerializedHashmap
62.50% covered (warning)
62.50%
5 / 8
0.00% covered (danger)
0.00%
0 / 2
9.58
0.00% covered (danger)
0.00%
0 / 1
 offsetSet
71.43% covered (warning)
71.43%
5 / 7
0.00% covered (danger)
0.00%
0 / 1
6.84
 offsetGet
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2namespace Apie\Serializer\Lists;
3
4use Apie\Core\Lists\ItemHashmap;
5use Apie\Core\Lists\ItemList;
6
7/**
8 * A hashmap of items that is already serialized and does not need to be serialized again.
9 *
10 * @see ItemListNormalizer
11 */
12final class SerializedHashmap extends ItemHashmap
13{
14    protected bool $mutable = false;
15
16    public function offsetSet(mixed $offset, mixed $value): void
17    {
18        if ($value instanceof ItemList && !($value instanceof SerializedList)) {
19            $value = new SerializedList($value->toArray());
20        } elseif ($value instanceof ItemHashmap && !($value instanceof SerializedHashmap)) {
21            $value = new SerializedHashmap($value->toArray());
22        } elseif (is_array($value)) {
23            $value = new SerializedHashmap($value);
24        }
25        parent::offsetSet($offset, $value);
26    }
27
28    /**
29     * @return mixed[]|string|int|float|bool
30     */
31    public function offsetGet(mixed $offset): array|string|int|float|bool|null|SerializedList|SerializedHashmap
32    {
33        return parent::offsetGet($offset);
34    }
35}