Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
29 / 29
86.67% covered (warning)
86.67%
39 / 45
66.67% covered (warning)
66.67%
22 / 33
54.55% covered (warning)
54.55%
6 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 1
LatLonRange
100.00% covered (success)
100.00%
29 / 29
86.67% covered (warning)
86.67%
39 / 45
66.67% covered (warning)
66.67%
22 / 33
100.00% covered (success)
100.00%
11 / 11
57.04
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
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
 __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%
3 / 3
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
 min
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
 max
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
 distance
100.00% covered (success)
100.00%
7 / 7
60.00% covered (warning)
60.00%
3 / 5
25.00% covered (danger)
25.00%
1 / 4
100.00% covered (success)
100.00%
1 / 1
6.80
 isPointContained
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
7 / 7
50.00% covered (danger)
50.00%
4 / 8
100.00% covered (success)
100.00%
1 / 1
6.00
 position
100.00% covered (success)
100.00%
3 / 3
85.71% covered (warning)
85.71%
6 / 7
75.00% covered (warning)
75.00%
3 / 4
100.00% covered (success)
100.00%
1 / 1
4.25
 getNorthPosition
100.00% covered (success)
100.00%
3 / 3
85.71% covered (warning)
85.71%
6 / 7
75.00% covered (warning)
75.00%
3 / 4
100.00% covered (success)
100.00%
1 / 1
4.25
 getCenterPosition
100.00% covered (success)
100.00%
3 / 3
85.71% covered (warning)
85.71%
6 / 7
75.00% covered (warning)
75.00%
3 / 4
100.00% covered (success)
100.00%
1 / 1
4.25
 getSouthPosition
100.00% covered (success)
100.00%
3 / 3
85.71% covered (warning)
85.71%
6 / 7
75.00% covered (warning)
75.00%
3 / 4
100.00% covered (success)
100.00%
1 / 1
4.25
1<?php
2namespace Fdsn\Webservices\Event\Structs;
3
4/**
5 * Data structure to handle Latitude,Longitude bounding box
6 *
7 * @param LatLon $min    Min Latitude,Longitude 
8 * @param LatLon $max    Max Latitude,Longitude 
9 */
10class LatLonRange {
11    private const earthRadius = 6372.795;
12    private LatLon $min;
13    private LatLon $max;
14
15    private $validLatitude = array('min' => -180, 'max' => 180);
16    private $validLongitude = array('min' => -180, 'max' => 180);
17
18    function __construct( LatLon $min, LatLon $max) {
19        $this->min = $min;
20        $this->max = $max;
21    }
22
23    function __destruct(){ }
24
25    /**
26     * Returns bounding box coordinates 
27     *
28     * @return string Bounding box in [%.5f,%.5f],[%.5f,%.5f] [min lat,lon],[max lat,lon] format
29     */
30    function __toString(){ 
31        return sprintf("[%.5f,%.5f],[%.5f,%.5f]", 
32            $this->min->lat(), $this->min->lon(),
33            $this->max->lat(), $this->max->lon()); 
34    }
35
36    /**
37     * Get min bouding box coordinates
38     *
39     * @return LatLon  Min bouding box coordinates
40     */
41    public function min():LatLon { return $this->min; }
42
43    /**
44     * Get max bouding box coordinates
45     *
46     * @return LatLon  Max bouding box coordinates
47     */
48    public function max():LatLon { return $this->max; }
49
50    /**
51     * Get distance (in km) between the 2 points
52     *
53     * @return float distance in km
54     */
55    public function distance():float{
56        $colat1 = ( 90 - $this->min->lat()) * pi() / 180;
57        $colat2 = ( 90 - $this->max->lat()) * pi() / 180;
58
59        $phi = ($this->max->lon() - $this->min->lon()) * pi() / 180;
60        $arg = cos($colat1) * cos($colat2) + sin($colat1) * sin($colat2) * cos($phi);
61
62        if( $arg > 1 ) $arg = 1;
63        if( $arg < -1 ) $arg = -1;
64
65        return  abs(self::earthRadius * acos($arg));
66    }
67
68    /**
69     * Check if a point (LatLon obj) is contained by the bounding box (this LatLonRange)
70     *
71     * @param LatLon $point point to check if is contained by the bounding box
72     *
73     * @return bool    true if is contained by the bounding box, false otherwise
74     */
75    public function isPointContained(LatLon $point):bool{
76        return ( $this->min->lat() <= $point->lat() && $point->lat() <= $this->max->lat() 
77            && $this->min->lon() <= $point->lon() && $point->lon() <= $this->max->lon() );
78    }
79
80    /**
81     * Get spatial position first point respect to second point
82     * possible values are:
83     * NO N NE
84     * O  C  E
85     * SO S SE
86     * @return string position of first point respect to second point (see __construct())
87     */
88    public function position():string{
89        //North
90        if( $this->min->lat() > $this->max->lat() ) return $this->getNorthPosition();
91
92        //Center
93        if( $this->min->lat() == $this->max->lat() ) return $this->getCenterPosition();
94
95        //South
96        if( $this->min->lat() < $this->max->lat() ) return $this->getSouthPosition();
97    }
98
99    /**
100     * Get north position
101     * possible values are:
102     * NO N NE
103     * @return string position of first point respect to second point (see __construct())
104     */
105    private function getNorthPosition():string{
106        if($this->min->lon() <  $this->max->lon()) return 'NO';
107        if($this->min->lon() == $this->max->lon()) return 'N';
108        if($this->min->lon() >  $this->max->lon()) return 'NE';
109    }
110    
111    /**
112     * Get center position
113     * possible values are:
114     * O  C  E
115     * @return string position of first point respect to second point (see __construct())
116     */
117    private function getCenterPosition():string{
118        if($this->min->lon() <  $this->max->lon()) return 'O';
119        if($this->min->lon() == $this->max->lon()) return 'C';
120        if($this->min->lon() >  $this->max->lon()) return 'E';
121    }
122
123    /**
124     * Get south position
125     * possible values are:
126     * SO S SE
127     * @return string position of first point respect to second point (see __construct())
128     */
129    private function getSouthPosition():string{
130        if($this->min->lon() >  $this->max->lon()) return 'SO';
131        if($this->min->lon() == $this->max->lon()) return 'S';
132        if($this->min->lon() <  $this->max->lon()) return 'SE';
133    }
134
135} 

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.

LatLonRange->__construct
18    function __construct( LatLon $min, LatLon $max) {
19        $this->min = $min;
20        $this->max = $max;
21    }
LatLonRange->__destruct
23    function __destruct(){ }
LatLonRange->__toString
31        return sprintf("[%.5f,%.5f],[%.5f,%.5f]", 
32            $this->min->lat(), $this->min->lon(),
33            $this->max->lat(), $this->max->lon()); 
34    }
LatLonRange->distance
56        $colat1 = ( 90 - $this->min->lat()) * pi() / 180;
57        $colat2 = ( 90 - $this->max->lat()) * pi() / 180;
58
59        $phi = ($this->max->lon() - $this->min->lon()) * pi() / 180;
60        $arg = cos($colat1) * cos($colat2) + sin($colat1) * sin($colat2) * cos($phi);
61
62        if( $arg > 1 ) $arg = 1;
62        if( $arg > 1 ) $arg = 1;
63        if( $arg < -1 ) $arg = -1;
63        if( $arg < -1 ) $arg = -1;
63        if( $arg < -1 ) $arg = -1;
64
65        return  abs(self::earthRadius * acos($arg));
65        return  abs(self::earthRadius * acos($arg));
66    }
LatLonRange->getCenterPosition
118        if($this->min->lon() <  $this->max->lon()) return 'O';
118        if($this->min->lon() <  $this->max->lon()) return 'O';
119        if($this->min->lon() == $this->max->lon()) return 'C';
119        if($this->min->lon() == $this->max->lon()) return 'C';
120        if($this->min->lon() >  $this->max->lon()) return 'E';
120        if($this->min->lon() >  $this->max->lon()) return 'E';
121    }
LatLonRange->getNorthPosition
106        if($this->min->lon() <  $this->max->lon()) return 'NO';
106        if($this->min->lon() <  $this->max->lon()) return 'NO';
107        if($this->min->lon() == $this->max->lon()) return 'N';
107        if($this->min->lon() == $this->max->lon()) return 'N';
108        if($this->min->lon() >  $this->max->lon()) return 'NE';
108        if($this->min->lon() >  $this->max->lon()) return 'NE';
109    }
LatLonRange->getSouthPosition
130        if($this->min->lon() >  $this->max->lon()) return 'SO';
130        if($this->min->lon() >  $this->max->lon()) return 'SO';
131        if($this->min->lon() == $this->max->lon()) return 'S';
131        if($this->min->lon() == $this->max->lon()) return 'S';
132        if($this->min->lon() <  $this->max->lon()) return 'SE';
132        if($this->min->lon() <  $this->max->lon()) return 'SE';
133    }
LatLonRange->isPointContained
75    public function isPointContained(LatLon $point):bool{
76        return ( $this->min->lat() <= $point->lat() && $point->lat() <= $this->max->lat() 
76        return ( $this->min->lat() <= $point->lat() && $point->lat() <= $this->max->lat() 
76        return ( $this->min->lat() <= $point->lat() && $point->lat() <= $this->max->lat() 
77            && $this->min->lon() <= $point->lon() && $point->lon() <= $this->max->lon() );
77            && $this->min->lon() <= $point->lon() && $point->lon() <= $this->max->lon() );
77            && $this->min->lon() <= $point->lon() && $point->lon() <= $this->max->lon() );
77            && $this->min->lon() <= $point->lon() && $point->lon() <= $this->max->lon() );
78    }
LatLonRange->max
48    public function max():LatLon { return $this->max; }
LatLonRange->min
41    public function min():LatLon { return $this->min; }
LatLonRange->position
90        if( $this->min->lat() > $this->max->lat() ) return $this->getNorthPosition();
90        if( $this->min->lat() > $this->max->lat() ) return $this->getNorthPosition();
93        if( $this->min->lat() == $this->max->lat() ) return $this->getCenterPosition();
93        if( $this->min->lat() == $this->max->lat() ) return $this->getCenterPosition();
96        if( $this->min->lat() < $this->max->lat() ) return $this->getSouthPosition();
96        if( $this->min->lat() < $this->max->lat() ) return $this->getSouthPosition();
97    }