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 |
||
| 19 | class CalculatorApiController extends ApiGuardController |
||
| 20 | { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var CalculatorTransformer |
||
| 24 | */ |
||
| 25 | protected $calcul_transformer; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var SimulatorHistory |
||
| 29 | */ |
||
| 30 | protected $calculator; |
||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | protected $apiMethods = [ |
||
| 35 | 'store' =>[ |
||
| 36 | 'keyAuthentication' => true |
||
| 37 | ], |
||
| 38 | 'getUserCalculs' =>[ |
||
| 39 | 'keyAuthentication' => true |
||
| 40 | ] |
||
| 41 | ]; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * CalculatorController constructor. |
||
| 45 | * @param CalculatorTransformer $calcul_transformer |
||
| 46 | * @param User $user |
||
| 47 | * @param SimulatorHistory $calculator |
||
| 48 | */ |
||
| 49 | public function __construct(CalculatorTransformer $calcul_transformer, User $user, SimulatorHistory $calculator) |
||
| 58 | |||
| 59 | /** |
||
| 60 | *Store calculator data in DB |
||
| 61 | * @param Request $request |
||
| 62 | * @return mixed |
||
| 63 | */ |
||
| 64 | public function store(Request $request) |
||
| 86 | |||
| 87 | View Code Duplication | public function getUserCalculs() |
|
| 95 | |||
| 96 | |||
| 97 | } |
||
| 98 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: