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

PointMapper::awake()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 6
cts 6
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 2
crap 4
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\Point;
9
use PeekAndPoke\Component\Slumber\Annotation\Slumber\GeoJson\AsPoint;
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 PointMapper extends AbstractPropertyMapper
18
{
19
    /** @var AsPoint */
20
    private $options;
21
22
    /**
23
     * @param AsPoint $options
24
     */
25 27
    public function __construct(AsPoint $options)
26
    {
27 27
        $this->options = $options;
28 27
    }
29
30
    /**
31
     * @return AsPoint
32
     */
33 1
    public function getOptions()
34
    {
35 1
        return $this->options;
36
    }
37
38
    /**
39
     * @param Slumberer $slumberer
40
     * @param Point     $value
41
     *
42
     * @return mixed
43
     */
44 10
    public function slumber(Slumberer $slumberer, $value)
45
    {
46 10
        if (! $value instanceof Point) {
47 9
            return null;
48
        }
49
50
        return [
51 1
            'type'        => Point::TYPE,
52
            'coordinates' => [
53 1
                $value->getLng(),
54 1
                $value->getLat(),
55
            ],
56
        ];
57
    }
58
59
    /**
60
     * @param Awaker $awaker
61
     * @param mixed  $value
62
     *
63
     * @return Point
64
     */
65 13
    public function awake(Awaker $awaker, $value)
66
    {
67
        /** @noinspection NotOptimalIfConditionsInspection */
68 13
        if (isset($value['type'], $value['coordinates']) && $value['type'] === 'Point') {
69
70 4
            $coords = $value['coordinates'];
71
72 4
            if (\count($coords) === 2) {
73 2
                return Point::fromLngLat($coords[0], $coords[1]);
74
            }
75
        }
76
77 11
        return null;
78
    }
79
}
80