Complex classes like Polygon 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 Polygon, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | class Polygon implements PolygonInterface, \Countable, \IteratorAggregate, \ArrayAccess, \JsonSerializable |
||
25 | { |
||
26 | const TYPE = 'POLYGON'; |
||
27 | |||
28 | /** |
||
29 | * @var CoordinateCollection |
||
30 | */ |
||
31 | private $coordinates; |
||
32 | |||
33 | /** |
||
34 | * @var BoundingBoxInterface |
||
35 | */ |
||
36 | private $boundingBox; |
||
37 | |||
38 | /** |
||
39 | * @var boolean |
||
40 | */ |
||
41 | private $hasCoordinate = false; |
||
42 | |||
43 | /** |
||
44 | * @var integer |
||
45 | */ |
||
46 | private $precision = 8; |
||
47 | |||
48 | /** |
||
49 | * @param null|array|CoordinateCollection $coordinates |
||
50 | */ |
||
51 | 38 | public function __construct($coordinates = null) |
|
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getGeometryType() |
||
76 | |||
77 | /** |
||
78 | * @return Ellipsoid |
||
79 | */ |
||
80 | 17 | public function getEllipsoid() |
|
84 | |||
85 | /** |
||
86 | * @return Coordinate |
||
87 | */ |
||
88 | 1 | public function getCoordinate() |
|
92 | |||
93 | /** |
||
94 | * @return boolean |
||
95 | */ |
||
96 | 8 | public function isEmpty() |
|
100 | |||
101 | |||
102 | /** |
||
103 | * @param CoordinateInterface $coordinate |
||
104 | * @return boolean |
||
105 | */ |
||
106 | 4 | public function pointInPolygon(CoordinateInterface $coordinate) |
|
179 | |||
180 | /** |
||
181 | * @param CoordinateInterface $coordinate |
||
182 | * @return boolean |
||
183 | */ |
||
184 | 6 | public function pointOnBoundary(CoordinateInterface $coordinate) |
|
256 | |||
257 | /** |
||
258 | * @param CoordinateInterface $coordinate |
||
259 | * @return boolean |
||
260 | */ |
||
261 | 6 | public function pointOnVertex(CoordinateInterface $coordinate) |
|
281 | |||
282 | /** |
||
283 | * {@inheritDoc} |
||
284 | */ |
||
285 | 38 | public function getCoordinates() |
|
289 | |||
290 | /** |
||
291 | * {@inheritDoc} |
||
292 | */ |
||
293 | public function setCoordinates(CoordinateCollection $coordinates) |
||
300 | |||
301 | /** |
||
302 | * @return array |
||
303 | */ |
||
304 | public function toArray() |
||
308 | |||
309 | /** |
||
310 | * {@inheritDoc} |
||
311 | */ |
||
312 | public function jsonSerialize() |
||
316 | |||
317 | /** |
||
318 | * {@inheritDoc} |
||
319 | */ |
||
320 | public function offsetExists($offset) |
||
324 | |||
325 | /** |
||
326 | * {@inheritDoc} |
||
327 | */ |
||
328 | public function offsetGet($offset) |
||
332 | |||
333 | /** |
||
334 | * {@inheritDoc} |
||
335 | */ |
||
336 | public function offsetSet($offset, $value) |
||
341 | |||
342 | /** |
||
343 | * {@inheritDoc} |
||
344 | */ |
||
345 | public function offsetUnset($offset) |
||
351 | |||
352 | /** |
||
353 | * {@inheritDoc} |
||
354 | */ |
||
355 | 7 | public function count() |
|
359 | |||
360 | /** |
||
361 | * {@inheritDoc} |
||
362 | */ |
||
363 | public function getIterator() |
||
367 | |||
368 | /** |
||
369 | * {@inheritDoc} |
||
370 | */ |
||
371 | 7 | public function get($key) |
|
375 | |||
376 | /** |
||
377 | * {@inheritDoc} |
||
378 | */ |
||
379 | 17 | public function set($key, CoordinateInterface $coordinate = null) |
|
399 | |||
400 | /** |
||
401 | * {@inheritDoc} |
||
402 | */ |
||
403 | 1 | public function add(CoordinateInterface $coordinate) |
|
412 | |||
413 | /** |
||
414 | * {@inheritDoc} |
||
415 | */ |
||
416 | public function remove($key) |
||
427 | |||
428 | /** |
||
429 | * @return integer |
||
430 | */ |
||
431 | 22 | public function getPrecision() |
|
435 | |||
436 | /** |
||
437 | * @param integer $precision |
||
438 | * @return $this |
||
439 | */ |
||
440 | 1 | public function setPrecision($precision) |
|
447 | |||
448 | /** |
||
449 | * @return BoundingBoxInterface |
||
450 | */ |
||
451 | 2 | public function getBoundingBox() |
|
455 | |||
456 | /** |
||
457 | * @param BoundingBoxInterface $boundingBox |
||
458 | * @return $this |
||
459 | */ |
||
460 | public function setBoundingBox(BoundingBoxInterface $boundingBox) |
||
466 | } |
||
467 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.