Completed
Push — master ( 643987...ab0124 )
by Daryl
01:58
created

Marker_Model::latlng_object()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
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 Location
23
     */
24
    protected $_location;
25
26
    /**
27
     * @var string
28
     */
29
    protected $_title;
30
31
    /**
32
     * Marker_Model constructor.
33
     * @param array|object|string $address
0 ignored issues
show
Bug introduced by
There is no parameter named $address. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
34
     * @param array $args
35
     */
36
    function __construct( $args = array() ) {
37
38
        $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...
39
            'address' => '',
40
            'title'   => '',
41
        ) );
42
43
        parent::__construct( $args );
44
45
    }
46
47
    /**
48
     * @return float
49
     */
50
    function latitude() {
51
        return $this->location()->latitude();
0 ignored issues
show
Documentation Bug introduced by
The method latitude does not exist on object<Clubdeuce\WPLib\C...ts\GoogleMaps\Location>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
52
    }
53
54
    /**
55
     * @return Location
56
     */
57
    function location() {
58
        if ( ! is_object( $this->_location ) ) {
59
            $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...
60
        }
61
        return $this->_location;
62
    }
63
64
    /**
65
     * @return float
66
     */
67
    function longitude() {
68
        return $this->location()->longitude();
0 ignored issues
show
Documentation Bug introduced by
The method longitude does not exist on object<Clubdeuce\WPLib\C...ts\GoogleMaps\Location>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    function title() {
75
        return $this->_title;
76
    }
77
78
    /**
79
     * @return Geocoder
80
     */
81
    private function _geocoder() {
82
        if (! is_object($this->_geocoder)) {
83
            $this->_geocoder = new Geocoder();
84
        }
85
86
        return $this->_geocoder;
87
    }
88
}
89