Passed
Push — main ( a8b0f9...5ab65b )
by Vasil
03:25
created

GetOfficesResponseFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 13
ccs 0
cts 6
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace VasilDakov\Econt\Response;
4
5
use VasilDakov\Econt\Exception\InvalidArgumentException;
6
use VasilDakov\Econt\Serializer\SerializerFactory;
7
8
class GetOfficesResponseFactory
9
{
10
    public function __invoke(string $json): GetOfficesResponse
11
    {
12
        /** @var array $array */
13
        $array = json_decode($json, true);
0 ignored issues
show
Unused Code introduced by
The assignment to $array is dead and can be removed.
Loading history...
14
15
        if (json_last_error() !== JSON_ERROR_NONE) {
16
            throw new InvalidArgumentException('Invalid or malformed JSON');
17
        }
18
19
        $serializer = (new SerializerFactory())();
20
21
        /**  @var GetOfficesResponse $response */
22
        return $serializer->deserialize($json, GetOfficesResponse::class, 'json');
23
    }
24
}
25