| Total Complexity | 44 |
| Total Lines | 356 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ThemeIcons often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ThemeIcons, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 37 | class ThemeIcons |
||
| 38 | { |
||
| 39 | /** |
||
| 40 | * @var IconInterface[] |
||
| 41 | */ |
||
| 42 | private $icons = []; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @return IconInterface |
||
| 46 | */ |
||
| 47 | public function getIconWarning() |
||
| 48 | { |
||
| 49 | return $this->getIconByName('warning'); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param string $name |
||
| 54 | * |
||
| 55 | * @return IconInterface |
||
| 56 | */ |
||
| 57 | public function getIconByName(string $name) |
||
| 58 | { |
||
| 59 | if (isset($this->icons[$name])) { |
||
| 60 | return $this->icons[$name]; |
||
| 61 | } |
||
| 62 | |||
| 63 | return new FontIcon($name, 'mdl-color-text--indigo-A200'); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @return IconInterface |
||
| 68 | */ |
||
| 69 | public function getIconDownload() |
||
| 70 | { |
||
| 71 | return $this->getIconByName('download'); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @return IconInterface |
||
| 76 | */ |
||
| 77 | public function getIconClear() |
||
| 78 | { |
||
| 79 | return $this->getIconByName('clear'); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return IconInterface |
||
| 84 | */ |
||
| 85 | public function getIconPlay() |
||
| 86 | { |
||
| 87 | return $this->getIconByName('play'); |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @return IconInterface |
||
| 92 | */ |
||
| 93 | public function getIconHelp() |
||
| 94 | { |
||
| 95 | return $this->getIconByName('help'); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return IconInterface |
||
| 100 | */ |
||
| 101 | public function getIconPublicLink() |
||
| 102 | { |
||
| 103 | return $this->getIconByName('publicLink'); |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @return IconInterface |
||
| 108 | */ |
||
| 109 | public function getIconBack() |
||
| 110 | { |
||
| 111 | return $this->getIconByName('back'); |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @return IconInterface |
||
| 116 | */ |
||
| 117 | public function getIconRestore() |
||
| 118 | { |
||
| 119 | return $this->getIconByName('restore'); |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @return IconInterface |
||
| 124 | */ |
||
| 125 | public function getIconSave() |
||
| 126 | { |
||
| 127 | return $this->getIconByName('save'); |
||
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @return IconInterface |
||
| 132 | */ |
||
| 133 | public function getIconUp() |
||
| 134 | { |
||
| 135 | return $this->getIconByName('up'); |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @return IconInterface |
||
| 140 | */ |
||
| 141 | public function getIconDown() |
||
| 142 | { |
||
| 143 | return $this->getIconByName('down'); |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @return IconInterface |
||
| 148 | */ |
||
| 149 | public function getIconViewPass() |
||
| 150 | { |
||
| 151 | return $this->getIconByName('viewPass'); |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @return IconInterface |
||
| 156 | */ |
||
| 157 | public function getIconCopy() |
||
| 158 | { |
||
| 159 | return $this->getIconByName('copy'); |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return IconInterface |
||
| 164 | */ |
||
| 165 | public function getIconClipboard() |
||
| 166 | { |
||
| 167 | return $this->getIconByName('clipboard'); |
||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @return IconInterface |
||
| 172 | */ |
||
| 173 | public function getIconEmail() |
||
| 174 | { |
||
| 175 | return $this->getIconByName('email'); |
||
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @return IconInterface |
||
| 180 | */ |
||
| 181 | public function getIconRefresh() |
||
| 182 | { |
||
| 183 | return $this->getIconByName('refresh'); |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @return IconInterface |
||
| 188 | */ |
||
| 189 | public function getIconEditPass() |
||
| 190 | { |
||
| 191 | return $this->getIconByName('editPass'); |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @return IconInterface |
||
| 196 | */ |
||
| 197 | public function getIconAppAdmin() |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @return IconInterface |
||
| 204 | */ |
||
| 205 | public function getIconAccAdmin() |
||
| 206 | { |
||
| 207 | return $this->getIconByName('accAdmin'); |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @return IconInterface |
||
| 212 | */ |
||
| 213 | public function getIconLdapUser() |
||
| 214 | { |
||
| 215 | return $this->getIconByName('ldapUser'); |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @return IconInterface |
||
| 220 | */ |
||
| 221 | public function getIconDisabled() |
||
| 222 | { |
||
| 223 | return $this->getIconByName('disabled'); |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @return IconInterface |
||
| 228 | */ |
||
| 229 | public function getIconNavPrev() |
||
| 230 | { |
||
| 231 | return $this->getIconByName('previous'); |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @return IconInterface |
||
| 236 | */ |
||
| 237 | public function getIconNavNext() |
||
| 238 | { |
||
| 239 | return $this->getIconByName('next'); |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return IconInterface |
||
| 244 | */ |
||
| 245 | public function getIconNavFirst() |
||
| 246 | { |
||
| 247 | return $this->getIconByName('first'); |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @return IconInterface |
||
| 252 | */ |
||
| 253 | public function getIconNavLast() |
||
| 254 | { |
||
| 255 | return $this->getIconByName('last'); |
||
| 256 | } |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @return IconInterface |
||
| 260 | */ |
||
| 261 | public function getIconAdd() |
||
| 262 | { |
||
| 263 | return $this->getIconByName('add'); |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @return IconInterface |
||
| 268 | */ |
||
| 269 | public function getIconView() |
||
| 270 | { |
||
| 271 | return $this->getIconByName('view'); |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return IconInterface |
||
| 276 | */ |
||
| 277 | public function getIconEdit() |
||
| 278 | { |
||
| 279 | return $this->getIconByName('edit'); |
||
| 280 | } |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @return IconInterface |
||
| 284 | */ |
||
| 285 | public function getIconDelete() |
||
| 286 | { |
||
| 287 | return $this->getIconByName('delete'); |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @return IconInterface |
||
| 292 | */ |
||
| 293 | public function getIconOptional() |
||
| 294 | { |
||
| 295 | return $this->getIconByName('optional'); |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @return IconInterface |
||
| 300 | */ |
||
| 301 | public function getIconCheck() |
||
| 302 | { |
||
| 303 | return $this->getIconByName('check'); |
||
| 304 | } |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @return IconInterface |
||
| 308 | */ |
||
| 309 | public function getIconSearch() |
||
| 310 | { |
||
| 311 | return $this->getIconByName('search'); |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @return IconInterface |
||
| 316 | */ |
||
| 317 | public function getIconAccount() |
||
| 318 | { |
||
| 319 | return $this->getIconByName('account'); |
||
| 320 | } |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return IconInterface |
||
| 324 | */ |
||
| 325 | public function getIconGroup() |
||
| 326 | { |
||
| 327 | return $this->getIconByName('group'); |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return IconInterface |
||
| 332 | */ |
||
| 333 | public function getIconSettings() |
||
| 334 | { |
||
| 335 | return $this->getIconByName('settings'); |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @return IconInterface |
||
| 340 | */ |
||
| 341 | public function getIconHeadline() |
||
| 342 | { |
||
| 343 | return $this->getIconByName('headline'); |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @return IconInterface |
||
| 348 | */ |
||
| 349 | public function getIconInfo() |
||
| 350 | { |
||
| 351 | return $this->getIconByName('info'); |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return IconInterface |
||
| 356 | */ |
||
| 357 | public function getIconCritical() |
||
| 358 | { |
||
| 359 | return $this->getIconByName('critical'); |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @return IconInterface |
||
| 364 | */ |
||
| 365 | public function getIconEnabled() |
||
| 366 | { |
||
| 367 | return $this->getIconByName('enabled'); |
||
| 368 | } |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @return IconInterface |
||
| 372 | */ |
||
| 373 | public function getIconNotices() |
||
| 374 | { |
||
| 375 | return $this->getIconByName('notices'); |
||
| 376 | } |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @return IconInterface |
||
| 380 | */ |
||
| 381 | public function getIconRemove() |
||
| 382 | { |
||
| 383 | return $this->getIconByName('remove'); |
||
| 384 | } |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @param string $alias |
||
| 388 | * @param IconInterface $icon |
||
| 389 | */ |
||
| 390 | public function addIcon(string $alias, IconInterface $icon) |
||
| 393 | } |
||
| 394 | } |