RetrieveReservationDetailParametersFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromJson() 0 9 2
A createFromArray() 0 3 1
1
<?php
2
3
namespace TK\API\ValueObject\Factory;
4
5
use TK\API\Exception\InvalidArgumentException;
6
use TK\API\ValueObject\RetrieveReservationDetailParameters;
7
8
class RetrieveReservationDetailParametersFactory implements ValueObjectFactoryInterface
9
{
10
    /**
11
     * @param array $parameters
12
     * @return RetrieveReservationDetailParameters
13
     * @throws \Exception
14
     */
15
    public static function createFromArray(array $parameters): RetrieveReservationDetailParameters
16
    {
17
         return new RetrieveReservationDetailParameters($parameters['UniqueId'], $parameters['Surname']);
18
    }
19
20
21
    /**
22
     * @param string $json
23
     * @return RetrieveReservationDetailParameters
24
     * @throws InvalidArgumentException
25
     * @throws \Exception
26
     */
27
    public static function createFromJson(string $json): RetrieveReservationDetailParameters
28
    {
29
        $parameters = json_decode($json, (bool)JSON_OBJECT_AS_ARRAY);
30
        if (json_last_error() !== JSON_ERROR_NONE) {
31
            throw new InvalidArgumentException(
32
                'RetrieveReservationDetailParametersFactory Error: ' . json_last_error_msg()
33
            );
34
        }
35
        return self::createFromArray($parameters);
36
    }
37
}
38