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 |
||
| 31 | class Files extends Action { |
||
| 32 | /** |
||
| 33 | * Logs file read actions |
||
| 34 | * |
||
| 35 | * @param array $params |
||
| 36 | */ |
||
| 37 | public function read(array $params) { |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Logs rename actions of files |
||
| 49 | * |
||
| 50 | * @param array $params |
||
| 51 | */ |
||
| 52 | public function rename(array $params) { |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Logs creation of files |
||
| 65 | * |
||
| 66 | * @param array $params |
||
| 67 | */ |
||
| 68 | View Code Duplication | public function create(array $params) { |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Logs copying of files |
||
| 84 | * |
||
| 85 | * @param array $params |
||
| 86 | */ |
||
| 87 | public function copy(array $params) { |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Logs writing of files |
||
| 100 | * |
||
| 101 | * @param array $params |
||
| 102 | */ |
||
| 103 | View Code Duplication | public function write(array $params) { |
|
| 116 | |||
| 117 | /** |
||
| 118 | * Logs update of files |
||
| 119 | * |
||
| 120 | * @param array $params |
||
| 121 | */ |
||
| 122 | public function update(array $params) { |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Logs deletions of files |
||
| 134 | * |
||
| 135 | * @param array $params |
||
| 136 | */ |
||
| 137 | public function delete(array $params) { |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Logs preview access to a file |
||
| 149 | * |
||
| 150 | * @param array $params |
||
| 151 | */ |
||
| 152 | public function preview(array $params) { |
||
| 165 | } |
||
| 166 |
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.