| 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 |
||
| 122 | protected function addLogosAndIcons(FieldList $fields) |
||
| 123 | { |
||
| 124 | $logoTypes = array('jpg', 'jpeg', 'png', 'gif'); |
||
| 125 | $iconTypes = array('ico'); |
||
| 126 | $appleTouchTypes = array('png'); |
||
| 127 | |||
| 128 | $fields->findOrMakeTab( |
||
| 129 | 'Root.LogosIcons', |
||
| 130 | _t(__CLASS__ . '.LogosIconsTab', 'Logos/Icons') |
||
| 131 | ); |
||
| 132 | |||
| 133 | $fields->addFieldToTab( |
||
| 134 | 'Root.LogosIcons', |
||
| 135 | $logoField = Injector::inst()->create( |
||
| 136 | FileHandleField::class, |
||
| 137 | 'Logo', |
||
| 138 | _t(__CLASS__ . '.LogoUploadField', 'Logo, to appear in the top left') |
||
| 139 | ) |
||
| 140 | ); |
||
| 141 | $logoField->getValidator()->setAllowedExtensions($logoTypes); |
||
| 142 | |||
| 143 | $fields->addFieldToTab( |
||
| 144 | 'Root.LogosIcons', |
||
| 145 | $logoRetinaField = Injector::inst()->create( |
||
| 146 | FileHandleField::class, |
||
| 147 | 'LogoRetina', |
||
| 148 | _t( |
||
| 149 | 'CwpConfig.LogoRetinaUploadField', |
||
| 150 | 'High resolution logo, to appear in the top left ' . |
||
| 151 | '(recommended to be twice the height and width of the standard logo)' |
||
| 152 | ) |
||
| 153 | ) |
||
| 154 | ); |
||
| 155 | $logoRetinaField->getValidator()->setAllowedExtensions($logoTypes); |
||
| 156 | |||
| 157 | $fields->addFieldToTab( |
||
| 158 | 'Root.LogosIcons', |
||
| 159 | $footerLogoField = Injector::inst()->create( |
||
| 160 | FileHandleField::class, |
||
| 161 | 'FooterLogo', |
||
| 162 | _t(__CLASS__ . '.FooterLogoField', 'Footer logo, to appear in the footer') |
||
| 163 | ) |
||
| 164 | ); |
||
| 165 | $footerLogoField->getValidator()->setAllowedExtensions($logoTypes); |
||
| 166 | |||
| 167 | $fields->addFieldToTab( |
||
| 168 | 'Root.LogosIcons', |
||
| 169 | $footerLogoRetinaField = Injector::inst()->create( |
||
| 170 | FileHandleField::class, |
||
| 171 | 'FooterLogoRetina', |
||
| 172 | _t( |
||
| 173 | 'CwpConfig.FooterLogoRetinaField', |
||
| 174 | 'High resolution footer logo (recommended twice the height and width of the standard footer logo)' |
||
| 175 | ) |
||
| 176 | ) |
||
| 177 | ); |
||
| 178 | $footerLogoRetinaField->getValidator()->setAllowedExtensions($logoTypes); |
||
| 179 | |||
| 180 | $fields->addFieldToTab( |
||
| 181 | 'Root.LogosIcons', |
||
| 182 | $footerLink = TextField::create( |
||
| 183 | 'FooterLogoLink', |
||
| 184 | _t(__CLASS__ . '.FooterLogoLinkField', 'Footer Logo link') |
||
| 185 | ) |
||
| 186 | ); |
||
| 187 | $footerLink->setRightTitle( |
||
| 188 | _t( |
||
| 189 | 'CwpConfig.FooterLogoLinkDesc', |
||
| 190 | 'Please include the protocol (ie, http:// or https://) unless it is an internal link.' |
||
| 191 | ) |
||
| 192 | ); |
||
| 193 | |||
| 194 | $fields->addFieldToTab( |
||
| 195 | 'Root.LogosIcons', |
||
| 196 | TextField::create( |
||
| 197 | 'FooterLogoDescription', |
||
| 198 | _t(__CLASS__ . '.FooterLogoDescField', 'Footer Logo description') |
||
| 199 | ) |
||
| 200 | ); |
||
| 201 | |||
| 202 | $fields->addFieldToTab( |
||
| 203 | 'Root.LogosIcons', |
||
| 204 | $footerLogoSecondaryField = Injector::inst()->create( |
||
| 205 | FileHandleField::class, |
||
| 206 | 'FooterLogoSecondary', |
||
| 207 | _t(__CLASS__ . '.FooterLogoSecondaryField', 'Secondary Footer Logo, to appear in the footer.') |
||
| 208 | ) |
||
| 209 | ); |
||
| 210 | $footerLogoSecondaryField->getValidator()->setAllowedExtensions($logoTypes); |
||
| 211 | |||
| 212 | $fields->addFieldToTab('Root.LogosIcons', $footerSecondaryLink = TextField::create( |
||
| 213 | 'FooterLogoSecondaryLink', |
||
| 214 | _t(__CLASS__ . '.FooterLogoSecondaryLinkField', 'Secondary Footer Logo link.') |
||
| 215 | )); |
||
| 216 | $footerSecondaryLink->setRightTitle(_t( |
||
| 217 | 'CwpConfig.FooterLogoSecondaryLinkDesc', |
||
| 218 | 'Please include the protocol (ie, http:// or https://) unless it is an internal link.' |
||
| 219 | )); |
||
| 220 | $fields->addFieldToTab('Root.LogosIcons', TextField::create( |
||
| 221 | 'FooterLogoSecondaryDescription', |
||
| 222 | _t(__CLASS__ . '.FooterLogoSecondaryDescField', 'Secondary Footer Logo description') |
||
| 223 | )); |
||
| 224 | |||
| 225 | $fields->addFieldToTab( |
||
| 226 | 'Root.LogosIcons', |
||
| 227 | $favIconField = Injector::inst()->create( |
||
| 228 | FileHandleField::class, |
||
| 229 | 'FavIcon', |
||
| 230 | _t(__CLASS__ . '.FavIconField', 'Favicon, in .ico format, dimensions of 16x16, 32x32, or 48x48') |
||
| 231 | ) |
||
| 232 | ); |
||
| 233 | $favIconField->getValidator()->setAllowedExtensions($iconTypes); |
||
| 234 | |||
| 235 | $fields->addFieldToTab( |
||
| 236 | 'Root.LogosIcons', |
||
| 237 | $atIcon144 = Injector::inst()->create( |
||
| 238 | FileHandleField::class, |
||
| 239 | 'AppleTouchIcon144', |
||
| 240 | _t( |
||
| 241 | 'CwpConfig.AppleIconField144', |
||
| 242 | 'Apple Touch Web Clip and Windows 8 Tile Icon (dimensions of 144x144, PNG format)' |
||
| 243 | ) |
||
| 244 | ) |
||
| 245 | ); |
||
| 246 | $atIcon144->getValidator()->setAllowedExtensions($appleTouchTypes); |
||
| 247 | |||
| 248 | $fields->addFieldToTab( |
||
| 249 | 'Root.LogosIcons', |
||
| 250 | $atIcon114 = Injector::inst()->create( |
||
| 251 | FileHandleField::class, |
||
| 252 | 'AppleTouchIcon114', |
||
| 253 | _t(__CLASS__ . '.AppleIconField114', 'Apple Touch Web Clip Icon (dimensions of 114x114, PNG format)') |
||
| 254 | ) |
||
| 255 | ); |
||
| 256 | $atIcon114->getValidator()->setAllowedExtensions($appleTouchTypes); |
||
| 257 | |||
| 258 | $fields->addFieldToTab( |
||
| 259 | 'Root.LogosIcons', |
||
| 260 | $atIcon72 = Injector::inst()->create( |
||
| 261 | FileHandleField::class, |
||
| 262 | 'AppleTouchIcon72', |
||
| 263 | _t(__CLASS__ . '.AppleIconField72', 'Apple Touch Web Clip Icon (dimensions of 72x72, PNG format)') |
||
| 264 | ) |
||
| 265 | ); |
||
| 266 | $atIcon72->getValidator()->setAllowedExtensions($appleTouchTypes); |
||
| 267 | |||
| 268 | $fields->addFieldToTab( |
||
| 269 | 'Root.LogosIcons', |
||
| 270 | $atIcon57 = Injector::inst()->create( |
||
| 271 | FileHandleField::class, |
||
| 272 | 'AppleTouchIcon57', |
||
| 273 | _t(__CLASS__ . '.AppleIconField57', 'Apple Touch Web Clip Icon (dimensions of 57x57, PNG format)') |
||
| 274 | ) |
||
| 275 | ); |
||
| 276 | $atIcon57->getValidator()->setAllowedExtensions($appleTouchTypes); |
||
| 277 | |||
| 278 | return $this; |
||
| 279 | } |
||
| 339 |