| Total Complexity | 15 | 
| Total Lines | 63 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php  | 
            ||
| 9 | class Coordinates implements CoordinatesInterface  | 
            ||
| 10 | { | 
            ||
| 11 | private float $latitude;  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 12 | private float $longitude;  | 
            ||
| 13 | |||
| 14 | public function __construct($latitude, $longitude)  | 
            ||
| 15 |     { | 
            ||
| 16 | $this->setLatitudeIsValid($latitude);  | 
            ||
| 17 | $this->setLongitudeIsValid($longitude);  | 
            ||
| 18 | }  | 
            ||
| 19 | |||
| 20 | public function getLatitude(): float  | 
            ||
| 21 |     { | 
            ||
| 22 | return $this->latitude;  | 
            ||
| 23 | }  | 
            ||
| 24 | |||
| 25 | public function getLongitude(): float  | 
            ||
| 26 |     { | 
            ||
| 27 | return $this->longitude;  | 
            ||
| 28 | }  | 
            ||
| 29 | |||
| 30 | public function toArray(): array  | 
            ||
| 31 |     { | 
            ||
| 32 | return [$this->getLongitude(), $this->getLatitude()];  | 
            ||
| 33 | }  | 
            ||
| 34 | |||
| 35 | public function toString(): string  | 
            ||
| 36 |     { | 
            ||
| 37 | return $this->getLongitude() . ', ' . $this->getLatitude();  | 
            ||
| 38 | }  | 
            ||
| 39 | |||
| 40 | private function setLatitudeIsValid($latitude): void  | 
            ||
| 41 |     { | 
            ||
| 42 | $isValid = true;  | 
            ||
| 43 | |||
| 44 |         if (!is_numeric($latitude)) { | 
            ||
| 45 | $isValid = false;  | 
            ||
| 46 | }  | 
            ||
| 47 | |||
| 48 | $latitude = (float)$latitude;  | 
            ||
| 49 | |||
| 50 |         if (!$isValid || $latitude < -90 || $latitude > 90) { | 
            ||
| 51 |             throw new InvalidArgumentException('Invalid latitude. It must be a number between -90 and 90'); | 
            ||
| 52 | }  | 
            ||
| 53 | |||
| 54 | $this->latitude = $latitude;  | 
            ||
| 55 | }  | 
            ||
| 56 | |||
| 57 | private function setLongitudeIsValid($longitude): void  | 
            ||
| 58 |     { | 
            ||
| 59 | $isValid = true;  | 
            ||
| 60 | |||
| 61 |         if (!is_numeric($longitude)) { | 
            ||
| 62 | $isValid = false;  | 
            ||
| 63 | }  | 
            ||
| 64 | |||
| 65 | $longitude = (float)$longitude;  | 
            ||
| 66 | |||
| 67 |         if (!$isValid || $longitude < -180 || $longitude > 180) { | 
            ||
| 68 |             throw new InvalidArgumentException('Invalid longitude. It must be a number between -90 and 90'); | 
            ||
| 69 | }  | 
            ||
| 70 | |||
| 71 | $this->longitude = $longitude;  | 
            ||
| 72 | }  | 
            ||
| 74 |