Test Failed
Push — main ( 33bb6d...d24563 )
by Vasil
03:10
created

GetCitiesResponseFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 2
1
<?php
2
3
namespace VasilDakov\Econt\Response;
4
5
use VasilDakov\Econt\Exception\InvalidArgumentException;
6
use VasilDakov\Econt\Serializer\SerializerFactory;
7
8
use function json_decode;
9
use function json_last_error;
10
11
class GetCitiesResponseFactory
12
{
13
    public function __invoke(string $json): GetCitiesResponse
14
    {
15
        /** @var array $array */
16
        $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...
17
18
        if (json_last_error() !== JSON_ERROR_NONE) {
19
            throw new InvalidArgumentException('Invalid or malformed JSON');
20
        }
21
22
        $serializer = (new SerializerFactory())();
23
24
        /**  @var GetCitiesResponse $response */
25
        return $serializer->deserialize($json, GetCitiesResponse::class, 'json');
26
    }
27
}
28