Conditions | 6 |
Paths | 18 |
Total Lines | 57 |
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 |
||
72 | public function __construct($controller, $name, $defaultAddress = "", $classNamesSearchedFor = array("SiteTree")) |
||
73 | { |
||
74 | $this->defaultAddress = $defaultAddress; |
||
75 | if (!$this->defaultAddress) { |
||
76 | $this->defaultAddress = isset($_GET["FindNearAddress"]) ? $_GET["FindNearAddress"] : ""; |
||
77 | } |
||
78 | $classNamesAsString = ''; |
||
79 | if (is_array($classNamesSearchedFor)) { |
||
80 | $this->classNamesSearchedFor = $classNamesSearchedFor; |
||
81 | $classNamesAsString = implode(",", $this->classNamesSearchedFor); |
||
82 | } |
||
83 | parent::__construct( |
||
84 | $controller, |
||
85 | "SearchByAddressForm", |
||
86 | new FieldList( |
||
87 | $addressField = new TextField( |
||
88 | "FindNearAddress", |
||
89 | _t("GoogleMapLocationsDOD.ENTERLOCATION", "Enter your location"), |
||
90 | $this->defaultAddress |
||
91 | ), |
||
92 | new HiddenField("ClassNamesSearchedFor", "ClassName", $classNamesAsString) |
||
93 | ), |
||
94 | new FieldList(new FormAction("findnearaddress", _t("GoogleMapLocationsDOD.SEARCH", "Search"))), |
||
95 | new RequiredFields("FindNearAddress") |
||
96 | ); |
||
97 | $addressField->setAttribute('placeholder', _t('GoogleMapLocationsDOD.YOUR_ADDRESS', "Enter your exact address or zip code here.")) ; |
||
98 | if ($this->useAutocomplete) { |
||
99 | $apiVersion = Config::inst()->get("GoogleMap", "api_version"); |
||
100 | Requirements::javascript( |
||
101 | "//maps.googleapis.com/maps/api/js" |
||
102 | ."?v=".$apiVersion |
||
103 | ."&libraries=places" |
||
104 | ."&key=".Config::inst()->get('GoogleMap', 'google_map_api_key') |
||
105 | ); |
||
106 | $typeOfResult = $this->Config()->get('type_of_result'); |
||
107 | $setTypeLine = ''; |
||
108 | if ($typeOfResult) { |
||
109 | $setTypeLine = 'autocomplete.setTypes([\''.$typeOfResult.'\']);'; |
||
110 | } |
||
111 | Requirements::customScript( |
||
112 | ' |
||
113 | function init_search_by_address_form() { |
||
114 | var input = document.getElementById("'.$this->getName()."_".$this->getName().'_FindNearAddress"); |
||
115 | var options = { |
||
116 | \'location_type\' : \'ROOFTOP\' |
||
117 | }; |
||
118 | var autocomplete = new google.maps.places.Autocomplete(input, options); |
||
119 | '.$setTypeLine.' |
||
120 | } |
||
121 | google.maps.event.addDomListener(window, "load", init_search_by_address_form); |
||
122 | ', |
||
123 | "SearchByAddressFormInit" |
||
124 | ); |
||
125 | } |
||
126 | $this->disableSecurityToken(); |
||
127 | return $this; |
||
128 | } |
||
129 | |||
195 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.