Test Failed
Pull Request — master (#6)
by Laurens
02:27
created

Location   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 58
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\ApplePassbook\MetaData;
6
7
class Location
8
{
9
    private float $latitude;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
10
    private float $longitude;
11
    private float $altitude;
12
    private string $relevantText;
13
14 4
    public function __construct(float $latitude, float $longitude, ?float $altitude = null, ?string $relevantText = null)
15
    {
16 4
        $this->latitude = $latitude;
17 4
        $this->longitude = $longitude;
18
19 4
        if ($altitude) {
20 1
            $this->altitude = $altitude;
21
        }
22
23 4
        if ($relevantText) {
24
            $this->relevantText = $relevantText;
25
        }
26 4
    }
27
28 1
    public function setAltitude(float $altitude): void
29
    {
30 1
        $this->altitude = $altitude;
31 1
    }
32
33 1
    public function setRelevantText(string $relevantText): void
34
    {
35 1
        $this->relevantText = $relevantText;
36 1
    }
37
38
    /**
39
     * @return array<string, float|string>
40
     */
41 4
    public function toArray(): array
42
    {
43
        $data = [
44 4
            'latitude' => $this->latitude,
45 4
            'longitude' => $this->longitude,
46
        ];
47
48 4
        if (isset($this->altitude)) {
49 1
            $data['altitude'] = $this->altitude;
50
        }
51
52 4
        if (isset($this->relevantText)) {
53 1
            $data['relevantText'] = $this->relevantText;
54
        }
55
56 4
        return $data;
57
    }
58
}
59