Complex classes like Section 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Section, and based on these observations, apply Extract Interface, too.
| 1 | <?php namespace Anomaly\Streams\Platform\Ui\ControlPanel\Component\Section; |
||
| 12 | class Section implements SectionInterface |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * The section slug. |
||
| 17 | * |
||
| 18 | * @var null|string |
||
| 19 | */ |
||
| 20 | protected $slug = null; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The section icon. |
||
| 24 | * |
||
| 25 | * @var null|string |
||
| 26 | */ |
||
| 27 | protected $icon = null; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The section title. |
||
| 31 | * |
||
| 32 | * @var null|string |
||
| 33 | */ |
||
| 34 | protected $title = null; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The section label. |
||
| 38 | * |
||
| 39 | * @var null|string |
||
| 40 | */ |
||
| 41 | protected $label = null; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The class. |
||
| 45 | * |
||
| 46 | * @var null|string |
||
| 47 | */ |
||
| 48 | protected $class = null; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The active flag. |
||
| 52 | * |
||
| 53 | * @var bool |
||
| 54 | */ |
||
| 55 | protected $active = false; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The path matcher. |
||
| 59 | * |
||
| 60 | * @var null|string |
||
| 61 | */ |
||
| 62 | protected $matcher = null; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The section permalink. |
||
| 66 | * |
||
| 67 | * @var null|string |
||
| 68 | */ |
||
| 69 | protected $permalink = null; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The section description. |
||
| 73 | * |
||
| 74 | * @var null|string |
||
| 75 | */ |
||
| 76 | protected $description = null; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * The highlighted flag. |
||
| 80 | * |
||
| 81 | * @var bool |
||
| 82 | */ |
||
| 83 | protected $highlighted = false; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * The section context. |
||
| 87 | * |
||
| 88 | * @var string |
||
| 89 | */ |
||
| 90 | protected $context = 'danger'; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * The section parent. |
||
| 94 | * |
||
| 95 | * @var null|string |
||
| 96 | */ |
||
| 97 | protected $parent = null; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Section buttons. These are only to |
||
| 101 | * transport input to the button builder. |
||
| 102 | * |
||
| 103 | * @var array |
||
| 104 | */ |
||
| 105 | protected $buttons = []; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * The section attributes. |
||
| 109 | * |
||
| 110 | * @var array |
||
| 111 | */ |
||
| 112 | protected $attributes = []; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * The section permission. |
||
| 116 | * |
||
| 117 | * @var null|string |
||
| 118 | */ |
||
| 119 | protected $permission = null; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * The section breadcrumb. |
||
| 123 | * |
||
| 124 | * @var null|string |
||
| 125 | */ |
||
| 126 | protected $breadcrumb = null; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * If the section will be hidden from the Control Panel. |
||
| 130 | * |
||
| 131 | * @var bool |
||
| 132 | */ |
||
| 133 | protected $hidden = false; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Get the slug. |
||
| 137 | * |
||
| 138 | * @return null|string |
||
| 139 | */ |
||
| 140 | public function getSlug() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Set the slug. |
||
| 147 | * |
||
| 148 | * @param $slug |
||
| 149 | * @return $this |
||
| 150 | */ |
||
| 151 | public function setSlug($slug) |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Get the icon. |
||
| 160 | * |
||
| 161 | * @return null|string |
||
| 162 | */ |
||
| 163 | public function getIcon() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Set the icon. |
||
| 170 | * |
||
| 171 | * @param $icon |
||
| 172 | * @return $this |
||
| 173 | */ |
||
| 174 | public function setIcon($icon) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Get the title. |
||
| 183 | * |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | public function getTitle() |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Set the title. |
||
| 193 | * |
||
| 194 | * @param string $title |
||
| 195 | */ |
||
| 196 | public function setTitle($title) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Get the label. |
||
| 203 | * |
||
| 204 | * @return string |
||
| 205 | */ |
||
| 206 | public function getLabel() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Set the label. |
||
| 213 | * |
||
| 214 | * @param string $label |
||
| 215 | * @return $this |
||
| 216 | */ |
||
| 217 | public function setLabel($label) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Get the class. |
||
| 226 | * |
||
| 227 | * @return string |
||
| 228 | */ |
||
| 229 | public function getClass() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Set the class. |
||
| 236 | * |
||
| 237 | * @param $class |
||
| 238 | * @return $this |
||
| 239 | */ |
||
| 240 | public function setClass($class) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Get the active flag. |
||
| 249 | * |
||
| 250 | * @return boolean |
||
| 251 | */ |
||
| 252 | public function isActive() |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Set the active flag. |
||
| 259 | * |
||
| 260 | * @param boolean $active |
||
| 261 | */ |
||
| 262 | public function setActive($active) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Get the matcher. |
||
| 271 | * |
||
| 272 | * @return null|string |
||
| 273 | */ |
||
| 274 | public function getMatcher() |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Set the matcher. |
||
| 281 | * |
||
| 282 | * @param $matcher |
||
| 283 | * @return $this |
||
| 284 | */ |
||
| 285 | public function setMatcher($matcher) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Get the permalink. |
||
| 294 | * |
||
| 295 | * @return null|string |
||
| 296 | */ |
||
| 297 | public function getPermalink() |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Set the permalink. |
||
| 304 | * |
||
| 305 | * @param $permalink |
||
| 306 | * @return $this |
||
| 307 | */ |
||
| 308 | public function setPermalink($permalink) |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Get the description. |
||
| 317 | * |
||
| 318 | * @return null|string |
||
| 319 | */ |
||
| 320 | public function getDescription() |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Set the description. |
||
| 327 | * |
||
| 328 | * @param $description |
||
| 329 | * @return $this |
||
| 330 | */ |
||
| 331 | public function setDescription($description) |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Get the highlighted flag. |
||
| 340 | * |
||
| 341 | * @return boolean |
||
| 342 | */ |
||
| 343 | public function isHighlighted() |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Set the highlighted flag. |
||
| 350 | * |
||
| 351 | * @param boolean $active |
||
|
|
|||
| 352 | * @return $this |
||
| 353 | */ |
||
| 354 | public function setHighlighted($highlighted) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Get the context. |
||
| 363 | * |
||
| 364 | * @return boolean |
||
| 365 | */ |
||
| 366 | public function getContext() |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Set the context flag. |
||
| 373 | * |
||
| 374 | * @param boolean $active |
||
| 375 | * @return $this |
||
| 376 | */ |
||
| 377 | public function setContext($context) |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Get the parent. |
||
| 386 | * |
||
| 387 | * @return null|string |
||
| 388 | */ |
||
| 389 | public function getParent() |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Return if the section is |
||
| 396 | * a sub-section or not. |
||
| 397 | * |
||
| 398 | * @return bool |
||
| 399 | */ |
||
| 400 | public function isSubSection() |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Set the parent. |
||
| 407 | * |
||
| 408 | * @param $parent |
||
| 409 | * @return $this |
||
| 410 | */ |
||
| 411 | public function setParent($parent) |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Get the buttons. |
||
| 420 | * |
||
| 421 | * @return array |
||
| 422 | */ |
||
| 423 | public function getButtons() |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Set the buttons. |
||
| 430 | * |
||
| 431 | * @param array $buttons |
||
| 432 | */ |
||
| 433 | public function setButtons($buttons) |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Get the attributes. |
||
| 440 | * |
||
| 441 | * @return array |
||
| 442 | */ |
||
| 443 | public function getAttributes() |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Set the attributes. |
||
| 450 | * |
||
| 451 | * @param array $attributes |
||
| 452 | */ |
||
| 453 | public function setAttributes(array $attributes) |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Get the permission. |
||
| 460 | * |
||
| 461 | * @return null|string |
||
| 462 | */ |
||
| 463 | public function getPermission() |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Set the permission. |
||
| 470 | * |
||
| 471 | * @param $permission |
||
| 472 | * @return $this |
||
| 473 | */ |
||
| 474 | public function setPermission($permission) |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Get the breadcrumb. |
||
| 483 | * |
||
| 484 | * @return null|string |
||
| 485 | */ |
||
| 486 | public function getBreadcrumb() |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Set the breadcrumb. |
||
| 493 | * |
||
| 494 | * @param $breadcrumb |
||
| 495 | * @return $this |
||
| 496 | */ |
||
| 497 | public function setBreadcrumb($breadcrumb) |
||
| 503 | |||
| 504 | /** |
||
| 505 | * Get the hidden flag. |
||
| 506 | * |
||
| 507 | * @return bool |
||
| 508 | */ |
||
| 509 | public function isHidden() |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Set the hidden flag. |
||
| 516 | * |
||
| 517 | * @param $hidden |
||
| 518 | * @return $this |
||
| 519 | */ |
||
| 520 | public function setHidden($hidden) |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Get the HREF attribute. |
||
| 529 | * |
||
| 530 | * @param null $path |
||
| 531 | * @return string |
||
| 532 | */ |
||
| 533 | public function getHref($path = null) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Return the child sections. |
||
| 540 | * |
||
| 541 | * @return SectionCollection |
||
| 542 | */ |
||
| 543 | public function getChildren() |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Return whether the section |
||
| 550 | * has children or not. |
||
| 551 | * |
||
| 552 | * @return bool |
||
| 553 | */ |
||
| 554 | public function hasChildren() |
||
| 558 | } |
||
| 559 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.