Map   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 155
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 6

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A marker() 0 15 1
A shape() 0 27 5
A render() 0 12 1
A getMarkers() 0 4 1
A getShapes() 0 4 1
A getOptions() 0 4 1
1
<?php
2
3
namespace Cornford\Googlmapper\Models;
4
5
use Cornford\Googlmapper\Contracts\ModelingInterface;
6
use Illuminate\View\Factory as View;
7
8
class Map implements ModelingInterface
9
{
10
    public const SHAPE_POLYLINE = 'polyline';
11
    public const SHAPE_POLYGON = 'polygon';
12
    public const SHAPE_RECTANGLE = 'rectangle';
13
    public const SHAPE_CIRCLE = 'circle';
14
15
    /**
16
     * Options.
17
     *
18
     * @var array
19
     */
20
    protected $options = [];
21
22
    /**
23
     * Markers.
24
     *
25
     * @var array
26
     */
27
    protected $markers = [];
28
29
    /**
30
     * Shapes.
31
     *
32
     * @var array
33
     */
34
    protected $shapes = [];
35
36
    /**
37
     * Public constructor.
38
     *
39
     * @param array $parameters
40
     */
41
    public function __construct(array $parameters = [])
42
    {
43
        $this->options = $parameters;
44
45
        if (isset($this->options['marker']) && $this->options['marker']) {
46
            $this->marker($this->options['latitude'], $this->options['longitude'], $this->options);
47
        }
48
    }
49
50
    /**
51
     * Add a map marker to the markers bag.
52
     *
53
     * @param float $latitude
54
     * @param float $longitude
55
     * @param array $options
56
     *
57
     * @return void
58
     */
59
    public function marker($latitude, $longitude, array $options = [])
60
    {
61
        $parameters = [
62
            'latitude' => $latitude,
63
            'longitude' => $longitude,
64
        ];
65
66
        $parameters = array_replace_recursive(
67
            $this->options,
68
            $parameters,
69
            $options
70
        );
71
72
        $this->markers[] = new Marker($parameters);
73
    }
74
75
    /**
76
     * Add a map shape to the shapes bag.
77
     *
78
     * @param string $type
79
     * @param array  $coordinates
80
     * @param array  $options
81
     *
82
     * @return void
83
     */
84
    public function shape($type, $coordinates, array $options = [])
85
    {
86
        $parameters = [
87
            'coordinates' => $coordinates
88
        ];
89
90
        $parameters = array_replace_recursive(
91
            $this->options,
92
            $parameters,
93
            $options
94
        );
95
96
        switch ($type) {
97
            case self::SHAPE_POLYLINE:
98
                $this->shapes[] = new Polyline($parameters);
99
                break;
100
            case self::SHAPE_POLYGON:
101
                $this->shapes[] = new Polygon($parameters);
102
                break;
103
            case self::SHAPE_RECTANGLE:
104
                $this->shapes[] = new Rectangle($parameters);
105
                break;
106
            case self::SHAPE_CIRCLE:
107
                $this->shapes[] = new Circle($parameters);
108
                break;
109
        }
110
    }
111
112
    /**
113
     * Render the model item.
114
     *
115
     * @param int  $identifier
116
     * @param View $view
117
     *
118
     * @return string
119
     */
120
    public function render($identifier, View $view)
121
    {
122
        $options = $this->options;
123
        $options['markers'] = $this->getMarkers();
124
        $options['shapes'] = $this->getShapes();
125
126
        return $view->make('googlmapper::map')
0 ignored issues
show
Bug introduced by
The method withOptions() does not seem to exist on object<Illuminate\Contracts\View\View>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
127
            ->withOptions($options)
128
            ->withId($identifier)
129
            ->withView($view)
130
            ->render();
131
    }
132
133
    /**
134
     * Return marker items.
135
     *
136
     * @return array
137
     */
138
    public function getMarkers()
139
    {
140
        return $this->markers;
141
    }
142
143
    /**
144
     * Return shape items.
145
     *
146
     * @return array
147
     */
148
    public function getShapes()
149
    {
150
        return $this->shapes;
151
    }
152
153
    /**
154
     * Get the model options.
155
     *
156
     * @return array
157
     */
158
    public function getOptions()
159
    {
160
        return $this->options;
161
    }
162
}
163