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%
24 / 24
93.33% covered (success)
93.33%
14 / 15
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%
24 / 24
93.33% covered (success)
93.33%
14 / 15
100.00% covered (success)
100.00%
8 / 8
15.07
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%
4 / 4
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 lon
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 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 */
10class LatLon {
11    private float $lat;
12    private float $lon;
13
14    /**
15     * Range of data validity
16     * @see    https://www.fdsn.org/webservices/fdsnws-event-1.2.pdf FDSN official documentation
17     */
18    private $validLatitude = array('min' => -90, 'max' => 90);
19
20    /**
21     * Range of data validity
22     * @see    FDSN Doc https://www.fdsn.org/webservices/fdsnws-event-1.2.pdf
23     */
24    private $validLongitude = array('min' => -180, 'max' => 180);
25
26    function __construct( float $latitude, float $longitude) {
27
28        if( ! $this->isValidLatitude($latitude) )
29            throw new \InvalidArgumentException("Latitude invalid");
30
31        if (! $this->isValidLongitude($longitude)) 
32            throw new \InvalidArgumentException("Longitude invalid");
33
34        $this->lat = $latitude;
35        $this->lon = $longitude;
36    }
37
38    function __destruct(){ }
39
40    function __toString(){ return sprintf("%.3f,%.3f", $this->lat, $this->lon); }
41
42    /**
43     * Get latitude
44     *
45     * @param int $roundTo (nullable) if set, return value rounded to `roundTo` decimals
46     * @return float latitude
47     */
48    public function lat(?int $roundTo = null):float { return is_null($roundTo) ? $this->lat : round($this->lat, $roundTo); }
49
50    /**
51     * Get longitude
52     *
53     * @param int $roundTo (nullable) if set, return value rounded to `roundTo` decimals
54     * @return float longitude
55     */
56    public function lon(?int $roundTo = null):float { return is_null($roundTo) ? $this->lon : round($this->lon, $roundTo); }
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} 

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

LatLon->__construct
26    function __construct( float $latitude, float $longitude) {
27
28        if( ! $this->isValidLatitude($latitude) )
29            throw new \InvalidArgumentException("Latitude invalid");
31        if (! $this->isValidLongitude($longitude)) 
32            throw new \InvalidArgumentException("Longitude invalid");
34        $this->lat = $latitude;
35        $this->lon = $longitude;
36    }
LatLon->__destruct
38    function __destruct(){ }
LatLon->__toString
40    function __toString(){ return sprintf("%.3f,%.3f", $this->lat, $this->lon); }
LatLon->equals
76    public function equals(self $other):bool{ return $this->lat == $other->lat && $this->lon == $other->lon; }
76    public function equals(self $other):bool{ return $this->lat == $other->lat && $this->lon == $other->lon; }
76    public function equals(self $other):bool{ return $this->lat == $other->lat && $this->lon == $other->lon; }
LatLon->isValidLatitude
63    private function isValidLatitude(float $latitude){ return ($this->validLatitude['min'] <= $latitude && $latitude <= $this->validLatitude['max']); }
63    private function isValidLatitude(float $latitude){ return ($this->validLatitude['min'] <= $latitude && $latitude <= $this->validLatitude['max']); }
63    private function isValidLatitude(float $latitude){ return ($this->validLatitude['min'] <= $latitude && $latitude <= $this->validLatitude['max']); }
LatLon->isValidLongitude
70    private function isValidLongitude(float $longitude){ return ($this->validLongitude['min'] <= $longitude && $longitude <= $this->validLongitude['max']); }
70    private function isValidLongitude(float $longitude){ return ($this->validLongitude['min'] <= $longitude && $longitude <= $this->validLongitude['max']); }
70    private function isValidLongitude(float $longitude){ return ($this->validLongitude['min'] <= $longitude && $longitude <= $this->validLongitude['max']); }
LatLon->lat
48    public function lat(?int $roundTo = null):float { return is_null($roundTo) ? $this->lat : round($this->lat, $roundTo); }
48    public function lat(?int $roundTo = null):float { return is_null($roundTo) ? $this->lat : round($this->lat, $roundTo); }
48    public function lat(?int $roundTo = null):float { return is_null($roundTo) ? $this->lat : round($this->lat, $roundTo); }
48    public function lat(?int $roundTo = null):float { return is_null($roundTo) ? $this->lat : round($this->lat, $roundTo); }
LatLon->lon
56    public function lon(?int $roundTo = null):float { return is_null($roundTo) ? $this->lon : round($this->lon, $roundTo); }
56    public function lon(?int $roundTo = null):float { return is_null($roundTo) ? $this->lon : round($this->lon, $roundTo); }
56    public function lon(?int $roundTo = null):float { return is_null($roundTo) ? $this->lon : round($this->lon, $roundTo); }
56    public function lon(?int $roundTo = null):float { return is_null($roundTo) ? $this->lon : round($this->lon, $roundTo); }