1
|
|
|
<?php namespace Arcanedev\GeoLocation\Entities\Measures; |
2
|
|
|
|
3
|
|
|
use Arcanedev\GeoLocation\Traits\CanBeJsonable; |
4
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
5
|
|
|
use Illuminate\Contracts\Support\Jsonable; |
6
|
|
|
use JsonSerializable; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class AbstractMeasure |
10
|
|
|
* |
11
|
|
|
* @package Arcanedev\GeoLocation\Entities\Measures |
12
|
|
|
* @author ARCANEDEV <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
abstract class AbstractMeasure implements Arrayable, Jsonable, JsonSerializable |
15
|
|
|
{ |
16
|
|
|
/* ----------------------------------------------------------------- |
17
|
|
|
| Traits |
18
|
|
|
| ----------------------------------------------------------------- |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use CanBeJsonable; |
22
|
|
|
|
23
|
|
|
/* ----------------------------------------------------------------- |
24
|
|
|
| Properties |
25
|
|
|
| ----------------------------------------------------------------- |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The text value. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $text; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The numeric value. |
37
|
|
|
* |
38
|
|
|
* @var int |
39
|
|
|
*/ |
40
|
|
|
protected $value; |
41
|
|
|
|
42
|
|
|
/* ----------------------------------------------------------------- |
43
|
|
|
| Main Methods |
44
|
|
|
| ----------------------------------------------------------------- |
45
|
|
|
*/ |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* AbstractMeasure constructor. |
49
|
|
|
* |
50
|
|
|
* @param string $text |
51
|
|
|
* @param float|int $value |
52
|
|
|
*/ |
53
|
87 |
|
public function __construct($text, $value) |
54
|
|
|
{ |
55
|
87 |
|
$this->text = $text; |
56
|
87 |
|
$this->value = $value; |
|
|
|
|
57
|
87 |
|
} |
58
|
|
|
|
59
|
|
|
/* ----------------------------------------------------------------- |
60
|
|
|
| Getters & Setters |
61
|
|
|
| ----------------------------------------------------------------- |
62
|
|
|
*/ |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the text (alias). |
66
|
|
|
* |
67
|
|
|
* @see getText |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
45 |
|
public function text() |
72
|
|
|
{ |
73
|
45 |
|
return $this->getText(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the text. |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
45 |
|
public function getText() |
82
|
|
|
{ |
83
|
45 |
|
return $this->text; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the value (alias). |
88
|
|
|
* |
89
|
|
|
* @see getValue |
90
|
|
|
* |
91
|
|
|
* @return float|int |
92
|
|
|
*/ |
93
|
48 |
|
public function value() |
94
|
|
|
{ |
95
|
48 |
|
return $this->getValue(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get the value. |
100
|
|
|
* |
101
|
|
|
* @return float|int |
102
|
|
|
*/ |
103
|
48 |
|
public function getValue() |
104
|
|
|
{ |
105
|
48 |
|
return $this->value; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/* ----------------------------------------------------------------- |
109
|
|
|
| Main Methods |
110
|
|
|
| ----------------------------------------------------------------- |
111
|
|
|
*/ |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Make a distance instance. |
115
|
|
|
* |
116
|
|
|
* @param string $text |
117
|
|
|
* @param int $value |
118
|
|
|
* |
119
|
|
|
* @return static |
120
|
|
|
*/ |
121
|
75 |
|
public static function make($text, $value) |
122
|
|
|
{ |
123
|
75 |
|
return new static($text, $value); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Make a distance instance from array. |
128
|
|
|
* |
129
|
|
|
* @param array $data |
130
|
|
|
* |
131
|
|
|
* @return static |
132
|
|
|
*/ |
133
|
57 |
|
public static function makeFromArray(array $data) |
134
|
|
|
{ |
135
|
57 |
|
return static::make($data['text'], $data['value']); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get the instance as an array. |
140
|
|
|
* |
141
|
|
|
* @return array |
142
|
|
|
*/ |
143
|
24 |
|
public function toArray() |
144
|
|
|
{ |
145
|
|
|
return [ |
146
|
24 |
|
'text' => $this->text(), |
147
|
24 |
|
'value' => $this->value(), |
148
|
|
|
]; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
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 theid
property of an instance of theAccount
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.