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 |
||
| 22 | class CommentController extends AdminModuleController { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Constructor |
||
| 26 | * |
||
| 27 | * @param Request $request |
||
| 28 | */ |
||
| 29 | public function __construct(Request $request) { |
||
|
|
|||
| 30 | parent::__construct(); |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Add lookup tables |
||
| 34 | */ |
||
| 35 | $this->middleware('add.lookup.tables:CommentStatus', ['only' => ['index','create','edit']]); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Validation rules |
||
| 40 | * |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | protected $arValidationArray = [ |
||
| 44 | 'name' => 'max:255', |
||
| 45 | 'headline' => 'max:255|required', |
||
| 46 | 'text' => 'max:1000', |
||
| 47 | 'url' => 'max:255', |
||
| 48 | 'email' => 'max:255', |
||
| 49 | 'rating' => 'integer|max:1|min:-1|required' |
||
| 50 | ]; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Associate relationships to other table |
||
| 54 | * |
||
| 55 | * @param object $object |
||
| 56 | * @param Request $request |
||
| 57 | */ |
||
| 58 | public function associateRelationships($object, Request $request) { |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Approve comment |
||
| 144 | * |
||
| 145 | * @param integer $id |
||
| 146 | * @param Request $request |
||
| 147 | * @return Response |
||
| 148 | */ |
||
| 149 | View Code Duplication | public function approve($id, Request $request){ |
|
| 183 | |||
| 184 | /** |
||
| 185 | * Mark as SPAM |
||
| 186 | * |
||
| 187 | * @param integer $id |
||
| 188 | * @param Request $request |
||
| 189 | * @return Response |
||
| 190 | */ |
||
| 191 | View Code Duplication | public function spam($id, Request $request){ |
|
| 224 | } |
||
| 225 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.