Conditions | 1 |
Paths | 1 |
Total Lines | 157 |
Code Lines | 107 |
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 |
||
191 | protected function addLogosAndIcons(FieldList $fields) |
||
192 | { |
||
193 | $logoTypes = array('jpg', 'jpeg', 'png', 'gif'); |
||
194 | $iconTypes = array('ico'); |
||
195 | $appleTouchTypes = array('png'); |
||
196 | |||
197 | $fields->findOrMakeTab( |
||
198 | 'Root.LogosIcons', |
||
199 | _t(__CLASS__ . '.LogosIconsTab', 'Logos/Icons') |
||
200 | ); |
||
201 | |||
202 | $fields->addFieldToTab( |
||
203 | 'Root.LogosIcons', |
||
204 | $logoField = Injector::inst()->create( |
||
205 | FileHandleField::class, |
||
206 | 'Logo', |
||
207 | _t(__CLASS__ . '.LogoUploadField', 'Logo, to appear in the top left') |
||
208 | ) |
||
209 | ); |
||
210 | $logoField->getValidator()->setAllowedExtensions($logoTypes); |
||
211 | |||
212 | $fields->addFieldToTab( |
||
213 | 'Root.LogosIcons', |
||
214 | $logoRetinaField = Injector::inst()->create( |
||
215 | FileHandleField::class, |
||
216 | 'LogoRetina', |
||
217 | _t( |
||
218 | 'CwpConfig.LogoRetinaUploadField', |
||
219 | 'High resolution logo, to appear in the top left ' . |
||
220 | '(recommended to be twice the height and width of the standard logo)' |
||
221 | ) |
||
222 | ) |
||
223 | ); |
||
224 | $logoRetinaField->getValidator()->setAllowedExtensions($logoTypes); |
||
225 | |||
226 | $fields->addFieldToTab( |
||
227 | 'Root.LogosIcons', |
||
228 | $footerLogoField = Injector::inst()->create( |
||
229 | FileHandleField::class, |
||
230 | 'FooterLogo', |
||
231 | _t(__CLASS__ . '.FooterLogoField', 'Footer logo, to appear in the footer') |
||
232 | ) |
||
233 | ); |
||
234 | $footerLogoField->getValidator()->setAllowedExtensions($logoTypes); |
||
235 | |||
236 | $fields->addFieldToTab( |
||
237 | 'Root.LogosIcons', |
||
238 | $footerLogoRetinaField = Injector::inst()->create( |
||
239 | FileHandleField::class, |
||
240 | 'FooterLogoRetina', |
||
241 | _t( |
||
242 | 'CwpConfig.FooterLogoRetinaField', |
||
243 | 'High resolution footer logo (recommended twice the height and width of the standard footer logo)' |
||
244 | ) |
||
245 | ) |
||
246 | ); |
||
247 | $footerLogoRetinaField->getValidator()->setAllowedExtensions($logoTypes); |
||
248 | |||
249 | $fields->addFieldToTab( |
||
250 | 'Root.LogosIcons', |
||
251 | $footerLink = TextField::create( |
||
252 | 'FooterLogoLink', |
||
253 | _t(__CLASS__ . '.FooterLogoLinkField', 'Footer Logo link') |
||
254 | ) |
||
255 | ); |
||
256 | $footerLink->setRightTitle( |
||
257 | _t( |
||
258 | 'CwpConfig.FooterLogoLinkDesc', |
||
259 | 'Please include the protocol (ie, http:// or https://) unless it is an internal link.' |
||
260 | ) |
||
261 | ); |
||
262 | |||
263 | $fields->addFieldToTab( |
||
264 | 'Root.LogosIcons', |
||
265 | TextField::create( |
||
266 | 'FooterLogoDescription', |
||
267 | _t(__CLASS__ . '.FooterLogoDescField', 'Footer Logo description') |
||
268 | ) |
||
269 | ); |
||
270 | |||
271 | $fields->addFieldToTab( |
||
272 | 'Root.LogosIcons', |
||
273 | $footerLogoSecondaryField = Injector::inst()->create( |
||
274 | FileHandleField::class, |
||
275 | 'FooterLogoSecondary', |
||
276 | _t(__CLASS__ . '.FooterLogoSecondaryField', 'Secondary Footer Logo, to appear in the footer.') |
||
277 | ) |
||
278 | ); |
||
279 | $footerLogoSecondaryField->getValidator()->setAllowedExtensions($logoTypes); |
||
280 | |||
281 | $fields->addFieldToTab('Root.LogosIcons', $footerSecondaryLink = TextField::create( |
||
282 | 'FooterLogoSecondaryLink', |
||
283 | _t(__CLASS__ . '.FooterLogoSecondaryLinkField', 'Secondary Footer Logo link.') |
||
284 | )); |
||
285 | $footerSecondaryLink->setRightTitle(_t( |
||
286 | 'CwpConfig.FooterLogoSecondaryLinkDesc', |
||
287 | 'Please include the protocol (ie, http:// or https://) unless it is an internal link.' |
||
288 | )); |
||
289 | $fields->addFieldToTab('Root.LogosIcons', TextField::create( |
||
290 | 'FooterLogoSecondaryDescription', |
||
291 | _t(__CLASS__ . '.FooterLogoSecondaryDescField', 'Secondary Footer Logo description') |
||
292 | )); |
||
293 | |||
294 | $fields->addFieldToTab( |
||
295 | 'Root.LogosIcons', |
||
296 | $favIconField = Injector::inst()->create( |
||
297 | FileHandleField::class, |
||
298 | 'FavIcon', |
||
299 | _t(__CLASS__ . '.FavIconField', 'Favicon, in .ico format, dimensions of 16x16, 32x32, or 48x48') |
||
300 | ) |
||
301 | ); |
||
302 | $favIconField->getValidator()->setAllowedExtensions($iconTypes); |
||
303 | |||
304 | $fields->addFieldToTab( |
||
305 | 'Root.LogosIcons', |
||
306 | $atIcon144 = Injector::inst()->create( |
||
307 | FileHandleField::class, |
||
308 | 'AppleTouchIcon144', |
||
309 | _t( |
||
310 | 'CwpConfig.AppleIconField144', |
||
311 | 'Apple Touch Web Clip and Windows 8 Tile Icon (dimensions of 144x144, PNG format)' |
||
312 | ) |
||
313 | ) |
||
314 | ); |
||
315 | $atIcon144->getValidator()->setAllowedExtensions($appleTouchTypes); |
||
316 | |||
317 | $fields->addFieldToTab( |
||
318 | 'Root.LogosIcons', |
||
319 | $atIcon114 = Injector::inst()->create( |
||
320 | FileHandleField::class, |
||
321 | 'AppleTouchIcon114', |
||
322 | _t(__CLASS__ . '.AppleIconField114', 'Apple Touch Web Clip Icon (dimensions of 114x114, PNG format)') |
||
323 | ) |
||
324 | ); |
||
325 | $atIcon114->getValidator()->setAllowedExtensions($appleTouchTypes); |
||
326 | |||
327 | $fields->addFieldToTab( |
||
328 | 'Root.LogosIcons', |
||
329 | $atIcon72 = Injector::inst()->create( |
||
330 | FileHandleField::class, |
||
331 | 'AppleTouchIcon72', |
||
332 | _t(__CLASS__ . '.AppleIconField72', 'Apple Touch Web Clip Icon (dimensions of 72x72, PNG format)') |
||
333 | ) |
||
334 | ); |
||
335 | $atIcon72->getValidator()->setAllowedExtensions($appleTouchTypes); |
||
336 | |||
337 | $fields->addFieldToTab( |
||
338 | 'Root.LogosIcons', |
||
339 | $atIcon57 = Injector::inst()->create( |
||
340 | FileHandleField::class, |
||
341 | 'AppleTouchIcon57', |
||
342 | _t(__CLASS__ . '.AppleIconField57', 'Apple Touch Web Clip Icon (dimensions of 57x57, PNG format)') |
||
343 | ) |
||
344 | ); |
||
345 | $atIcon57->getValidator()->setAllowedExtensions($appleTouchTypes); |
||
346 | |||
347 | return $this; |
||
348 | } |
||
557 |