Geolocation::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JustSteveKing\LaravelPostcodes\Service\BulkReverseGeocoding;
6
7
class Geolocation
8
{
9
    /** @var float */
10
    private $lng;
11
    /** @var float */
12
    private $lat;
13
    /** @var int|null */
14
    private $radius;
15
    /** @var int|null */
16
    private $limit;
17
18
    public function __construct(
19
        float $lng,
20
        float $lat,
21
        int $radius = null,
22
        int $limit = null
23
    ) {
24
        $this->lng = $lng;
25
        $this->lat = $lat;
26
        $this->radius = $radius;
27
        $this->limit = $limit;
28
    }
29
30
    public function getLng(): float
31
    {
32
        return $this->lng;
33
    }
34
35
    public function getLat(): float
36
    {
37
        return $this->lat;
38
    }
39
40
    public function getRadius(): ?int
41
    {
42
        return $this->radius;
43
    }
44
45
    public function getLimit(): ?int
46
    {
47
        return $this->limit;
48
    }
49
50
    public function toArray(): array
51
    {
52
        return [
53
            'longitude' => $this->getLng(),
54
            'latitude' => $this->getLat(),
55
        ] + array_filter([
56
            'radius' => $this->getRadius(),
57
            'limit' => $this->getLimit(),
58
        ]);
59
    }
60
}
61