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  | 
            ||
| 9 | View Code Duplication | class SettingsController extends BaseApiController  | 
            |
| 
                                                                                                    
                        
                         | 
                |||
| 10 | { | 
            ||
| 11 | /**  | 
            ||
| 12 | * The name of the model that is used by the base api controller  | 
            ||
| 13 | * to preform actions like (add, edit ... etc).  | 
            ||
| 14 | * @var string  | 
            ||
| 15 | */  | 
            ||
| 16 | protected $model = 'settings';  | 
            ||
| 17 | |||
| 18 | /**  | 
            ||
| 19 | * The validations rules used by the base api controller  | 
            ||
| 20 | * to check before add.  | 
            ||
| 21 | * @var array  | 
            ||
| 22 | */  | 
            ||
| 23 | protected $validationRules = [  | 
            ||
| 24 | 'name' => 'required|string|max:100',  | 
            ||
| 25 | 'value' => 'required|string'  | 
            ||
| 26 | ];  | 
            ||
| 27 | |||
| 28 | /**  | 
            ||
| 29 | * Save list of settings.  | 
            ||
| 30 | *  | 
            ||
| 31 | * @param \Illuminate\Http\Request $request  | 
            ||
| 32 | * @return \Illuminate\Http\Response  | 
            ||
| 33 | */  | 
            ||
| 34 | public function saveMany(Request $request)  | 
            ||
| 38 | }  | 
            ||
| 39 | 
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.