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 |
||
| 12 | class Git extends Plugin |
||
| 13 | { |
||
| 14 | protected $actions = []; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @return string |
||
| 18 | */ |
||
| 19 | public static function pluginName() |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Run the Git plugin. |
||
| 26 | * |
||
| 27 | * @return bool |
||
| 28 | */ |
||
| 29 | public function execute() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Determine which action to run, and run it. |
||
| 49 | * |
||
| 50 | * @param $action |
||
| 51 | * @param array $options |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | protected function runAction($action, array $options = []) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Handle a merge action. |
||
| 76 | * |
||
| 77 | * @param $options |
||
| 78 | * @return bool |
||
| 79 | */ |
||
| 80 | protected function runMergeAction($options) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Handle a tag action. |
||
| 91 | * |
||
| 92 | * @param $options |
||
| 93 | * @return bool |
||
| 94 | */ |
||
| 95 | protected function runTagAction($options) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Handle a pull action. |
||
| 114 | * |
||
| 115 | * @param $options |
||
| 116 | * @return bool |
||
| 117 | */ |
||
| 118 | View Code Duplication | protected function runPullAction($options) |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Handle a push action. |
||
| 136 | * |
||
| 137 | * @param $options |
||
| 138 | * @return bool |
||
| 139 | */ |
||
| 140 | View Code Duplication | protected function runPushAction($options) |
|
| 155 | } |
||
| 156 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.