Passed
Push — main ( bcc232...2bc5a4 )
by Vasil
03:27
created

GetContractClientsResponseFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 21
ccs 4
cts 7
cp 0.5714
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VasilDakov\Speedy\Service\Client;
6
7
use Throwable;
8
use VasilDakov\Speedy\Exception\InvalidArgumentException;
9
use VasilDakov\Speedy\Serializer\SerializerFactory;
10
11
use function json_decode;
12
use function json_last_error;
13
14
/**
15
 * Class GetContractResponseFactory
16
 *
17
 * @author Vasil Dakov <[email protected]>
18
 * @copyright 2009-2022 Neutrino.bg
19
 * @version 1.0
20
 * @psalm-suppress UnusedFunctionCall
21
 */
22
final class GetContractClientsResponseFactory
23
{
24
    /**
25
     * @param string $json
26
     * @return GetContractClientsResponse
27
     * @throws Throwable
28
     */
29 1
    public function __invoke(string $json): GetContractClientsResponse
30
    {
31 1
        json_decode($json, true);
32
33 1
        if (json_last_error() !== JSON_ERROR_NONE) {
34 1
            throw new InvalidArgumentException('Invalid or malformed JSON');
35
        }
36
37
        $serializer = (new SerializerFactory())();
38
39
        /** @var GetContractClientsResponse $response */
40
        $response = $serializer->deserialize($json, GetContractClientsResponse::class, 'json');
41
42
        return $response;
43
    }
44
}
45