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 | class SystemdCommandBuilder implements CommandBuilderInterface |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Command action. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $action; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Option list. |
||
| 30 | * |
||
| 31 | * @var string[] |
||
| 32 | */ |
||
| 33 | protected $options = []; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Service. |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $service; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * {@inheritdoc} |
||
| 44 | */ |
||
| 45 | 3 | public function start($service) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | */ |
||
| 60 | 2 | View Code Duplication | public function stop($service) |
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritdoc} |
||
| 74 | */ |
||
| 75 | 2 | public function restart($service) |
|
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | 2 | public function reload($service) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * {@inheritdoc} |
||
| 104 | */ |
||
| 105 | 2 | public function enable($service) |
|
| 116 | |||
| 117 | /** |
||
| 118 | * {@inheritdoc} |
||
| 119 | */ |
||
| 120 | 2 | View Code Duplication | public function disable($service) |
| 131 | |||
| 132 | /** |
||
| 133 | * {@inheritdoc} |
||
| 134 | */ |
||
| 135 | 1 | public function daemonReload() |
|
| 141 | |||
| 142 | /** |
||
| 143 | * {@inheritdoc} |
||
| 144 | */ |
||
| 145 | 1 | public function quiet() |
|
| 151 | |||
| 152 | /** |
||
| 153 | * {@inheritdoc} |
||
| 154 | */ |
||
| 155 | 8 | public function getCommand() |
|
| 166 | } |
||
| 167 |