Passed
Pull Request — main (#54)
by
unknown
09:29
created

Location::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 21
rs 9.9
1
<?php
2
3
namespace NotificationChannels\WhatsApp\Component;
4
5
class Location extends Component
6
{
7
    protected float $latitude;
8
    protected float $longitude;
9
    protected ?string $name;
10
    protected ?string $address;
11
12
    public function __construct(float $latitude, float $longitude, ?string $name = null, ?string $address = null)
13
    {
14
        $this->latitude = $latitude;
15
        $this->longitude = $longitude;
16
        $this->name = $name;
17
        $this->address = $address;
18
    }
19
20
    public function toArray(): array
21
    {
22
        $location = [
23
            'latitude' => (string) $this->latitude,
24
            'longitude' => (string) $this->longitude,
25
        ];
26
27
        if ($this->name !== null) {
28
            $location['name'] = $this->name;
29
        }
30
31
        if ($this->address !== null) {
32
            $location['address'] = $this->address;
33
        }
34
35
        $baseArray = [
36
            'type' => 'location',
37
            'location' => $location,
38
        ];
39
40
        return $this->buildParameterArray($baseArray);
41
    }
42
}
43