Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
5 / 6
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
BuiltinSerializer
83.33% covered (warning)
83.33%
5 / 6
50.00% covered (danger)
50.00%
1 / 2
4.07
0.00% covered (danger)
0.00%
0 / 1
 saveImpl
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 loadImpl
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
3.14
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\Core\Serialization;
6
7use JsonException;
8use Exception;
9use PeServer\Core\Binary;
10use PeServer\Core\Serialization\SerializerBase;
11use PeServer\Core\Throws\JsonDecodeException;
12use PeServer\Core\Throws\JsonEncodeException;
13use PeServer\Core\Throws\ParseException;
14use PeServer\Core\Throws\Throws;
15use PeServer\Core\TypeUtility;
16
17/**
18 * PHP組み込みシリアライザー。
19 */
20final class BuiltinSerializer extends SerializerBase
21{
22    #region SerializerBase
23
24    protected function saveImpl(array|object $value): Binary
25    {
26        $data = serialize($value);
27        return new Binary($data);
28    }
29
30    protected function loadImpl(Binary $value): array|object
31    {
32        $data = unserialize($value->raw);
33        if (is_array($data) || is_object($data)) {
34            return $data;
35        }
36
37        throw new Exception(TypeUtility::getType($data));
38    }
39
40    #endregion
41}