Completed
Pull Request — master (#22)
by Daryl
01:32
created

Marker_Model::__call()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 20
loc 20
ccs 9
cts 10
cp 0.9
rs 9.2
cc 4
eloc 11
nc 3
nop 2
crap 4.016
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
Bug introduced by
The method set_position() does not exist on Clubdeuce\WPLib\Components\GoogleMaps\Info_Window. Did you maybe mean position()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

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 1
		$value = null;
0 ignored issues
show
Unused Code introduced by
$value is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
67
68
		do {
69 1
			$value = parent::__call( $method_name, $args );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $value is correct as parent::__call($method_name, $args) (which targets Clubdeuce\WPLib\Componen...ps\Model_Base::__call()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
70
71 1
			if ( $value ) {
72 1
				break;
73
			}
74
75 1
			if ( $this->has_marker() ) {
76 1
				$value = call_user_func_array( array( $this->marker(), $method_name ), $args );
77 1
				break;
78
			}
79
		} while ( false );
80
81 1
		return $value;
82
83
	}
84
85
}
86