Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
18 / 18
92.31% covered (success)
92.31%
12 / 13
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
LatLon
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
18 / 18
92.31% covered (success)
92.31%
12 / 13
100.00% covered (success)
100.00%
8 / 8
13.08
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 __destruct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 lat
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 lon
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isValidLatitude
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 isValidLongitude
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 equals
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
2.50
1<?php
2namespace Fdsn\Webservices\Event\Structs;
3
4/**
5 * Data structure to handle Latitude,Longitude point
6 *
7 * @param float $latitude        Latitude (-180~180)
8 * @param float $longitude        Longitude (-180~180) 
9 *
10 * @return true, if every check is passed, false otherwise
11 */
12class LatLon {
13    private float $lat;
14    private float $lon;
15
16    /**
17     * Range of data validity
18     * @see    https://www.fdsn.org/webservices/fdsnws-event-1.2.pdf FDSN official documentation
19     */
20    private $validLatitude = array('min' => -90, 'max' => 90);
21
22    /**
23     * Range of data validity
24     * @see    FDSN Doc https://www.fdsn.org/webservices/fdsnws-event-1.2.pdf
25     */
26    private $validLongitude = array('min' => -180, 'max' => 180);
27
28    function __construct( float $latitude, float $longitude) {
29
30        if( ! $this->isValidLatitude($latitude) )
31            throw new \InvalidArgumentException("Latitude invalid");
32
33        if (! $this->isValidLongitude($longitude)) 
34            throw new \InvalidArgumentException("Longitude invalid");
35
36        $this->lat = $latitude;
37        $this->lon = $longitude;
38    }
39
40    function __destruct(){ }
41
42    function __toString(){ return sprintf("%.5f,%.5f", $this->lat, $this->lon); }
43
44    /**
45     * Get latitude
46     *
47     * @return float latitude
48     */
49    public function lat():float { return $this->lat; }
50
51    /**
52     * Get longitude
53     *
54     * @return float longitude
55     */
56    public function lon():float { return $this->lon; }
57
58    /**
59     * Check latitude validity
60     *
61     * @return bool True if is valid, false otherwise
62     */
63    private function isValidLatitude(float $latitude){ return ($this->validLatitude['min'] <= $latitude && $latitude <= $this->validLatitude['max']); }
64
65    /**
66     * Check longitude validity
67     *
68     * @return bool True if is valid, false otherwise
69     */
70    private function isValidLongitude(float $longitude){ return ($this->validLongitude['min'] <= $longitude && $longitude <= $this->validLongitude['max']); }
71
72    /**
73     * Compare two objects
74     * @return bool        true are equals, false otherwise
75     */
76    public function equals(self $other):bool{ return $this->lat == $other->lat && $this->lon == $other->lon; }
77
78}