Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
73.33% |
33 / 45 |
|
42.86% |
3 / 7 |
CRAP | |
0.00% |
0 / 1 |
Point | |
73.33% |
33 / 45 |
|
42.86% |
3 / 7 |
40.82 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
__get | |
63.64% |
7 / 11 |
|
0.00% |
0 / 1 |
7.73 | |||
__set | |
78.57% |
11 / 14 |
|
0.00% |
0 / 1 |
9.80 | |||
parse | |
83.33% |
10 / 12 |
|
0.00% |
0 / 1 |
4.07 | |||
move | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isValid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
getData | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | namespace MultiMaps; |
3 | |
4 | /** |
5 | * Determines the point of the map elements |
6 | * |
7 | * @file Bounds.php |
8 | * @ingroup MultiMaps |
9 | * @author Pavel Astakhov <pastakhov@yandex.ru> |
10 | * @license GPL-2.0-or-later |
11 | * @property-read float $lat Latitude coordinate |
12 | * @property-read float $lon Longitude coordinate |
13 | * @property Bounds $bounds Bounds associated with the point, used in the geocoding |
14 | * @property-read array $pos Position as array( 'lat' => lat, 'lon' => lon) |
15 | */ |
16 | class Point { |
17 | /** |
18 | * Latitude |
19 | * @var float |
20 | */ |
21 | protected $latitude = false; |
22 | |
23 | /** |
24 | * Longitude |
25 | * @var float |
26 | */ |
27 | protected $longitude = false; |
28 | |
29 | /** |
30 | * Bounds associated with the point, used in the geocoding |
31 | * @var Bounds |
32 | */ |
33 | protected $bounds = false; |
34 | |
35 | /** |
36 | * Constructor |
37 | * @param float $lat |
38 | * @param float $lon |
39 | */ |
40 | public function __construct( $lat = false, $lon = false ) { |
41 | if ( is_numeric( $lat ) && is_numeric( $lon ) ) { |
42 | $this->latitude = (float)$lat; |
43 | $this->longitude = (float)$lon; |
44 | } |
45 | } |
46 | |
47 | public function __get( $name ) { |
48 | switch ( $name ) { |
49 | case 'lat': |
50 | return $this->latitude; |
51 | case 'lon': |
52 | return $this->longitude; |
53 | case 'bounds': |
54 | return $this->bounds; |
55 | case 'pos': |
56 | if ( $this->isValid() ) { |
57 | return [ 'lat' => $this->latitude, 'lon' => $this->longitude ]; |
58 | } |
59 | break; |
60 | } |
61 | return null; |
62 | } |
63 | |
64 | public function __set( $name, $value ) { |
65 | switch ( $name ) { |
66 | case 'lat': |
67 | if ( is_numeric( $value ) ) { |
68 | $this->latitude = (float)$value; |
69 | } else { |
70 | $this->latitude = false; |
71 | } |
72 | break; |
73 | case 'lon': |
74 | if ( is_numeric( $value ) ) { |
75 | $this->longitude = (float)$value; |
76 | } else { |
77 | $this->longitude = false; |
78 | } |
79 | break; |
80 | case 'bounds': |
81 | if ( ( $value instanceof Bounds && $value->isValid() ) || $value === false ) { |
82 | $this->bounds = $value; |
83 | } |
84 | break; |
85 | } |
86 | } |
87 | |
88 | /** |
89 | * Parse geographic coordinates |
90 | * @param string $string geographic coordinates |
91 | * @param string|null $service Name of map service |
92 | * @return bool |
93 | */ |
94 | public function parse( $string, $service = null ) { |
95 | $coord = GeoCoordinate::getLatLonFromString( $string ); |
96 | if ( is_array( $coord ) === false ) { |
97 | $coord = Geocoders::getCoordinates( $string, $service ); |
98 | if ( is_array( $coord ) === false ) { |
99 | $this->latitude = false; |
100 | $this->longitude = false; |
101 | return false; |
102 | } |
103 | if ( isset( $coord['bounds'] ) ) { |
104 | $this->bounds = $coord['bounds']; |
105 | } |
106 | } |
107 | $this->lat = $coord['lat']; |
108 | $this->lon = $coord['lon']; |
109 | return true; |
110 | } |
111 | |
112 | /** |
113 | * Move this point at a given distance in meters |
114 | * @param float $nord To the north (meters) |
115 | * @param float $east To the East (meters) |
116 | */ |
117 | public function move( $nord, $east ) { |
118 | GeoCoordinate::moveCoordinatesInMeters( $this->latitude, $this->longitude, $nord, $east ); |
119 | } |
120 | |
121 | /** |
122 | * Checks if the object is valid |
123 | * @return bool |
124 | */ |
125 | public function isValid() { |
126 | return ( $this->latitude !== false && $this->longitude !== false ); |
127 | } |
128 | |
129 | /** |
130 | * Returns an array of data |
131 | * @return array |
132 | */ |
133 | public function getData() { |
134 | if ( $this->isValid() ) { |
135 | return [ 'lat' => $this->latitude, 'lon' => $this->longitude ]; |
136 | } |
137 | return null; |
138 | } |
139 | |
140 | } |