| Conditions | 3 |
| Paths | 2 |
| Total Lines | 54 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 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 |
||
| 52 | public function FieldHolder($properties = array()) { |
||
| 53 | Requirements::javascript(THIRDPARTY_DIR.'/jquery/jquery.js'); |
||
| 54 | Requirements::javascript(THIRDPARTY_DIR.'/jquery-livequery/jquery.livequery.js'); |
||
| 55 | Requirements::javascript(THIRDPARTY_DIR.'/jquery-metadata/jquery.metadata.js'); |
||
| 56 | Requirements::javascript(MAPPABLE_MODULE_PATH.'/javascript/mapField.js'); |
||
| 57 | |||
| 58 | $attributes = array( |
||
| 59 | 'class' => 'editableMap', |
||
| 60 | 'id' => 'GoogleMap', |
||
| 61 | 'data-LatFieldName' => $this->latField, |
||
| 62 | 'data-LonFieldName' => $this->longField, |
||
| 63 | 'data-ZoomFieldName' => $this->zoomField, |
||
| 64 | 'data-UseMapBounds' => false |
||
| 65 | ); |
||
| 66 | |||
| 67 | Requirements::css('mappable/css/mapField.css'); |
||
| 68 | |||
| 69 | // check for and if required add guide points |
||
| 70 | if (!empty($this->guidePoints)) { |
||
| 71 | $latlongps = array(); |
||
| 72 | |||
| 73 | foreach ($this->guidePoints as $guidepoint) { |
||
| 74 | array_push($latlongps, $guidepoint); |
||
| 75 | } |
||
| 76 | |||
| 77 | $guidePointsJSON = json_encode($latlongps); |
||
| 78 | // convert the mappable guidepoints to lat lon |
||
| 79 | |||
| 80 | $attributes['data-GuidePoints'] = $guidePointsJSON; |
||
| 81 | |||
| 82 | // we only wish to change the bounds to those of all the points iff |
||
| 83 | // the item currently has no location |
||
| 84 | $attributes['data-useMapBounds'] = true; |
||
| 85 | } |
||
| 86 | $content = '<div class="editableMapWrapper">'.$this->create_tag( |
||
| 87 | "div", |
||
| 88 | $attributes |
||
| 89 | ).'</div>'; |
||
| 90 | |||
| 91 | $this->FieldList()->push(new LiteralField('locationEditor', $content)); |
||
| 92 | |||
| 93 | $content2 = <<<HTML |
||
| 94 | <div id="mapSearch"> |
||
| 95 | <input name="location_search" id="location_search" size=80/> |
||
| 96 | <button class="action" id="searchLocationButton">Search Location Name</button> |
||
| 97 | <div id="mapSearchResults"> |
||
| 98 | </div> |
||
| 99 | </div> |
||
| 100 | HTML; |
||
| 101 | |||
| 102 | $this->FieldList()->push(new LiteralField('mapSearch', $content2)); |
||
| 103 | |||
| 104 | return parent::FieldHolder(); |
||
| 105 | } |
||
| 106 | |||
| 128 |