Complex classes like Mapper 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Mapper, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class Mapper extends MapperBase implements MappingInterface |
||
| 21 | { |
||
| 22 | private const GOOGLE_RESPONSE_OK = 'OK'; |
||
| 23 | private const GOOGLE_RESPONSE_ZERO_RESULTS = 'ZERO_RESULTS'; |
||
| 24 | private const GOOGLE_RESPONSE_QUERY_LIMIT = 'OVER_QUERY_LIMIT'; |
||
| 25 | private const GOOGLE_RESPONSE_DENIED = 'REQUEST_DENIED'; |
||
| 26 | private const GOOGLE_RESPONSE_INVALID = 'INVALID_REQUEST'; |
||
| 27 | private const GOOGLE_RESPONSE_UNKNOWN = 'UNKNOWN_ERROR'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Renders and returns Google Map code. |
||
| 31 | * |
||
| 32 | * @param int $item |
||
| 33 | * |
||
| 34 | * @return string |
||
| 35 | */ |
||
| 36 | public function render($item = -1) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Renders and returns Google Map javascript code. |
||
| 51 | * |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | public function renderJavascript() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Generates the render options for Google Map. |
||
| 68 | * |
||
| 69 | * @param int $item |
||
| 70 | * |
||
| 71 | * @return string |
||
| 72 | */ |
||
| 73 | protected function generateRenderOptions($item = -1) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Search for a location against Google Maps Api. |
||
| 90 | * |
||
| 91 | * @param string $location |
||
| 92 | * |
||
| 93 | * @return mixed |
||
| 94 | */ |
||
| 95 | protected function searchLocation($location) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Locate a location and return a Location instance. |
||
| 110 | * |
||
| 111 | * @param string $location |
||
| 112 | * |
||
| 113 | * @throws MapperArgumentException |
||
| 114 | * @throws MapperSearchException |
||
| 115 | * @throws MapperSearchResponseException |
||
| 116 | * @throws MapperSearchResultException |
||
| 117 | * @throws MapperSearchKeyException |
||
| 118 | * @throws MapperSearchLimitException |
||
| 119 | * @throws MapperException |
||
| 120 | * |
||
| 121 | * @return Location |
||
| 122 | */ |
||
| 123 | public function location($location) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Add a new map. |
||
| 206 | * |
||
| 207 | * @param float $latitude |
||
| 208 | * @param float $longitude |
||
| 209 | * @param array $options |
||
| 210 | * |
||
| 211 | * @return self |
||
| 212 | */ |
||
| 213 | public function map($latitude, $longitude, array $options = []) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Add a new street view map. |
||
| 233 | * |
||
| 234 | * @param float $latitude |
||
| 235 | * @param float $longitude |
||
| 236 | * @param int $heading |
||
| 237 | * @param int $pitch |
||
| 238 | * @param array $options |
||
| 239 | * |
||
| 240 | * @return self |
||
| 241 | */ |
||
| 242 | public function streetview($latitude, $longitude, $heading, $pitch, array $options = []) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Add a new map marker. |
||
| 264 | * |
||
| 265 | * @param float $latitude |
||
| 266 | * @param float $longitude |
||
| 267 | * @param array $options |
||
| 268 | * |
||
| 269 | * @throws MapperException |
||
| 270 | * |
||
| 271 | * @return self |
||
| 272 | */ |
||
| 273 | public function marker($latitude, $longitude, array $options = []) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Add a new map information window. |
||
| 295 | * |
||
| 296 | * @param float $latitude |
||
| 297 | * @param float $longitude |
||
| 298 | * @param string $content |
||
| 299 | * @param array $options |
||
| 300 | * |
||
| 301 | * @throws MapperException |
||
| 302 | * |
||
| 303 | * @return self |
||
| 304 | */ |
||
| 305 | public function informationWindow($latitude, $longitude, $content = '', array $options = []) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Add a new map polyline. |
||
| 330 | * |
||
| 331 | * @param array $coordinates |
||
| 332 | * @param array $options |
||
| 333 | * |
||
| 334 | * @throws MapperException |
||
| 335 | * |
||
| 336 | * @return self |
||
| 337 | */ |
||
| 338 | public function polyline(array $coordinates = [], array $options = []) |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Add a new map polygon. |
||
| 368 | * |
||
| 369 | * @param array $coordinates |
||
| 370 | * @param array $options |
||
| 371 | * |
||
| 372 | * @throws MapperException |
||
| 373 | * |
||
| 374 | * @return self |
||
| 375 | */ |
||
| 376 | public function polygon(array $coordinates = [], array $options = []) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Add a new map rectangle. |
||
| 407 | * |
||
| 408 | * @param array $coordinates |
||
| 409 | * @param array $options |
||
| 410 | * |
||
| 411 | * @throws MapperException |
||
| 412 | * |
||
| 413 | * @return self |
||
| 414 | */ |
||
| 415 | public function rectangle(array $coordinates = [], array $options = []) |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Add a new map circle. |
||
| 446 | * |
||
| 447 | * @param array $coordinates |
||
| 448 | * @param array $options |
||
| 449 | * |
||
| 450 | * @throws MapperException |
||
| 451 | * |
||
| 452 | * @return self |
||
| 453 | */ |
||
| 454 | public function circle(array $coordinates = [], array $options = []) |
||
| 483 | } |
||
| 484 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.