Passed
Pull Request — main (#28)
by
unknown
10:10
created

Location::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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