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 |
||
| 8 | class UpdateFormRequest extends FormRequest |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Determine if the user is authorized to make this request. |
||
| 12 | * |
||
| 13 | * @return bool |
||
| 14 | */ |
||
| 15 | public function authorize() |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Get the validation rules that apply to the request. |
||
| 23 | * |
||
| 24 | * @return array |
||
| 25 | */ |
||
| 26 | View Code Duplication | public function rules() |
|
| 33 | |||
| 34 | /** |
||
| 35 | * Get custom attributes for validator errors. |
||
| 36 | * |
||
| 37 | * @return array |
||
| 38 | */ |
||
| 39 | public function attributes() |
||
| 43 | } |
||
| 44 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: