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 |
||
| 15 | class SystemdCommandBuilder implements CommandBuilderInterface |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Command action. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $action; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Option list. |
||
| 26 | * |
||
| 27 | * @var string[] |
||
| 28 | */ |
||
| 29 | protected $options = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Service. |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | protected $service; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * {@inheritdoc} |
||
| 40 | */ |
||
| 41 | 3 | public function start($service) |
|
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | 2 | View Code Duplication | public function stop($service) |
| 67 | |||
| 68 | /** |
||
| 69 | * {@inheritdoc} |
||
| 70 | */ |
||
| 71 | 2 | public function restart($service) |
|
| 82 | |||
| 83 | /** |
||
| 84 | * {@inheritdoc} |
||
| 85 | */ |
||
| 86 | 2 | public function enable($service) |
|
| 97 | |||
| 98 | /** |
||
| 99 | * {@inheritdoc} |
||
| 100 | */ |
||
| 101 | 2 | View Code Duplication | public function disable($service) |
| 112 | |||
| 113 | /** |
||
| 114 | * {@inheritdoc} |
||
| 115 | */ |
||
| 116 | 1 | public function daemonReload() |
|
| 122 | |||
| 123 | /** |
||
| 124 | * {@inheritdoc} |
||
| 125 | */ |
||
| 126 | 1 | public function quiet() |
|
| 132 | |||
| 133 | /** |
||
| 134 | * {@inheritdoc} |
||
| 135 | */ |
||
| 136 | 7 | public function getCommand() |
|
| 147 | } |
||
| 148 |