Test Failed
Push — main ( d030ca...7189b9 )
by Vasil
05:52
created

DestinationServicesResponseFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 6
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 14
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Neutrino package.
5
 *
6
 * (c) Vasil Dakov <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace VasilDakov\Speedy\Service\Service;
15
16
use VasilDakov\Speedy\Exception\InvalidArgumentException;
17
use VasilDakov\Speedy\Serializer\SerializerFactory;
18
19
/**
20
 * Class DestinationServicesResponseFactory
21
 *
22
 * @author Vasil Dakov <[email protected]>
23
 * @copyright 2009-2023 Neutrino.bg
24
 * @version 1.0
25
 */
26
class DestinationServicesResponseFactory
27
{
28
    public function __invoke(string $json): DestinationServicesResponse
29
    {
30
        json_decode($json, true);
31
32
        if (json_last_error() !== JSON_ERROR_NONE) {
33
            throw new InvalidArgumentException('Invalid or malformed JSON');
34
        }
35
36
        $serializer = (new SerializerFactory())();
37
38
        /** @var DestinationServicesResponse $response */
39
        $response = $serializer->deserialize($json, DestinationServicesResponse::class, 'json');
40
41
        return $response;
42
    }
43
}
44