Completed
Push — master ( 1a7397...8cd977 )
by Daryl
04:36
created

Marker::title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

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 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Clubdeuce\WPGoogleMaps;
4
5
/**
6
 * Class Marker
7
 * @package Clubdeuce\WPGoogleMaps
8
 */
9
class Marker extends Model_Base {
10
11
	/**
12
	 * @var string
13
	 */
14
	protected $_address;
15
16
	/**
17
	 * @var Geocoder
18
	 */
19
	protected $_geocoder;
20
21
	/**
22
	 * @var Info_Window
23
	 */
24
	protected $_info_window;
25
26
	/**
27
	 * @var Marker_Label
28
	 */
29
	protected $_label;
30
31
	/**
32
	 * @var double
33
	 */
34
	protected $_latitude = null;
35
36
	/**
37
	 * @var double
38
	 */
39
	protected $_longitude;
40
41
	/**
42
	 * @var Location|\WP_Error
43
	 */
44
	protected $_location;
45
46
	/**
47
	 * @var string
48
	 */
49
	protected $_title;
50
51
	/**
52
	 * @var array
53
	 */
54
	protected $_extra_args = array();
55
56
	/**
57
	 * Marker_Model constructor.
58
	 * @param array $args
59
	 */
60 2
	function __construct( $args = array() ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
61
62 2
		$args = wp_parse_args( $args, array(
63 2
			'address'     => '',
64 2
			'info_window' => '',
65 2
			'label'       => new Marker_Label(),
66 2
			'title'       => '',
67
			'latitude'    => null,
68
			'longitude'   => null,
69
		) );
70
71 2
		if ( empty( $args['info_window'] ) ) {
72 2
			$args['info_window'] = new Info_Window( array(
73 2
				'position' => array( 'lat' => $args['latitude'], 'lng' => $args['longitude'] ),
74
			) );
75
		}
76
77 2
		parent::__construct( $args );
78
79 2
	}
80
81
	/**
82
	 * @return Info_Window
83
	 */
84 2
	function info_window() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
85
86 2
		return $this->_info_window;
87
88
	}
89
90
	/**
91
	 * @return Marker_Label
92
	 */
93 1
	function label() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
94
95 1
		if ( is_string( $this->_label ) ) {
96 1
			$this->_label = new Marker_Label( array( 'text' => $this->_label ) );
97
		}
98
99 1
		return $this->_label;
100
101
	}
102
103
	/**
104
	 * @return double
105
	 */
106 1 View Code Duplication
	function latitude() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
108 1
		if ( is_null( $this->_latitude ) && ! is_wp_error( $this->location() ) ) {
109 1
			$this->_latitude = $this->location()->latitude();
110
		}
111 1
		return doubleval( $this->_latitude );
112
	}
113
114
	/**
115
	 * @return Location|\WP_Error
116
	 */
117 2
	function location() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
118 2
		if ( ! is_object( $this->_location ) ) {
119 2
			$this->_location = $this->_geocoder()->geocode( $this->_address );
120
		}
121 2
		return $this->_location;
122
	}
123
124
	/**
125
	 * @return double
126
	 */
127 1 View Code Duplication
	function longitude() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
129 1
		if ( is_null( $this->_longitude ) && ! is_wp_error( $this->location() ) ) {
130 1
			$this->_longitude = doubleval( $this->location()->longitude() );
131
		}
132 1
		return doubleval( $this->_longitude );
133
	}
134
135
	/**
136
	 * Get the position of this marker. An array with key/value pairs of lat and lng.
137
	 *
138
	 * @return array
139
	 */
140 1
	function position() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
141
142 1
		return array( 'lat' => $this->latitude(), 'lng' => $this->longitude() );
143
144
	}
145
146
	/**
147
	 * @return string
148
	 */
149 1
	function title() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
150 1
		return $this->_title;
151
	}
152
153
	/**
154
	 * @param  array $args
155
	 * @return array
156
	 */
157 1
	function marker_args( $args = array() ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
158
159 1
		$args = array_merge( $args, $this->_extra_args );
160
161 1
		$args = wp_parse_args( $args, array(
162 1
			'position'  => $this->position(),
163 1
			'label'     => $this->label()->options(),
164 1
			'title'     => $this->title(),
165
		) );
166
167 1
		return $args;
168
169
	}
170
171
	/**
172
	 * @return Geocoder
173
	 */
174 2
	protected function _geocoder() {
175 2
		if (! is_a( $this->_geocoder, '\Clubdeuce\WPGoogleMaps\Geocoder' ) ) {
176 1
			$this->_geocoder = new Geocoder();
177
		}
178
179 2
		return $this->_geocoder;
180
	}
181
182
}
183