Completed
Push — master ( ed2425...d8adec )
by Daryl
01:55
created

Marker_Model::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace Clubdeuce\WPLib\Components\GoogleMaps;
4
5
/**
6
 * Class Marker_Model
7
 * @package Clubdeuce\WPLib\Components\GoogleMaps
8
 */
9
class Marker_Model extends \WPLib_Model_Base {
10
11
    /**
12
     * @var string
13
     */
14
    protected $_address;
15
16
    /**
17
     * @var Geocoder
18
     */
19
    protected $_geocoder;
20
21
    /**
22
     * @var string
23
     */
24
    protected $_label;
25
26
    /**
27
     * @var Location
28
     */
29
    protected $_location;
30
31
    /**
32
     * @var string
33
     */
34
    protected $_title;
35
36
    /**
37
     * Marker_Model constructor.
38
     * @param array $args
39
     */
40
    function __construct( $args = array() ) {
41
42
        $args = wp_parse_args( $args, array(
1 ignored issue
show
Coding Style introduced by
Consider using a different name than the parameter $args. This often makes code more readable.
Loading history...
43
            'address' => '',
44
            'label'   => null,
45
            'title'   => '',
46
        ) );
47
48
        parent::__construct( $args );
49
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    function label() {
56
        return $this->_label;
57
    }
58
59
    /**
60
     * @return float
61
     */
62
    function latitude() {
63
        return $this->location()->latitude();
64
    }
65
66
    /**
67
     * @return Location
68
     */
69
    function location() {
70
        if ( ! is_object( $this->_location ) ) {
71
            $this->_location = $this->_geocoder()->geocode( $this->_address );
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->_geocoder()->geocode($this->_address) can also be of type object<WP_Error>. However, the property $_location is declared as type object<Clubdeuce\WPLib\C...ts\GoogleMaps\Location>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
72
        }
73
        return $this->_location;
74
    }
75
76
    /**
77
     * @return float
78
     */
79
    function longitude() {
80
        return $this->location()->longitude();
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    function title() {
87
        return $this->_title;
88
    }
89
90
    /**
91
     * @return Geocoder
92
     */
93
    private function _geocoder() {
94
        if (! is_object( $this->_geocoder ) ) {
95
            $this->_geocoder = new Geocoder();
96
        }
97
98
        return $this->_geocoder;
99
    }
100
}
101