Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.86% covered (success)
92.86%
26 / 28
88.89% covered (warning)
88.89%
8 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
Location
92.86% covered (success)
92.86%
26 / 28
88.89% covered (warning)
88.89%
8 / 9
11.04
0.00% covered (danger)
0.00%
0 / 1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCountry
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCountry
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 serialize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 unserialize
83.33% covered (warning)
83.33%
10 / 12
0.00% covered (danger)
0.00%
0 / 1
3.04
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   phpOMS\Stdlib\Base
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15namespace phpOMS\Stdlib\Base;
16
17use phpOMS\Contract\SerializableInterface;
18use phpOMS\Localization\ISO3166TwoEnum;
19
20/**
21 * Location class.
22 *
23 * @package phpOMS\Stdlib\Base
24 * @license OMS License 2.0
25 * @link    https://jingga.app
26 * @since   1.0.0
27 */
28class Location implements \JsonSerializable, SerializableInterface
29{
30    /**
31     * Location id
32     *
33     * @var int
34     * @since 1.0.0
35     */
36    public int $id = 0;
37
38    /**
39     * Zip or postal.
40     *
41     * @var string
42     * @since 1.0.0
43     */
44    public string $postal = '';
45
46    /**
47     * Name of city.
48     *
49     * @var string
50     * @since 1.0.0
51     */
52    public string $city = '';
53
54    /**
55     * Name of the country.
56     *
57     * @var string
58     * @since 1.0.0
59     */
60    public string $country = ISO3166TwoEnum::_XXX;
61
62    /**
63     * Street & district.
64     *
65     * @var string
66     * @since 1.0.0
67     */
68    public string $address = '';
69
70    /**
71     * Address type
72     *
73     * @var int
74     * @since 1.0.0
75     */
76    public int $type = AddressType::HOME;
77
78    /**
79     * State.
80     *
81     * @var string
82     * @since 1.0.0
83     */
84    public string $state = '';
85
86    public float $lat = 0.0;
87
88    public float $lon = 0.0;
89
90    /**
91     * Get location id
92     *
93     * @return int
94     *
95     * @since 1.0.0
96     */
97    public function getId() : int
98    {
99        return $this->id;
100    }
101
102    /**
103     * Get location type
104     *
105     * @return int
106     *
107     * @since 1.0.0
108     */
109    public function getType() : int
110    {
111        return $this->type;
112    }
113
114    /**
115     * Set location type
116     *
117     * @param int $type Location type
118     *
119     * @return void
120     *
121     * @since 1.0.0
122     */
123    public function setType(int $type) : void
124    {
125        $this->type = $type;
126    }
127
128    /**
129     * Get country code
130     *
131     * @return string
132     *
133     * @since 1.0.0
134     */
135    public function getCountry() : string
136    {
137        return $this->country;
138    }
139
140    /**
141     * Set country code
142     *
143     * @param string $country Country name
144     *
145     * @return void
146     *
147     * @since 1.0.0
148     */
149    public function setCountry(string $country) : void
150    {
151        $this->country = $country;
152    }
153
154    /**
155     * {@inheritdoc}
156     */
157    public function serialize() : string
158    {
159        return (string) \json_encode($this->jsonSerialize());
160    }
161
162    /**
163     * {@inheritdoc}
164     */
165    public function jsonSerialize() : mixed
166    {
167        return $this->toArray();
168    }
169
170    /**
171     * {@inheritdoc}
172     */
173    public function toArray() : array
174    {
175        return [
176            'postal'  => $this->postal,
177            'city'    => $this->city,
178            'country' => $this->country,
179            'address' => $this->address,
180            'state'   => $this->state,
181            'lat'     => $this->lat,
182            'lon'     => $this->lon,
183        ];
184    }
185
186    /**
187     * {@inheritdoc}
188     */
189    public function unserialize(mixed $serialized) : void
190    {
191        if (!\is_string($serialized)) {
192            return;
193        }
194
195        $data = \json_decode($serialized, true);
196
197        if (!\is_array($data)) {
198            return;
199        }
200
201        $this->postal  = $data['postal'];
202        $this->city    = $data['city'];
203        $this->country = $data['country'];
204        $this->address = $data['address'];
205        $this->state   = $data['state'];
206        $this->lat     = $data['lat'];
207        $this->lon     = $data['lon'];
208    }
209}