Passed
Pull Request — master (#16)
by Daryl
01:42
created

Map_View::the_map_params()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Clubdeuce\WPGoogleMaps;
4
5
/**
6
 * Class Map_View
7
 * @package Clubdeuce\WPGoogleMaps
8
 */
9
class Map_View {
10
11
	/**
12
	 * @var Map
13
	 */
14
	protected $_model;
15
16
	/**
17
	 * Map_View constructor.
18
	 *
19
	 * @param Map_Model $model
20
	 */
21 3
	public function __construct( $model ) {
22
		
23 3
		$this->_model = $model;
0 ignored issues
show
Documentation Bug introduced by
It seems like $model of type Clubdeuce\WPGoogleMaps\Map_Model is incompatible with the declared type Clubdeuce\WPGoogleMaps\Map of property $_model.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24
		
25 3
	}
26
27
	/**
28
	 * @param array $args
29
	 */
30 1
	public function the_map( $args = array() ) { 
31
		
32 1
		$args = wp_parse_args( $args, array(
33 1
			'template' => Google_Maps::source_dir() . '/templates/map-view.php',
34
		) );
35
36 1
		require $args['template'];
37
		
38 1
	}
39
40 1
	public function the_map_params() {
41
42 1
		echo json_encode( $this->_map_params() );
43
44 1
	}
45
46
	/**
47
	 * @return array
48
	 */
49 2
	protected function _map_params() {
50
51 2
		$model  = $this->_model;
52
		$params = array(
53 2
			'center'                   => $model->center(),
54 2
			'styles'                   => $model->styles(),
55 2
			'zoom'                     => $model->zoom(),
56
		);
57
58 2
		return array_filter( $params );
59
60
	}
61
62
	/**
63
	 * @return array
64
	 */
65 1
	protected function _make_markers_args() {
66
67 1
		$marker_args = array();
68
69 1
		foreach ( $this->_model->markers() as $marker ) {
0 ignored issues
show
Bug introduced by
The method markers() does not exist on Clubdeuce\WPGoogleMaps\Map. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
		foreach ( $this->_model->/** @scrutinizer ignore-call */ markers() as $marker ) {
Loading history...
70
			$args = array(
71 1
				'position'  => $marker->position(),
72 1
				'title'     => $marker->title(),
73
			);
74
75 1
			if ( ! empty( $label = self::_make_label_args( $marker->label() ) ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The method Clubdeuce\WPGoogleMaps\M...iew::_make_label_args() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

75
			if ( ! empty( $label = self::/** @scrutinizer ignore-call */ _make_label_args( $marker->label() ) ) ) {
Loading history...
76 1
				$args['label'] =  $label;
77
			}
78
79 1
			$marker_args[] = $args;
80
		}
81
82 1
		return array_filter( $marker_args );
83
84
	}
85
86
	/**
87
	 * @param  Marker_Label $label
88
	 *
89
	 * @return array
90
	 */
91 1
	protected function _make_label_args( $label ) {
92
93 1
		$args = array();
94
95 1
		if ( ! empty( $label->text() ) ) {
96
			$args = array(
97 1
				'color'      => $label->color(),
98 1
				'fontFamily' => $label->font_family(),
99 1
				'fontSize'   => $label->font_size(),
100 1
				'fontWeight' => $label->font_weight(),
101 1
				'text'       => $label->text(),
102
			);
103
		}
104
105 1
		return $args;
106
107
	}
108
109
	/**
110
	 * @return array
111
	 */
112 1
	protected function _make_info_windows() {
113
114 1
		$windows = array();
115
116
		/**
117
		 * @var Marker $marker
118
		 */
119 1
		foreach( $this->_model->markers() as $marker ) {
120 1
			$info_window = $marker->info_window();
121 1
			$windows[]   = array(
122 1
				'content'      => $info_window->content(),
123 1
				'pixel_offset' => $info_window->pixel_offset(),
124 1
				'position'     => $info_window->position(),
125 1
				'max_width'    => $info_window->max_width(),
126
			);
127
		}
128
129 1
		return $windows;
130
131
	}
132
	
133
}