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 enable($service) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * {@inheritdoc} |
||
| 104 | */ |
||
| 105 | 2 | View Code Duplication | public function disable($service) |
| 116 | |||
| 117 | /** |
||
| 118 | * {@inheritdoc} |
||
| 119 | */ |
||
| 120 | 1 | public function daemonReload() |
|
| 126 | |||
| 127 | /** |
||
| 128 | * {@inheritdoc} |
||
| 129 | */ |
||
| 130 | 1 | public function quiet() |
|
| 136 | |||
| 137 | /** |
||
| 138 | * {@inheritdoc} |
||
| 139 | */ |
||
| 140 | 7 | public function getCommand() |
|
| 151 | } |
||
| 152 |