Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
19 | View Code Duplication | final class Linux implements Server |
|
20 | { |
||
21 | private $cpu; |
||
22 | private $memory; |
||
23 | private $processes; |
||
24 | private $loadAverage; |
||
25 | |||
26 | 6 | public function __construct(TimeContinuumInterface $clock) |
|
33 | |||
34 | 1 | public function cpu(): Cpu |
|
35 | { |
||
36 | 1 | return ($this->cpu)(); |
|
37 | } |
||
38 | |||
39 | 1 | public function memory(): Memory |
|
40 | { |
||
41 | 1 | return ($this->memory)(); |
|
42 | } |
||
43 | 1 | public function processes(): Processes |
|
47 | |||
48 | 1 | public function loadAverage(): LoadAverage |
|
52 | } |
||
53 |