Complex classes like Node 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 Node, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class Node |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var String $id : The unique id of the node. |
||
| 15 | */ |
||
| 16 | private $id; |
||
| 17 | /** |
||
| 18 | * @var String $color : The text color of the node. |
||
| 19 | */ |
||
| 20 | private $color; |
||
| 21 | /** |
||
| 22 | * @var float $created : The timestamp of the creation date of the node. |
||
| 23 | */ |
||
| 24 | private $created; |
||
| 25 | /** |
||
| 26 | * @var float $modified : The timestamp of the modified date of the node. |
||
| 27 | */ |
||
| 28 | private $modified; |
||
| 29 | /** |
||
| 30 | * @var String $position : The relative position of the node. |
||
| 31 | */ |
||
| 32 | private $position; |
||
| 33 | /** |
||
| 34 | * @var int $vshift : The vshift of the node. |
||
| 35 | */ |
||
| 36 | private $vshift; |
||
| 37 | /** |
||
| 38 | * @var Bool $folded : Is the node folded or not. |
||
| 39 | */ |
||
| 40 | private $folded; |
||
| 41 | /** |
||
| 42 | * @var String $text : The text of the node. |
||
| 43 | */ |
||
| 44 | private $text; |
||
| 45 | /** |
||
| 46 | * @var Bool $bold : Is the text node in bold. |
||
| 47 | */ |
||
| 48 | private $bold; |
||
| 49 | /** |
||
| 50 | * @var Bool $italic : Is the text node in italic. |
||
| 51 | */ |
||
| 52 | private $italic; |
||
| 53 | /** |
||
| 54 | * @var String $fontName : The font name of the node. |
||
| 55 | */ |
||
| 56 | private $fontName; |
||
| 57 | /** |
||
| 58 | * @var int $fontSize : The font size of the node. |
||
| 59 | */ |
||
| 60 | private $fontSize; |
||
| 61 | /** |
||
| 62 | * @var Icon $icon : The icon of the node if there is one. |
||
| 63 | */ |
||
| 64 | private $icon; |
||
| 65 | /** |
||
| 66 | * @var NodeList $children : The children of the node as a collection of Nodes. |
||
| 67 | */ |
||
| 68 | private $children; |
||
| 69 | /** |
||
| 70 | * @var DOMElement $domNode : The DOMElement instance of the current Node. |
||
| 71 | */ |
||
| 72 | private $domNode; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param DOMElement $domNode : The DOMElement instance of the current Node. |
||
| 76 | * @param NodeList $children : The children of the node as a collection of Nodes. |
||
| 77 | * @param Icon $icon : The icon of the node if there is one. |
||
| 78 | * @param String $id : The unique id of the node. |
||
| 79 | * @param String $color : The text color of the node. |
||
| 80 | * @param float $created : The timestamp of the creation date of the node. |
||
| 81 | * @param float $modified : The timestamp of the modified date of the node. |
||
| 82 | * @param String $position : The relative position of the node. |
||
| 83 | * @param int $vshift : The vshift of the node. |
||
| 84 | * @param Bool $folded : Is the node folded or not. |
||
| 85 | * @param String $text : The text of the node. |
||
| 86 | * @param Bool $bold : Is the text node in bold. |
||
| 87 | * @param Bool $italic : Is the text node in italic. |
||
| 88 | * @param String $fontName : The font name of the current Node. |
||
| 89 | * @param int $fontSize : The font size of the node. |
||
| 90 | */ |
||
| 91 | public function __construct(DOMElement $domNode = null, NodeList $children = null, Icon $icon = null, $id = null, $color = null, $created = null, $modified = null, $position = null, $vshift = null, $folded = null, $text = null, $bold = null, $italic = null, $fontName = null, $fontSize = null) { |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Return the Id of the current node. |
||
| 111 | * |
||
| 112 | * @return String : The node id. |
||
| 113 | */ |
||
| 114 | public function getId() { |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Set the Id of the current node. |
||
| 120 | * |
||
| 121 | * @param String $id : The node id. |
||
| 122 | */ |
||
| 123 | public function setId($id) { |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Return the color of the current node. |
||
| 129 | * |
||
| 130 | * @return String : The node color value in hexadecimal. |
||
| 131 | */ |
||
| 132 | public function getColor() { |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Set the color of the current node. |
||
| 138 | * |
||
| 139 | * @param String $color : The node color value in hexadecimal. |
||
| 140 | */ |
||
| 141 | public function setColor($color) { |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Return the created timestamp of the current node. |
||
| 147 | * |
||
| 148 | * @return float : The node created timestamp. |
||
| 149 | */ |
||
| 150 | public function getCreated() { |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Set the created timestamp of the current node. |
||
| 156 | * |
||
| 157 | * @param float $created : The node created timestamp. |
||
| 158 | */ |
||
| 159 | public function setCreated($created) { |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Return the modified timestamp of the current node. |
||
| 165 | * |
||
| 166 | * @return float : The node modified timestamp. |
||
| 167 | */ |
||
| 168 | public function getModified() { |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Set the modified timestamp of the current node. |
||
| 174 | * |
||
| 175 | * @param float $modified : The node modified timestamp. |
||
| 176 | */ |
||
| 177 | public function setModified($modified) { |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Return the relative position the current node to the parent node. |
||
| 183 | * |
||
| 184 | * @return String : The node relative position. |
||
| 185 | */ |
||
| 186 | public function getPosition() { |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Set the relative position the current node to the parent node. |
||
| 192 | * |
||
| 193 | * @param String $position : The node relative position. |
||
| 194 | */ |
||
| 195 | public function setPosition($position) { |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Return the vshift value of the current node. |
||
| 201 | * |
||
| 202 | * @return int : The node vshift value. |
||
| 203 | */ |
||
| 204 | public function getVshift() { |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Set the vshift value of the current node. |
||
| 210 | * |
||
| 211 | * @param int $vshift : The node vshift value. |
||
| 212 | */ |
||
| 213 | public function setVshift($vshift) { |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Return if the current node is folded or not. |
||
| 219 | * |
||
| 220 | * @return Bool $folded |
||
| 221 | */ |
||
| 222 | public function isFolded() { |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Set if the current node is folded or not. |
||
| 228 | * |
||
| 229 | * @param Bool $folded |
||
| 230 | */ |
||
| 231 | public function setFolded($folded) { |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Return the text of the current node with html entities decoded. |
||
| 237 | * |
||
| 238 | * @return String : The node text value. |
||
| 239 | */ |
||
| 240 | public function getText() { |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Return the text of the current node. |
||
| 246 | * |
||
| 247 | * @return String : The node text value. |
||
| 248 | */ |
||
| 249 | public function getRawText() { |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Set the text of the current node with html entities decoded. |
||
| 255 | * |
||
| 256 | * @param String $text : The node text value in plain text not html encoded. |
||
| 257 | */ |
||
| 258 | public function setText($text) { |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Return the font name of the current node. |
||
| 264 | * |
||
| 265 | * @return String : The node font name. |
||
| 266 | */ |
||
| 267 | public function getFontName() { |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Set the font name of the current node. |
||
| 273 | * |
||
| 274 | * @param String $fontName : The node font name. |
||
| 275 | */ |
||
| 276 | public function setFontName($fontName) { |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Return if the text node is bold. |
||
| 282 | * |
||
| 283 | * @return Bool : If the text is bold or not. |
||
| 284 | */ |
||
| 285 | public function isBold() { |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Set if the text node is bold. |
||
| 291 | * |
||
| 292 | * @param Bool $bold : If the text must be bold or not. |
||
| 293 | */ |
||
| 294 | public function setBold($bold) { |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Return if the text node is italic. |
||
| 300 | * |
||
| 301 | * @return Bool : If the text is italic or not. |
||
| 302 | */ |
||
| 303 | public function isItalic() { |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Set if the text node is italic. |
||
| 309 | * |
||
| 310 | * @param Bool $italic : If the text must be italic or not. |
||
| 311 | */ |
||
| 312 | public function setItalic($italic) { |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Return the font size of the current node. |
||
| 318 | * |
||
| 319 | * @return int : The node font size. |
||
| 320 | */ |
||
| 321 | public function getFontSize() { |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Set the font size of the current node. |
||
| 327 | * |
||
| 328 | * @param int $fontSize : The node font size. |
||
| 329 | */ |
||
| 330 | public function setFontSize($fontSize) { |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Return the icon of the current node if there is one. |
||
| 336 | * |
||
| 337 | * @return Icon : The icon. |
||
| 338 | */ |
||
| 339 | public function getIcon() { |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Set the icon of the current node. |
||
| 345 | * |
||
| 346 | * @param Icon $icon : The node icon. |
||
| 347 | */ |
||
| 348 | public function setIcon(Icon $icon) { |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Return the list of children of the current node. |
||
| 354 | * |
||
| 355 | * @param NodeList $children : The list of children node. |
||
|
|
|||
| 356 | */ |
||
| 357 | public function getChildren() { |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Set the list of children of the current node. |
||
| 363 | * |
||
| 364 | * @param NodeList $children : The list of children node. |
||
| 365 | */ |
||
| 366 | public function setChildren(NodeList $children) { |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Return the DOMElement instance of the cirrent Node. |
||
| 372 | * |
||
| 373 | * @return DOMElement : DOMElement instance. |
||
| 374 | */ |
||
| 375 | public function getDomNode() { |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Set the current DOMElement instance. |
||
| 381 | * |
||
| 382 | * @param DOMElement $domNode : The DOMElement instance. |
||
| 383 | */ |
||
| 384 | public function setDomNode(DOMElement $domNode) { |
||
| 387 | |||
| 388 | /** |
||
| 389 | * To String method. |
||
| 390 | * |
||
| 391 | * @return String : The text content of the node. |
||
| 392 | */ |
||
| 393 | public function __toString() { |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Transform the objects tree in an array tree. |
||
| 399 | * |
||
| 400 | * @return Array $array : The array tree. |
||
| 401 | */ |
||
| 402 | public function toArray() { |
||
| 427 | } |
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.