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 |
||
20 | class CalculatorApiController extends ApiGuardController |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var CalculatorTransformer |
||
25 | */ |
||
26 | protected $calcul_transformer; |
||
27 | |||
28 | /** |
||
29 | * @var SimulatorHistory |
||
30 | */ |
||
31 | protected $calculator; |
||
32 | |||
33 | protected $alert; |
||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $apiMethods = [ |
||
38 | 'store' => [ |
||
39 | 'keyAuthentication' => true |
||
40 | ], |
||
41 | 'getUserCalculs' => [ |
||
42 | 'keyAuthentication' => true |
||
43 | ] |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * CalculatorController constructor. |
||
48 | * @param CalculatorTransformer $calcul_transformer |
||
49 | * @param User $user |
||
50 | * @param SimulatorHistory $calculator |
||
51 | */ |
||
52 | public function __construct(Alert $alert,CalculatorTransformer $calcul_transformer, User $user, SimulatorHistory $calculator) |
||
62 | |||
63 | /** |
||
64 | *Store calculator data in DB |
||
65 | * @param Request $request |
||
66 | * @return mixed |
||
67 | */ |
||
68 | public function store(Request $request) |
||
98 | |||
99 | /** |
||
100 | * @return array|static[] |
||
101 | */ |
||
102 | View Code Duplication | public function getUserCalculs() |
|
110 | |||
111 | public function dataVerify(Request $request) |
||
123 | } |
||
124 |
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: