| Conditions | 16 |
| Paths | 128 |
| Total Lines | 49 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 32 | public function read($address, $return_type = 'point', $bounds = FALSE, $return_multiple = FALSE) { |
||
| 33 | if (is_array($address)) $address = join(',', $address); |
||
| 34 | |||
| 35 | if (gettype($bounds) == 'object') { |
||
| 36 | $bounds = $bounds->getBBox(); |
||
| 37 | } |
||
| 38 | if (gettype($bounds) == 'array') { |
||
| 39 | $bounds_string = '&bounds='.$bounds['miny'].','.$bounds['minx'].'|'.$bounds['maxy'].','.$bounds['maxx']; |
||
| 40 | } |
||
| 41 | else { |
||
| 42 | $bounds_string = ''; |
||
| 43 | } |
||
| 44 | |||
| 45 | $url = "http://maps.googleapis.com/maps/api/geocode/json"; |
||
| 46 | $url .= '?address='. urlencode($address); |
||
| 47 | $url .= $bounds_string; |
||
| 48 | $url .= '&sensor=false'; |
||
| 49 | $this->result = json_decode(@file_get_contents($url)); |
||
| 50 | |||
| 51 | if ($this->result->status == 'OK') { |
||
| 52 | if ($return_multiple == FALSE) { |
||
| 53 | if ($return_type == 'point') { |
||
| 54 | return $this->getPoint(); |
||
| 55 | } |
||
| 56 | if ($return_type == 'bounds' || $return_type == 'polygon') { |
||
| 57 | return $this->getPolygon(); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | if ($return_multiple == TRUE) { |
||
| 61 | if ($return_type == 'point') { |
||
| 62 | $points = array(); |
||
| 63 | foreach ($this->result->results as $delta => $item) { |
||
| 64 | $points[] = $this->getPoint($delta); |
||
| 65 | } |
||
| 66 | return new MultiPoint($points); |
||
| 67 | } |
||
| 68 | if ($return_type == 'bounds' || $return_type == 'polygon') { |
||
| 69 | $polygons = array(); |
||
| 70 | foreach ($this->result->results as $delta => $item) { |
||
| 71 | $polygons[] = $this->getPolygon($delta); |
||
| 72 | } |
||
| 73 | return new MultiPolygon($polygons); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | else { |
||
| 78 | if ($this->result->status) throw new Exception('Error in Google Geocoder: '.$this->result->status); |
||
| 79 | else throw new Exception('Unknown error in Google Geocoder'); |
||
| 80 | return FALSE; |
||
| 81 | } |
||
| 167 |