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 |
||
| 15 | class ConfigController extends Controller |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Display a listing of the resource. |
||
| 19 | * |
||
| 20 | * @return \Illuminate\Http\Response |
||
| 21 | */ |
||
| 22 | public function index($project_key) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * get permissions by project_key and roleid. |
||
| 48 | * |
||
| 49 | * @param string $project_key |
||
| 50 | * @param string $role_id |
||
| 51 | * @return array |
||
| 52 | */ |
||
| 53 | View Code Duplication | public function getPermissions($project_key, $role_id) |
|
| 61 | } |
||
| 62 |
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: