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 CommonBehavior extends \yii\base\Behavior |
||
| 20 | { |
||
| 21 | public function events() |
||
| 28 | |||
| 29 | public function onBeforeAction($event) |
||
| 33 | |||
| 34 | public function onAfterAction($event) |
||
| 38 | |||
| 39 | View Code Duplication | public function runRequests($requests) |
|
| 50 | |||
| 51 | View Code Duplication | public function normalizeTasks($tasks) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Is response NOT Ok. |
||
| 68 | * @param Response|int $response |
||
| 69 | * @return bool |
||
| 70 | */ |
||
| 71 | public function isNotOk($response) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Run request. |
||
| 78 | * @param string|array $query |
||
| 79 | * @return Response |
||
| 80 | */ |
||
| 81 | public function runRequest($query) |
||
| 90 | } |
||
| 91 |
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.