Total Complexity | 75 |
Total Lines | 432 |
Duplicated Lines | 0 % |
Changes | 8 | ||
Bugs | 1 | Features | 1 |
Complex classes like geoPHP often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use geoPHP, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class geoPHP |
||
18 | { |
||
19 | |||
20 | // Earth radius constants in meters |
||
21 | |||
22 | /** WGS84 semi-major axis (a), aka equatorial radius */ |
||
23 | const EARTH_WGS84_SEMI_MAJOR_AXIS = 6378137.0; |
||
24 | |||
25 | /** WGS84 semi-minor axis (b), aka polar radius */ |
||
26 | const EARTH_WGS84_SEMI_MINOR_AXIS = 6356752.314245; |
||
27 | |||
28 | /** WGS84 inverse flattening */ |
||
29 | const EARTH_WGS84_FLATTENING = 298.257223563; |
||
30 | |||
31 | /** WGS84 semi-major axis (a), aka equatorial radius */ |
||
32 | const EARTH_GRS80_SEMI_MAJOR_AXIS = 6378137.0; |
||
33 | |||
34 | /** GRS80 semi-minor axis */ |
||
35 | const EARTH_GRS80_SEMI_MINOR_AXIS = 6356752.314140; |
||
36 | |||
37 | /** GRS80 inverse flattening */ |
||
38 | const EARTH_GRS80_FLATTENING = 298.257222100882711; |
||
39 | |||
40 | /** IUGG mean radius R1 = (2a + b) / 3 */ |
||
41 | const EARTH_MEAN_RADIUS = 6371008.8; |
||
42 | |||
43 | /** IUGG R2: Earth's authalic ("equal area") radius is the radius of a hypothetical perfect sphere |
||
44 | * which has the same surface area as the reference ellipsoid. */ |
||
45 | const EARTH_AUTHALIC_RADIUS = 6371007.2; |
||
46 | |||
47 | /** |
||
48 | * @var array<string, string> |
||
49 | */ |
||
50 | private static $adapterMap = [ |
||
51 | 'wkt' => 'WKT', |
||
52 | 'ewkt' => 'EWKT', |
||
53 | 'wkb' => 'WKB', |
||
54 | 'ewkb' => 'EWKB', |
||
55 | 'json' => 'GeoJSON', |
||
56 | 'geojson' => 'GeoJSON', |
||
57 | 'kml' => 'KML', |
||
58 | 'gpx' => 'GPX', |
||
59 | 'georss' => 'GeoRSS', |
||
60 | 'google_geocode' => 'GoogleGeocode', |
||
61 | 'geohash' => 'GeoHash', |
||
62 | 'twkb' => 'TWKB', |
||
63 | 'osm' => 'OSM' |
||
64 | ]; |
||
65 | |||
66 | /** |
||
67 | * @var array<string, string> |
||
68 | */ |
||
69 | private static $geometryList = [ |
||
70 | 'point' => 'Point', |
||
71 | 'linestring' => 'LineString', |
||
72 | 'polygon' => 'Polygon', |
||
73 | 'multipoint' => 'MultiPoint', |
||
74 | 'multilinestring' => 'MultiLineString', |
||
75 | 'multipolygon' => 'MultiPolygon', |
||
76 | 'geometrycollection' => 'GeometryCollection' |
||
77 | ]; |
||
78 | |||
79 | /** |
||
80 | * @return string |
||
81 | */ |
||
82 | public static function version(): string |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @return array<string, string> returns the supported adapter-map, e.g. ['wkt' => 'WKT',...] |
||
89 | */ |
||
90 | public static function getAdapterMap(): array |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @return array<string, string> returns the mapped geometry-list, e.g. ['point' => 'Point',...] |
||
97 | */ |
||
98 | public static function getGeometryList(): array |
||
99 | { |
||
100 | return self::$geometryList; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Converts data to Geometry using geo adapters |
||
105 | * If $data is an array, all passed in values will be combined into a single geometry. |
||
106 | * |
||
107 | * @param mixed $data The data in any supported format, including geoPHP Geometry. |
||
108 | * @var null|string $type Data type. Tries to detect it if omitted. |
||
109 | * @var null|mixed $otherArgs Arguments will be passed to the geo adapter. |
||
110 | * |
||
111 | * @return Collection|Geometry|null |
||
112 | * @throws \Exception |
||
113 | */ |
||
114 | public static function load($data) |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @staticvar bool $geosInstalled |
||
163 | * @param bool $force |
||
164 | * @return bool |
||
165 | */ |
||
166 | public static function geosInstalled($force = null): bool |
||
167 | { |
||
168 | static $geosInstalled = null; |
||
169 | |||
170 | if ($force !== null) { |
||
171 | $geosInstalled = $force; |
||
172 | } |
||
173 | if (getenv('GEOS_DISABLED') == 1) { |
||
174 | $geosInstalled = false; |
||
175 | } |
||
176 | if ($geosInstalled !== null) { |
||
177 | return $geosInstalled; |
||
178 | } |
||
179 | |||
180 | $geosInstalled = class_exists('GEOSGeometry', false); |
||
181 | |||
182 | return $geosInstalled; |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @param \GEOSGeometry $geos |
||
187 | * @return Geometry|null |
||
188 | * @throws \Exception |
||
189 | * @codeCoverageIgnore |
||
190 | */ |
||
191 | public static function geosToGeometry($geos) |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * Reduce a geometry, or an array of geometries, into their 'lowest' available common geometry. |
||
211 | * For example a GeometryCollection of only points will become a MultiPoint |
||
212 | * A multi-point containing a single point will return a point. |
||
213 | * An array of geometries can be passed and they will be compiled into a single geometry |
||
214 | * |
||
215 | * @param Geometry|Geometry[]|GeometryCollection|GeometryCollection[] $geometries |
||
216 | * @return mixed Geometry|false |
||
217 | */ |
||
218 | public static function geometryReduce($geometries) |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * @param Geometry[]|GeometryCollection[] $unreduced |
||
275 | * @param Geometry[]|GeometryCollection[] $reduced |
||
276 | * @param array<string> $types |
||
277 | * @return void |
||
278 | */ |
||
279 | private static function explodeCollections($unreduced, &$reduced, &$types) |
||
288 | } |
||
289 | } |
||
290 | } |
||
291 | |||
292 | /** |
||
293 | * Build an appropriate Geometry, MultiGeometry, or GeometryCollection to contain the Geometries in it. |
||
294 | * |
||
295 | * @see geos::geom::GeometryFactory::buildGeometry |
||
296 | * |
||
297 | * @param Geometry|Geometry[]|GeometryCollection|GeometryCollection[]|null[] $geometries |
||
298 | * @return Geometry A Geometry of the "smallest", "most type-specific" class that can contain the elements. |
||
299 | * @throws \Exception |
||
300 | */ |
||
301 | public static function buildGeometry($geometries) |
||
349 | } |
||
350 | |||
351 | /** |
||
352 | * Detect a format given a value. This function is meant to be SPEEDY. |
||
353 | * It could make a mistake in XML detection if you are mixing or using namespaces in weird ways |
||
354 | * (i.e. KML inside an RSS feed) |
||
355 | * |
||
356 | * @param mixed $input |
||
357 | * @return string|false |
||
358 | */ |
||
359 | public static function detectFormat($input) |
||
451 |