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 | protected $AccuracyUSec; |
||
| 8 | |||
| 9 | protected $ActiveExitTimestamp; |
||
| 10 | |||
| 11 | protected $After = []; |
||
| 12 | |||
| 13 | protected $Conflicts = []; |
||
| 14 | |||
| 15 | protected $Documentation; |
||
| 16 | |||
| 17 | protected $FragmentPath; |
||
| 18 | |||
| 19 | protected $InactiveEnterTimestamp; |
||
| 20 | |||
| 21 | protected $LastTriggerUSec; |
||
| 22 | |||
| 23 | protected $LastTriggerUSecMonotonic; |
||
| 24 | |||
| 25 | protected $NextElapseUSecMonotonic; |
||
| 26 | |||
| 27 | protected $NextElapseUSecRealtime; |
||
| 28 | |||
| 29 | protected $Persistent; |
||
| 30 | |||
| 31 | protected $RandomizedDelayUSec; |
||
| 32 | |||
| 33 | protected $RemainAfterElapse; |
||
| 34 | |||
| 35 | protected $Requires = []; |
||
| 36 | |||
| 37 | protected $RequiresMountsFor = []; |
||
| 38 | |||
| 39 | protected $Result; |
||
| 40 | |||
| 41 | protected $Triggers = []; |
||
| 42 | |||
| 43 | protected $Unit; |
||
| 44 | |||
| 45 | protected $UnitFilePreset; |
||
| 46 | |||
| 47 | protected $UnitFileState; |
||
| 48 | |||
| 49 | protected $WakeSystem; |
||
| 50 | |||
| 51 | protected $WantedBy = []; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return mixed |
||
| 55 | */ |
||
| 56 | public function getAccuracyUSec() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param mixed $AccuracyUSec |
||
| 63 | * @return Timer |
||
| 64 | */ |
||
| 65 | public function setAccuracyUSec($AccuracyUSec) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return mixed |
||
| 73 | */ |
||
| 74 | public function getActiveExitTimestamp() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param mixed $ActiveExitTimestamp |
||
| 81 | * @return Timer |
||
| 82 | */ |
||
| 83 | public function setActiveExitTimestamp($ActiveExitTimestamp) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return array |
||
| 91 | */ |
||
| 92 | public function getAfter(): array |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param array $After |
||
| 99 | * @return Timer |
||
| 100 | */ |
||
| 101 | public function setAfter(array $After): Timer |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @return array |
||
| 109 | */ |
||
| 110 | public function getConflicts(): array |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @param array $Conflicts |
||
| 117 | * @return Timer |
||
| 118 | */ |
||
| 119 | public function setConflicts(array $Conflicts): Timer |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @return mixed |
||
| 127 | */ |
||
| 128 | public function getDocumentation() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @param mixed $Documentation |
||
| 135 | * @return Timer |
||
| 136 | */ |
||
| 137 | public function setDocumentation($Documentation) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @return mixed |
||
| 145 | */ |
||
| 146 | public function getFragmentPath() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @param mixed $FragmentPath |
||
| 153 | * @return Timer |
||
| 154 | */ |
||
| 155 | public function setFragmentPath($FragmentPath) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @return mixed |
||
| 163 | */ |
||
| 164 | public function getInactiveEnterTimestamp() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @param mixed $InactiveEnterTimestamp |
||
| 171 | * @return Timer |
||
| 172 | */ |
||
| 173 | public function setInactiveEnterTimestamp($InactiveEnterTimestamp) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @return mixed |
||
| 181 | */ |
||
| 182 | public function getLastTriggerUSec() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param mixed $LastTriggerUSec |
||
| 189 | * @return Timer |
||
| 190 | */ |
||
| 191 | public function setLastTriggerUSec($LastTriggerUSec) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return mixed |
||
| 199 | */ |
||
| 200 | public function getLastTriggerUSecMonotonic() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @param mixed $LastTriggerUSecMonotonic |
||
| 207 | * @return Timer |
||
| 208 | */ |
||
| 209 | public function setLastTriggerUSecMonotonic($LastTriggerUSecMonotonic) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @return mixed |
||
| 217 | */ |
||
| 218 | public function getNextElapseUSecMonotonic() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @param mixed $NextElapseUSecMonotonic |
||
| 225 | * @return Timer |
||
| 226 | */ |
||
| 227 | public function setNextElapseUSecMonotonic($NextElapseUSecMonotonic) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @return mixed |
||
| 235 | */ |
||
| 236 | public function getNextElapseUSecRealtime() |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param mixed $NextElapseUSecRealtime |
||
| 243 | * @return Timer |
||
| 244 | */ |
||
| 245 | public function setNextElapseUSecRealtime($NextElapseUSecRealtime) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @return mixed |
||
| 253 | */ |
||
| 254 | public function getPersistent() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param mixed $Persistent |
||
| 261 | * @return Timer |
||
| 262 | */ |
||
| 263 | public function setPersistent($Persistent) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @return mixed |
||
| 271 | */ |
||
| 272 | public function getRandomizedDelayUSec() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @param mixed $RandomizedDelayUSec |
||
| 279 | * @return Timer |
||
| 280 | */ |
||
| 281 | public function setRandomizedDelayUSec($RandomizedDelayUSec) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @return mixed |
||
| 289 | */ |
||
| 290 | public function getRemainAfterElapse() |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @param mixed $RemainAfterElapse |
||
| 297 | * @return Timer |
||
| 298 | */ |
||
| 299 | public function setRemainAfterElapse($RemainAfterElapse) |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @return array |
||
| 307 | */ |
||
| 308 | public function getRequires(): array |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @param array $Requires |
||
| 315 | * @return Timer |
||
| 316 | */ |
||
| 317 | public function setRequires(array $Requires): Timer |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @return array |
||
| 325 | */ |
||
| 326 | public function getRequiresMountsFor(): array |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @param array $RequiresMountsFor |
||
| 333 | * @return Timer |
||
| 334 | */ |
||
| 335 | public function setRequiresMountsFor(array $RequiresMountsFor): Timer |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @return mixed |
||
| 343 | */ |
||
| 344 | public function getResult() |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param mixed $Result |
||
| 351 | * @return Timer |
||
| 352 | */ |
||
| 353 | public function setResult($Result) |
||
| 358 | |||
| 359 | /** |
||
| 360 | * @return array |
||
| 361 | */ |
||
| 362 | public function getTriggers(): array |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @param array $Triggers |
||
| 369 | * @return Timer |
||
| 370 | */ |
||
| 371 | public function setTriggers(array $Triggers): Timer |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @return mixed |
||
| 379 | */ |
||
| 380 | public function getUnit() |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @param mixed $Unit |
||
| 387 | * @return Timer |
||
| 388 | */ |
||
| 389 | public function setUnit($Unit) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @return mixed |
||
| 397 | */ |
||
| 398 | public function getUnitFilePreset() |
||
| 402 | |||
| 403 | /** |
||
| 404 | * @param mixed $UnitFilePreset |
||
| 405 | * @return Timer |
||
| 406 | */ |
||
| 407 | public function setUnitFilePreset($UnitFilePreset) |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @return mixed |
||
| 415 | */ |
||
| 416 | public function getUnitFileState() |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @param mixed $UnitFileState |
||
| 423 | * @return Timer |
||
| 424 | */ |
||
| 425 | public function setUnitFileState($UnitFileState) |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @return mixed |
||
| 433 | */ |
||
| 434 | public function getWakeSystem() |
||
| 438 | |||
| 439 | /** |
||
| 440 | * @param mixed $WakeSystem |
||
| 441 | * @return Timer |
||
| 442 | */ |
||
| 443 | public function setWakeSystem($WakeSystem) |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @return array |
||
| 451 | */ |
||
| 452 | public function getWantedBy(): array |
||
| 456 | |||
| 457 | /** |
||
| 458 | * @param array $WantedBy |
||
| 459 | * @return Timer |
||
| 460 | */ |
||
| 461 | public function setWantedBy(array $WantedBy): Timer |
||
| 466 | } |
||
| 467 |