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 |
||
| 17 | trait EntityLockTrait |
||
| 18 | { |
||
| 19 | |||
| 20 | protected $entityLock = true; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Boot the trait for the model. |
||
| 24 | * |
||
| 25 | * @return void |
||
| 26 | */ |
||
| 27 | /* public static function bootActionLogTrait() |
||
|
|
|||
| 28 | { |
||
| 29 | |||
| 30 | static::created(function ($model) { |
||
| 31 | if (!empty($model->actionLogging)) { |
||
| 32 | static::storeActionLog($model, 'create'); |
||
| 33 | } |
||
| 34 | }); |
||
| 35 | |||
| 36 | static::updated(function ($model) { |
||
| 37 | if (!empty($model->actionLogging)) { |
||
| 38 | static::storeActionLog($model, 'update'); |
||
| 39 | } |
||
| 40 | }); |
||
| 41 | |||
| 42 | static::deleted(function ($model) { |
||
| 43 | if (!empty($model->actionLogging)) { |
||
| 44 | static::storeActionLog($model, 'delete'); |
||
| 45 | } |
||
| 46 | }); |
||
| 47 | |||
| 48 | if (method_exists(static::class, 'restored')) { |
||
| 49 | static::restored(function ($model) { |
||
| 50 | if (!empty($model->actionLogging)) { |
||
| 51 | static::storeActionLog($model, 'restore'); |
||
| 52 | } |
||
| 53 | }); |
||
| 54 | } |
||
| 55 | }*/ |
||
| 56 | |||
| 57 | public function lockIn() |
||
| 86 | |||
| 87 | View Code Duplication | protected static function getEntityLockModelInstance() |
|
| 95 | |||
| 96 | |||
| 97 | public function withoutEntityLock() |
||
| 102 | |||
| 103 | public function isLocked() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Polymorphic relationship. Second parameter to morphOne/morphMany |
||
| 111 | * should be the same as the prefix for the *_id/*_type fields. |
||
| 112 | */ |
||
| 113 | View Code Duplication | public function entityLock() |
|
| 122 | |||
| 123 | } |
||
| 124 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.