Completed
Pull Request — master (#22)
by Daryl
02:28
created

Marker_Model   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 94.74%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
wmc 8
c 8
b 0
f 0
lcom 1
cbo 5
dl 18
loc 72
ccs 18
cts 19
cp 0.9474
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A location() 0 5 1
A has_marker() 0 5 1
A label() 0 5 1
A info_window() 0 8 1
A __call() 18 18 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Clubdeuce\WPLib\Components\GoogleMaps;
4
use Clubdeuce\WPGoogleMaps\Marker as WPMarker;
5
6
/**
7
 * Class Marker_Model
8
 * @package Clubdeuce\WPLib\Components\GoogleMaps
9
 *
10
 * @method \Clubdeuce\WPGoogleMaps\Marker marker()
11
 */
12
class Marker_Model extends Model_Base {
13
14
	/**
15
	 * @var WPMarker
16
	 */
17
    protected $_marker;
18
19
	/**
20
	 * @return bool
21
	 */
22 1
	function has_marker() {
23
24 1
		return $this->_has( '_marker' );
25
26
	}
27
28
	/**
29
	 * @return Location
30
	 */
31 2
	function location() {
32
33 2
		return new Location( array( 'location' => $this->marker()->location() ) );
34
35
	}
36
37
	/**
38
	 * @return Marker_Label
39
	 */
40 1
	function label() {
41
42 1
		return new Marker_Label( array( 'label' => $this->marker()->label() ) );
43
44
	}
45
46
	/**
47
	 * @return Info_Window
48
	 */
49 1
	function info_window() {
50
51 1
		$window = new Info_Window( array( 'info_window' => $this->marker()->info_window() ) );
52 1
		$window->set_position( array( 'lat' => $this->marker()->latitude(), 'lng' => $this->marker()->longitude()));
0 ignored issues
show
Unused Code introduced by
The call to Info_Window::set_position() has too many arguments starting with array('lat' => $this->ma...>marker()->longitude()).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
53
54 1
		return $window;
55
56
	}
57
58
	/**
59
	 * @param string $method_name
60
	 * @param array $args
61
	 *
62
	 * @return mixed|null
63
	 */
64 1 View Code Duplication
	function __call( $method_name, $args ) {
0 ignored issues
show
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...
65
66
		do {
67 1
			$value = parent::__call( $method_name, $args );
68
69 1
			if ( $value ) {
70 1
				break;
71
			}
72
73 1
			if ( $this->has_marker() ) {
74 1
				$value = call_user_func_array( array( $this->marker(), $method_name ), $args );
75 1
				break;
76
			}
77
		} while ( false );
78
79 1
		return $value;
80
81
	}
82
83
}
84