Completed
Push — master ( 5e9615...0f6ac6 )
by WEBEWEB
02:26
created

RegionResponseDeserializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 41
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deserializeListeRegionsResponse() 0 16 3
A deserializeRegion() 0 9 1
1
<?php
2
3
/*
4
 * This file is part of the geo-api-library package.
5
 *
6
 * (c) 2020 WEBEWEB
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
namespace WBW\Library\GeoAPI\Serializer;
13
14
use WBW\Library\Core\Argument\Helper\ArrayHelper;
15
use WBW\Library\GeoAPI\Model\Region;
16
use WBW\Library\GeoAPI\Model\Response\Region\ListeRegionsResponse;
17
18
/**
19
 * Région response deserializer.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Library\GeoAPI\Serializer
23
 */
24
class RegionResponseDeserializer {
25
26
    /**
27
     * Deserializes a liste régions response.
28
     *
29
     * @param string $rawResponse The raw response.
30
     * @return ListeRegionsResponse Returns the liste régions response.
31
     */
32
    public static function deserializeListeRegionsResponse($rawResponse) {
33
34
        $model = new ListeRegionsResponse();
35
        $model->setRawResponse($rawResponse);
36
37
        $response = json_decode($rawResponse, true);
38
        if (null === $response) {
39
            return $model;
40
        }
41
42
        foreach ($response as $current) {
43
            $model->addRegion(static::deserializeRegion($current));
44
        }
45
46
        return $model;
47
    }
48
49
    /**
50
     * Deserializes a région.
51
     *
52
     * @param array $response The response.
53
     * @return Region Returns the région.
54
     */
55
    public static function deserializeRegion(array $response) {
56
57
        $model = new Region();
58
        $model->setCode(ArrayHelper::get($response, "code"));
59
        $model->setNom(ArrayHelper::get($response, "nom"));
60
        $model->setScore(ArrayHelper::get($response, "_score"));
61
62
        return $model;
63
    }
64
}