GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

GpsData::parseCoordinate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uro\TeltonikaFmParser\Model;
6
7
use JsonSerializable;
8
9
class GpsData implements JsonSerializable
10
{
11
    /**
12
     * @var float
13
     */
14
    private $longitude;
15
16
    /**
17
     * @var float
18
     */
19
    private $latitude;
20
21
    /**
22
     * @var int
23
     */
24
    private $altitude;
25
26
    /**
27
     * @var int
28
     */
29
    private $angle;
30
31
    /**
32
     * @var int
33
     */
34
    private $satellites;
35
36
    /**
37
     * @var int
38
     */
39
    private $speed;
40
41
    public function __construct(
42
        float $longitude,
43
        float $latitude,
44
        int $altitude,
45
        int $angle,
46
        int $satellites,
47
        int $speed
48
    )
49
    {
50
        $this->longitude = $longitude;
51
        $this->latitude = $latitude;
52
        $this->altitude = $altitude;
53
        $this->angle = $angle;
54
        $this->satellites = $satellites;
55
        $this->speed = $speed;
56
    }
57
58
    public function getLongitude(): float
59
    {
60
        return $this->longitude;
61
    }
62
63
    public function getLatitude(): float
64
    {
65
        return $this->latitude;
66
    }
67
68
    public function getAltitude(): int
69
    {
70
        return $this->altitude;
71
    }
72
73
    public function getAngle(): int
74
    {
75
        return $this->angle;
76
    }
77
78
    public function getSatellites(): int
79
    {
80
        return $this->satellites;
81
    }
82
83
    public function getSpeed(): int
84
    {
85
        return $this->speed;
86
    }
87
88
    /**
89
     * If there were no GPS fix in the moment of data acquisition – Angle, Satellites and Speed are 0.
90
     *
91
     * @return bool
92
     */
93
    public function hasGpsFix(): bool
94
    {
95
        return !((($this->angle === $this->speed) === $this->satellites) && ($this->satellites == 0));
96
    }
97
98
    public static function parseCoordinate($coordinate, $precision = 10000000)
99
    {
100
        return unpack('l', pack('l', hexdec($coordinate)))[1] / $precision;
101
    }
102
103
    public static function createFromHex(string $payload, int &$position): GpsData
104
    {
105
        $longitude = self::parseCoordinate(substr($payload, $position, 8));
106
        $position += 8;
107
108
        $latitude = self::parseCoordinate(substr($payload, $position, 8));
109
        $position += 8;
110
111
        $altitude = (int)hexdec(substr($payload, $position, 4));
112
        $position += 4;
113
114
        $angle = (int)hexdec(substr($payload, $position, 4));
115
        $position += 4;
116
117
        $satellites = (int)hexdec(substr($payload, $position, 2));
118
        $position += 2;
119
120
        $speed = (int)hexdec(substr($payload, $position, 4));
121
        $position += 4;
122
123
        return new GpsData($longitude, $latitude, $altitude, $angle, $satellites, $speed);
124
    }
125
126
    public function jsonSerialize(): array
127
    {
128
        return [
129
            'longitude' => $this->getLongitude(),
130
            'latitude' => $this->getLatitude(),
131
            'altitude' => $this->getAltitude(),
132
            'angle' => $this->getAngle(),
133
            'satellites' => $this->getSatellites(),
134
            'speed' => $this->getSpeed(),
135
            'hasGpsFix' => $this->hasGpsFix()
136
        ];
137
    }
138
}
139