Location::getCoordinates()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 2
b 1
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Rawaby88\OpenWeatherMap\Services\Support;
4
5
/**
6
 * Class Location.
7
 */
8
class Location
9
{
10
    /**
11
     * @var string The city name.
12
     */
13
    public $city;
14
15
    /**
16
     * @var string The countryCode code.
17
     */
18
    public $countryCode;
19
20
    /**
21
     * @var float|null The longitude coordinate.
22
     */
23
    public $lon;
24
25
    /**
26
     * @var float|null The latitude coordinate.
27
     */
28
    public $lat;
29
30
    /**
31
     * Location constructor.
32
     * @param string $city The city name.
33
     * @param string $countryCode The country code.
34
     * @param float|null $lat The longitude coordinate.
35
     * @param float|null $lon The latitude coordinate.
36
     */
37
    public function __construct(string $city, string $countryCode, $lat = null, $lon = null)
38
    {
39
        $this->city = $city;
40
        $this->countryCode = $countryCode;
41
        $this->lat = $lat;
42
        $this->lon = $lon;
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getCoordinates(): array
49
    {
50
        return ['lon' => $this->lon, 'lat' => $this->lat];
51
    }
52
53
    /**
54
     * Encoding to json.
55
     * @return false|string
56
     */
57
    public function toJson()
58
    {
59
        return json_encode(
60
            [
61
                'city'        => $this->city,
62
                'countryCode' => $this->countryCode,
63
                'lon'         => $this->lon,
64
                'lat'         => $this->lat,
65
            ]
66
        );
67
    }
68
}
69