Completed
Push — master ( af7add...6e606c )
by Karsten
02:11
created

LineStringMapper::awake()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 2
crap 3
1
<?php
2
/**
3
 * File was created 03.03.2016 13:36
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Core\Codec\Property\GeoJson;
7
8
use PeekAndPoke\Component\GeoJson\LineString;
9
use PeekAndPoke\Component\Slumber\Annotation\Slumber\GeoJson\AsLineString;
10
use PeekAndPoke\Component\Slumber\Core\Codec\Awaker;
11
use PeekAndPoke\Component\Slumber\Core\Codec\Property\AbstractPropertyMapper;
12
use PeekAndPoke\Component\Slumber\Core\Codec\Slumberer;
13
14
/**
15
 * @author Karsten J. Gerber <[email protected]>
16
 */
17
class LineStringMapper extends AbstractPropertyMapper
18
{
19
    /** @var AsLineString */
20
    private $options;
21
22 22
    public function __construct(AsLineString $options)
23
    {
24 22
        $this->options = $options;
25 22
    }
26
27
    /**
28
     * @return AsLineString
29
     */
30 1
    public function getOptions()
31
    {
32 1
        return $this->options;
33
    }
34
35
    /**
36
     * @param Slumberer  $slumberer
37
     * @param LineString $value
38
     *
39
     * @return mixed
40
     */
41 8
    public function slumber(Slumberer $slumberer, $value)
42
    {
43 8
        if (! $value instanceof LineString) {
44 6
            return null;
45
        }
46
47
        return [
48 2
            'type'        => 'LineString',
49 2
            'coordinates' => $value->getCoordinates(),
50
        ];
51
    }
52
53
    /**
54
     * @param Awaker $awaker
55
     * @param mixed  $value
56
     *
57
     * @return LineString
58
     */
59 13
    public function awake(Awaker $awaker, $value)
60
    {
61
        /** @noinspection NotOptimalIfConditionsInspection */
62 13
        if (isset($value['type'], $value['coordinates']) && $value['type'] === 'LineString') {
63 4
            return LineString::fromLngLats($value['coordinates']);
64
        }
65
66 9
        return null;
67
    }
68
}
69