Complex classes like Timer 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 Timer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class Timer extends AbstractType |
||
| 6 | { |
||
| 7 | private $AccuracyUSec; |
||
| 8 | |||
| 9 | private $After = []; |
||
| 10 | |||
| 11 | private $Conflicts = []; |
||
| 12 | |||
| 13 | private $Documentation; |
||
| 14 | |||
| 15 | private $FragmentPath; |
||
| 16 | |||
| 17 | private $LastTriggerUSec; |
||
| 18 | |||
| 19 | private $LastTriggerUSecMonotonic; |
||
| 20 | |||
| 21 | private $NextElapseUSecMonotonic; |
||
| 22 | |||
| 23 | private $NextElapseUSecRealtime; |
||
| 24 | |||
| 25 | private $Persistent; |
||
| 26 | |||
| 27 | private $RandomizedDelayUSec; |
||
| 28 | |||
| 29 | private $RemainAfterElapse; |
||
| 30 | |||
| 31 | private $Requires = []; |
||
| 32 | |||
| 33 | private $RequiresMountsFor = []; |
||
| 34 | |||
| 35 | private $Result; |
||
| 36 | |||
| 37 | private $Triggers = []; |
||
| 38 | |||
| 39 | private $Unit; |
||
| 40 | |||
| 41 | private $UnitFilePreset; |
||
| 42 | |||
| 43 | private $UnitFileState; |
||
| 44 | |||
| 45 | private $WakeSystem; |
||
| 46 | |||
| 47 | private $WantedBy = []; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @return mixed |
||
| 51 | */ |
||
| 52 | public function getAccuracyUSec() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param mixed $AccuracyUSec |
||
| 59 | * @return Timer |
||
| 60 | */ |
||
| 61 | public function setAccuracyUSec($AccuracyUSec) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | public function getAfter(): array |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @param array $After |
||
| 77 | * @return Timer |
||
| 78 | */ |
||
| 79 | public function setAfter(array $After): Timer |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @return array |
||
| 87 | */ |
||
| 88 | public function getConflicts(): array |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param array $Conflicts |
||
| 95 | * @return Timer |
||
| 96 | */ |
||
| 97 | public function setConflicts(array $Conflicts): Timer |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @return mixed |
||
| 105 | */ |
||
| 106 | public function getDocumentation() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param mixed $Documentation |
||
| 113 | * @return Timer |
||
| 114 | */ |
||
| 115 | public function setDocumentation($Documentation) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @return mixed |
||
| 123 | */ |
||
| 124 | public function getFragmentPath() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param mixed $FragmentPath |
||
| 131 | * @return Timer |
||
| 132 | */ |
||
| 133 | public function setFragmentPath($FragmentPath) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return mixed |
||
| 141 | */ |
||
| 142 | public function getLastTriggerUSec() |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @param mixed $LastTriggerUSec |
||
| 149 | * @return Timer |
||
| 150 | */ |
||
| 151 | public function setLastTriggerUSec($LastTriggerUSec) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return mixed |
||
| 159 | */ |
||
| 160 | public function getLastTriggerUSecMonotonic() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @param mixed $LastTriggerUSecMonotonic |
||
| 167 | * @return Timer |
||
| 168 | */ |
||
| 169 | public function setLastTriggerUSecMonotonic($LastTriggerUSecMonotonic) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @return mixed |
||
| 177 | */ |
||
| 178 | public function getNextElapseUSecMonotonic() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param mixed $NextElapseUSecMonotonic |
||
| 185 | * @return Timer |
||
| 186 | */ |
||
| 187 | public function setNextElapseUSecMonotonic($NextElapseUSecMonotonic) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @return mixed |
||
| 195 | */ |
||
| 196 | public function getNextElapseUSecRealtime() |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @param mixed $NextElapseUSecRealtime |
||
| 203 | * @return Timer |
||
| 204 | */ |
||
| 205 | public function setNextElapseUSecRealtime($NextElapseUSecRealtime) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @return mixed |
||
| 213 | */ |
||
| 214 | public function getPersistent() |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @param mixed $Persistent |
||
| 221 | * @return Timer |
||
| 222 | */ |
||
| 223 | public function setPersistent($Persistent) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return mixed |
||
| 231 | */ |
||
| 232 | public function getRandomizedDelayUSec() |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @param mixed $RandomizedDelayUSec |
||
| 239 | * @return Timer |
||
| 240 | */ |
||
| 241 | public function setRandomizedDelayUSec($RandomizedDelayUSec) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @return mixed |
||
| 249 | */ |
||
| 250 | public function getRemainAfterElapse() |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @param mixed $RemainAfterElapse |
||
| 257 | * @return Timer |
||
| 258 | */ |
||
| 259 | public function setRemainAfterElapse($RemainAfterElapse) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @return array |
||
| 267 | */ |
||
| 268 | public function getRequires(): array |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @param array $Requires |
||
| 275 | * @return Timer |
||
| 276 | */ |
||
| 277 | public function setRequires(array $Requires): Timer |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @return array |
||
| 285 | */ |
||
| 286 | public function getRequiresMountsFor(): array |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @param array $RequiresMountsFor |
||
| 293 | * @return Timer |
||
| 294 | */ |
||
| 295 | public function setRequiresMountsFor(array $RequiresMountsFor): Timer |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @return mixed |
||
| 303 | */ |
||
| 304 | public function getResult() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @param mixed $Result |
||
| 311 | * @return Timer |
||
| 312 | */ |
||
| 313 | public function setResult($Result) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @return array |
||
| 321 | */ |
||
| 322 | public function getTriggers(): array |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @param array $Triggers |
||
| 329 | * @return Timer |
||
| 330 | */ |
||
| 331 | public function setTriggers(array $Triggers): Timer |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @return mixed |
||
| 339 | */ |
||
| 340 | public function getUnit() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @param mixed $Unit |
||
| 347 | * @return Timer |
||
| 348 | */ |
||
| 349 | public function setUnit($Unit) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @return mixed |
||
| 357 | */ |
||
| 358 | public function getUnitFilePreset() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @param mixed $UnitFilePreset |
||
| 365 | * @return Timer |
||
| 366 | */ |
||
| 367 | public function setUnitFilePreset($UnitFilePreset) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @return mixed |
||
| 375 | */ |
||
| 376 | public function getUnitFileState() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @param mixed $UnitFileState |
||
| 383 | * @return Timer |
||
| 384 | */ |
||
| 385 | public function setUnitFileState($UnitFileState) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * @return mixed |
||
| 393 | */ |
||
| 394 | public function getWakeSystem() |
||
| 398 | |||
| 399 | /** |
||
| 400 | * @param mixed $WakeSystem |
||
| 401 | * @return Timer |
||
| 402 | */ |
||
| 403 | public function setWakeSystem($WakeSystem) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @return array |
||
| 411 | */ |
||
| 412 | public function getWantedBy(): array |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @param array $WantedBy |
||
| 419 | * @return Timer |
||
| 420 | */ |
||
| 421 | public function setWantedBy(array $WantedBy): Timer |
||
| 426 | } |
||
| 427 |