Coordinates::setLongitude()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace LeKoala\GeoTools\Models;
4
5
/**
6
 * A global coordinates model
7
 */
8
class Coordinates
9
{
10
    /**
11
     * @var float
12
     */
13
    protected $latitude;
14
15
    /**
16
     * @var float
17
     */
18
    protected $longitude;
19
20
    /**
21
     * @param string|float $latitude
22
     * @param string|float $longitude
23
     */
24
    public function __construct($latitude = null, $longitude = null)
25
    {
26
        if ($latitude && !is_float($latitude)) {
27
            $latitude = floatval($latitude);
28
        }
29
        if ($longitude && !is_float($longitude)) {
30
            $longitude = floatval($longitude);
31
        }
32
        if ($latitude && $longitude) {
33
            $this->latitude = $latitude;
0 ignored issues
show
Documentation Bug introduced by
It seems like $latitude can also be of type string. However, the property $latitude is declared as type double. 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...
34
            $this->longitude = $longitude;
0 ignored issues
show
Documentation Bug introduced by
It seems like $longitude can also be of type string. However, the property $longitude is declared as type double. 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...
35
        }
36
    }
37
38
    /**
39
     * Create from a given source (array, pairs)
40
     *
41
     * Coordinates::create('lat,lon')
42
     * Coordinates::create('lat','lon')
43
     * Coordinates::create(['lat','lon'])
44
     *
45
     * @param mixed $source
46
     * @param array<string> $more
47
     * @return self
48
     */
49
    public static function create($source, ...$more)
50
    {
51
        if (!is_array($source)) {
52
            $source = explode(',', $source);
53
        }
54
        if (!empty($more)) {
55
            $source = array_merge($source, $more);
56
        }
57
        return new self($source[0], $source[1]);
58
    }
59
60
    /**
61
     * Get the value of latitude
62
     */
63
    public function getLatitude(): ?float
64
    {
65
        return $this->latitude;
66
    }
67
68
    /**
69
     * Set the value of latitude
70
     *
71
     * @return $this
72
     */
73
    public function setLatitude(float $latitude)
74
    {
75
        $this->latitude = $latitude;
76
        return $this;
77
    }
78
79
    /**
80
     * Get the value of longitude
81
     */
82
    public function getLongitude(): ?float
83
    {
84
        return $this->longitude;
85
    }
86
87
    /**
88
     * Set the value of longitude
89
     *
90
     * @return $this
91
     */
92
    public function setLongitude(float $longitude)
93
    {
94
        $this->longitude = $longitude;
95
        return $this;
96
    }
97
}
98