1 | <?php |
||
2 | |||
3 | namespace BultonFr\NMEA\Frames; |
||
4 | |||
5 | use \DateTime; |
||
6 | use \DateTimeZone; |
||
7 | |||
8 | /** |
||
9 | * Define the parser system for RMC frame type |
||
10 | * |
||
11 | * @package BultonFr\NMEA |
||
12 | * @author Vermeulen Maxime <[email protected]> |
||
13 | * @link http://www.gpsinformation.org/dale/nmea.htm#RMC |
||
14 | * @link http://aprs.gids.nl/nmea/#rmc |
||
15 | */ |
||
16 | class RMC extends \BultonFr\NMEA\Frame |
||
17 | { |
||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | protected $frameType = 'RMC'; |
||
22 | |||
23 | /** |
||
24 | * Format : --RMC,hhmmss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a,m |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | protected $frameRegex = '/^' |
||
28 | .'([A-Z]{2}[A-Z]{3}),' //Equipment and trame type |
||
29 | .'(\d{6})(\.\d{2,3})?,' //Time (UTC) |
||
30 | .'(A|V),' //Status A=active or V=Void |
||
31 | .'([0-9\.]+),' //Latitude |
||
32 | .'(N|S),' //N or S (North or South) |
||
33 | .'([0-9\.]+),' //Longitude |
||
34 | .'(E|W),' //E or W (East or West) |
||
35 | .'([0-9\.]*),' //Speed over ground in knots |
||
36 | .'([0-9\.]*),' //Track angle in degrees True |
||
37 | .'(\d{6}),' //Date |
||
38 | .'([0-9\.]*),' //Magnetic variation degrees |
||
39 | //(Easterly var. subtracts from true course) |
||
40 | .'(E|W)?' //E or W (East or West) |
||
41 | .'(,(A|D|E|N|S)?)?' //Mode indicator (NMEA >= 2.3) |
||
42 | .'$/m'; |
||
43 | |||
44 | /** |
||
45 | * @var \DateTime $utcTime Time of the line (UTC) |
||
46 | */ |
||
47 | protected $utcTime; |
||
48 | |||
49 | /** |
||
50 | * @var string $status Status A=active or V=Void |
||
51 | */ |
||
52 | protected $status; |
||
53 | |||
54 | /** |
||
55 | * @var string $latitude Latitude |
||
56 | */ |
||
57 | protected $latitude; |
||
58 | |||
59 | /** |
||
60 | * @var string $latitudeDirection N or S (North or South) |
||
61 | */ |
||
62 | protected $latitudeDirection; |
||
63 | |||
64 | /** |
||
65 | * @var string $longitude Longitude |
||
66 | */ |
||
67 | protected $longitude; |
||
68 | |||
69 | /** |
||
70 | * @var string $longitudeDirection E or W (East or West) |
||
71 | */ |
||
72 | protected $longitudeDirection; |
||
73 | |||
74 | /** |
||
75 | * @var string $speed Speed over ground in knots |
||
76 | */ |
||
77 | protected $speed; |
||
78 | |||
79 | /** |
||
80 | * @var string $angle Track angle in degrees True |
||
81 | */ |
||
82 | protected $angle; |
||
83 | |||
84 | /** |
||
85 | * @var \DateTime $utcDate Date of the line (UTC) |
||
86 | */ |
||
87 | protected $utcDate; |
||
88 | |||
89 | /** |
||
90 | * @var string $magneticVariation Magnetic variation degrees |
||
91 | * (Easterly var. subtracts from true course) |
||
92 | */ |
||
93 | protected $magneticVariation; |
||
94 | |||
95 | /** |
||
96 | * @var string $magneticVariationDirection E or W (East or West) |
||
97 | */ |
||
98 | protected $magneticVariationDirection; |
||
99 | |||
100 | /** |
||
101 | * @var string $mode Mode indicator (NMEA >= 2.3) |
||
102 | * * A : autonomous |
||
103 | * * D : differential |
||
104 | * * E : Estimated |
||
105 | * * N : not valid |
||
106 | * * S : Simulator |
||
107 | */ |
||
108 | protected $mode; |
||
109 | |||
110 | /** |
||
111 | * Getter to property utcTime |
||
112 | * |
||
113 | * @return \DateTime |
||
114 | */ |
||
115 | public function getUtcTime() |
||
116 | { |
||
117 | 1 | return $this->utcTime; |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * Getter to property status |
||
122 | * |
||
123 | * @return float |
||
124 | */ |
||
125 | public function getStatus() |
||
126 | { |
||
127 | 1 | return $this->status; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Getter to property latitude |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getLatitude() |
||
136 | { |
||
137 | 1 | return $this->latitude; |
|
138 | } |
||
139 | |||
140 | /** |
||
141 | * Getter to property latitudeDirection |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | public function getLatitudeDirection() |
||
146 | { |
||
147 | 1 | return $this->latitudeDirection; |
|
148 | } |
||
149 | |||
150 | /** |
||
151 | * Getter to property longitude |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getLongitude() |
||
156 | { |
||
157 | 1 | return $this->longitude; |
|
158 | } |
||
159 | |||
160 | /** |
||
161 | * Getter to property longitudeDirection |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | public function getLongitudeDirection() |
||
166 | { |
||
167 | 1 | return $this->longitudeDirection; |
|
168 | } |
||
169 | |||
170 | /** |
||
171 | * Getter to property speed |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | public function getSpeed() |
||
176 | { |
||
177 | 1 | return $this->speed; |
|
178 | } |
||
179 | |||
180 | /** |
||
181 | * Getter to property angle |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | public function getAngle() |
||
186 | { |
||
187 | 1 | return $this->angle; |
|
188 | } |
||
189 | |||
190 | /** |
||
191 | * Getter to property date |
||
192 | * |
||
193 | * @return string |
||
194 | */ |
||
195 | public function getUtcDate() |
||
196 | { |
||
197 | 1 | return $this->utcDate; |
|
0 ignored issues
–
show
|
|||
198 | } |
||
199 | |||
200 | /** |
||
201 | * Getter to property magneticVariation |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | public function getMagneticVariation() |
||
206 | { |
||
207 | 1 | return $this->magneticVariation; |
|
208 | } |
||
209 | |||
210 | /** |
||
211 | * Getter to property magneticVariationDirection |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | public function getMagneticVariationDirection() |
||
216 | { |
||
217 | 1 | return $this->magneticVariationDirection; |
|
218 | } |
||
219 | |||
220 | /** |
||
221 | * Getter to property mode |
||
222 | * |
||
223 | * @return string |
||
224 | */ |
||
225 | public function getMode() |
||
226 | { |
||
227 | 1 | return $this->mode; |
|
228 | } |
||
229 | |||
230 | /** |
||
231 | * {@inheritdoc} |
||
232 | */ |
||
233 | protected function decodeFrame($msgParts) |
||
234 | { |
||
235 | 1 | $utcTimeZone = new DateTimeZone('UTC'); |
|
236 | |||
237 | 1 | $this->utcTime = DateTime::createFromFormat( |
|
0 ignored issues
–
show
It seems like
DateTime::createFromForm...Parts[2], $utcTimeZone) can also be of type false . However, the property $utcTime is declared as type DateTime . 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 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;
}
![]() |
|||
238 | 1 | 'His', |
|
239 | 1 | $msgParts[2], |
|
240 | 1 | $utcTimeZone |
|
241 | ); |
||
242 | |||
243 | 1 | $this->status = (string) $msgParts[4]; |
|
244 | |||
245 | 1 | $this->latitude = (string) $msgParts[5]; |
|
246 | 1 | $this->latitudeDirection = (string) $msgParts[6]; |
|
247 | 1 | $this->longitude = (string) $msgParts[7]; |
|
248 | 1 | $this->longitudeDirection = (string) $msgParts[8]; |
|
249 | |||
250 | 1 | $this->speed = (float) $msgParts[9]; |
|
251 | 1 | $this->angle = (float) $msgParts[10]; |
|
252 | |||
253 | 1 | $this->utcDate = DateTime::createFromFormat( |
|
0 ignored issues
–
show
It seems like
DateTime::createFromForm...arts[11], $utcTimeZone) can also be of type false . However, the property $utcDate is declared as type DateTime . 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 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;
}
![]() |
|||
254 | 1 | 'dmy', |
|
255 | 1 | $msgParts[11], |
|
256 | 1 | $utcTimeZone |
|
257 | ); |
||
258 | 1 | $this->utcDate->setTime(0, 0, 0); |
|
259 | |||
260 | 1 | $this->magneticVariation = (float) $msgParts[12]; |
|
261 | 1 | $this->magneticVariationDirection = (string) $msgParts[13]; |
|
262 | |||
263 | 1 | if (isset($msgParts[15])) { |
|
264 | 1 | $this->mode = (string) $msgParts[15]; |
|
265 | } |
||
266 | 1 | } |
|
267 | } |
||
268 |