Test Failed
Pull Request — master (#6)
by Laurens
01:35
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
    public function __construct(float $latitude, float $longitude, ?float $altitude = null, ?string $relevantText = null)
15
    {
16
        $this->latitude = $latitude;
17
        $this->longitude = $longitude;
18
19
        if ($altitude) {
20
            $this->altitude = $altitude;
21
        }
22
23
        if ($relevantText) {
24
            $this->relevantText = $relevantText;
25
        }
26
    }
27
28
    public function setAltitude(float $altitude): void
29 4
    {
30
        $this->altitude = $altitude;
31 4
    }
32 4
33 4
    public function setRelevantText(string $relevantText): void
34 4
    {
35 4
        $this->relevantText = $relevantText;
36
    }
37 1
38
    /**
39 1
     * @return array<string, float|string>
40 1
     */
41
    public function toArray(): array
42 1
    {
43
        $data = [
44 1
            'latitude' => $this->latitude,
45 1
            'longitude' => $this->longitude,
46
        ];
47 4
48
        if (isset($this->altitude)) {
49
            $data['altitude'] = $this->altitude;
50 4
        }
51 4
52
        if (isset($this->relevantText)) {
53
            $data['relevantText'] = $this->relevantText;
54 4
        }
55 1
56
        return $data;
57
    }
58
}
59