Complex classes like AbstractNavigationNode 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 AbstractNavigationNode, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | abstract class AbstractNavigationNode implements NavigationInterface, AlphabeticalTreeNodeInterface { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Active ? |
||
| 27 | * |
||
| 28 | * @var bool |
||
| 29 | */ |
||
| 30 | private $active; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Enable ? |
||
| 34 | * |
||
| 35 | * @var bool |
||
| 36 | */ |
||
| 37 | private $enable; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Icon. |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $icon; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Id. |
||
| 48 | * |
||
| 49 | * @var string |
||
| 50 | */ |
||
| 51 | private $id; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Index. |
||
| 55 | * |
||
| 56 | * @var array |
||
| 57 | */ |
||
| 58 | private $index; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Matcher. |
||
| 62 | * |
||
| 63 | * @var string |
||
| 64 | */ |
||
| 65 | private $matcher; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Navigation nodes. |
||
| 69 | * |
||
| 70 | * @var AbstractNavigationNode[] |
||
| 71 | */ |
||
| 72 | private $nodes; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Parent. |
||
| 76 | * |
||
| 77 | * @var AbstractNavigationNode |
||
| 78 | */ |
||
| 79 | private $parent; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Target. |
||
| 83 | * |
||
| 84 | * @var string |
||
| 85 | */ |
||
| 86 | private $target; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * URI. |
||
| 90 | * |
||
| 91 | * @var string |
||
| 92 | */ |
||
| 93 | private $uri; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Visible ? |
||
| 97 | * |
||
| 98 | * @var bool |
||
| 99 | */ |
||
| 100 | private $visible; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Constructor. |
||
| 104 | * |
||
| 105 | * @param string $name The name. |
||
| 106 | * @param string|null $icon The icon. |
||
| 107 | * @param string|null $uri The URI. |
||
| 108 | * @param string $matcher The matcher. |
||
| 109 | */ |
||
| 110 | protected function __construct($name, $icon = null, $uri = null, $matcher = self::NAVIGATION_MATCHER_URL) { |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Add a navigation node. |
||
| 126 | * |
||
| 127 | * @param AbstractNavigationNode $node The navigation node. |
||
| 128 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 129 | */ |
||
| 130 | public function addNode(AbstractNavigationNode $node) { |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Clear the navigation nodes. |
||
| 138 | * |
||
| 139 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 140 | */ |
||
| 141 | public function clearNodes() { |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Get the active. |
||
| 150 | * |
||
| 151 | * @return bool Returns the active. |
||
| 152 | */ |
||
| 153 | public function getActive() { |
||
| 156 | |||
| 157 | /** |
||
| 158 | * {@inheritdoc} |
||
| 159 | */ |
||
| 160 | public function getAlphabeticalTreeNodeLabel() { |
||
| 163 | |||
| 164 | /** |
||
| 165 | * {@inheritdoc} |
||
| 166 | */ |
||
| 167 | public function getAlphabeticalTreeNodeParent() { |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Get the enable. |
||
| 173 | * |
||
| 174 | * @return bool Returns the enable. |
||
| 175 | */ |
||
| 176 | public function getEnable() { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Get the first navigation node. |
||
| 182 | * |
||
| 183 | * @return AbstractNavigationNode|null Returns the first navigation node in case of success, null otherwise. |
||
| 184 | */ |
||
| 185 | public function getFirstNode() { |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Get the icon. |
||
| 191 | * |
||
| 192 | * @return string Returns the icon. |
||
| 193 | */ |
||
| 194 | public function getIcon() { |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Get the id. |
||
| 200 | * |
||
| 201 | * @return string Returns the id. |
||
| 202 | */ |
||
| 203 | public function getId() { |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Get the last navigation node. |
||
| 209 | * |
||
| 210 | * @return AbstractNavigationNode|null Returns the last navigation node in case of success, null otherwise. |
||
| 211 | */ |
||
| 212 | public function getLastNode() { |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Get the matcher. |
||
| 218 | * |
||
| 219 | * @return string Returns the matcher. |
||
| 220 | */ |
||
| 221 | public function getMatcher() { |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Get a navigation node at. |
||
| 227 | * |
||
| 228 | * @param int $position The position. |
||
| 229 | * @return AbstractNavigationNode|null Returns the navigation node in case of success, null otherwise. |
||
| 230 | */ |
||
| 231 | public function getNodeAt($position) { |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Get a navigation node by id. |
||
| 242 | * |
||
| 243 | * @param string $id The id. |
||
| 244 | * @param bool $recursively Recursively ? |
||
| 245 | * @return AbstractNavigationNode Returns the navigation node in case of success, null otherwise. |
||
| 246 | */ |
||
| 247 | public function getNodeById($id, $recursively = false) { |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Get the navigation nodes. |
||
| 272 | * |
||
| 273 | * @return AbstractNavigationNode[] Returns the navigation nodes. |
||
| 274 | */ |
||
| 275 | public function getNodes() { |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Get the parent. |
||
| 281 | * |
||
| 282 | * @return AbstractNavigationNode Returns the parent. |
||
| 283 | */ |
||
| 284 | public function getParent() { |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Get the target. |
||
| 290 | * |
||
| 291 | * @return string Returns the target. |
||
| 292 | */ |
||
| 293 | public function getTarget() { |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Get the URI. |
||
| 299 | * |
||
| 300 | * @return string Returns the URI. |
||
| 301 | */ |
||
| 302 | public function getUri() { |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Get the visible. |
||
| 308 | * |
||
| 309 | * @return bool Returns the visible. |
||
| 310 | */ |
||
| 311 | public function getVisible() { |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Determines if this node is displayable. |
||
| 317 | * |
||
| 318 | * @return bool Returns true in case of success, false otherwise. |
||
| 319 | */ |
||
| 320 | public function isDisplayable() { |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Remove a navigation node. |
||
| 338 | * |
||
| 339 | * @param AbstractNavigationNode $node The navigation node. |
||
| 340 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 341 | */ |
||
| 342 | public function removeNode(AbstractNavigationNode $node) { |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Set the active. |
||
| 356 | * |
||
| 357 | * @param bool $active Active ? |
||
| 358 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 359 | */ |
||
| 360 | public function setActive($active) { |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Set the enable. |
||
| 367 | * |
||
| 368 | * @param bool $enable Enable ? |
||
| 369 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 370 | */ |
||
| 371 | public function setEnable($enable) { |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Set the icon. |
||
| 378 | * |
||
| 379 | * @param string $icon The icon. |
||
| 380 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 381 | */ |
||
| 382 | public function setIcon($icon) { |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Set the id. |
||
| 389 | * |
||
| 390 | * @param string $id The id. |
||
| 391 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 392 | */ |
||
| 393 | protected function setId($id) { |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Set the index. |
||
| 400 | * |
||
| 401 | * @param array $index The index. |
||
| 402 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 403 | */ |
||
| 404 | protected function setIndex(array $index) { |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Set the mather. |
||
| 411 | * |
||
| 412 | * @param string $matcher The matcher. |
||
| 413 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 414 | */ |
||
| 415 | public function setMatcher($matcher) { |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Set the navigation nodes. |
||
| 422 | * |
||
| 423 | * @param AbstractNavigationNode[] $nodes The navigation nodes. |
||
| 424 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 425 | */ |
||
| 426 | protected function setNodes(array $nodes) { |
||
| 430 | |||
| 431 | /** |
||
| 432 | * Set the parent. |
||
| 433 | * |
||
| 434 | * @param AbstractNavigationNode $parent The parent. |
||
| 435 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 436 | */ |
||
| 437 | protected function setParent(AbstractNavigationNode $parent = null) { |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Set the target. |
||
| 444 | * |
||
| 445 | * @param string $target The target. |
||
| 446 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 447 | */ |
||
| 448 | public function setTarget($target) { |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Set the URI. |
||
| 455 | * |
||
| 456 | * @param string $uri The URI. |
||
| 457 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 458 | */ |
||
| 459 | public function setUri($uri) { |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Set the visible. |
||
| 466 | * |
||
| 467 | * @param bool $visible Visible ? |
||
| 468 | * @return AbstractNavigationNode Returns this navigation node. |
||
| 469 | */ |
||
| 470 | protected function setVisible($visible) { |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Size. |
||
| 477 | * |
||
| 478 | * @return int Returns the size. |
||
| 479 | */ |
||
| 480 | public function size() { |
||
| 483 | } |
||
| 484 |