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 |
||
36 | class Ownnotev2ApiController extends ApiController { |
||
37 | |||
38 | private $backend; |
||
39 | private $config; |
||
40 | private $noteService; |
||
41 | |||
42 | public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, OwnNoteService $noteService) { |
||
48 | |||
49 | /** |
||
50 | * MOBILE FUNCTIONS |
||
51 | */ |
||
52 | |||
53 | /** |
||
54 | * @NoAdminRequired |
||
55 | * @NoCSRFRequired |
||
56 | */ |
||
57 | public function index() { |
||
62 | |||
63 | /** |
||
64 | * @NoAdminRequired |
||
65 | * @NoCSRFRequired |
||
66 | */ |
||
67 | View Code Duplication | public function get($id) { |
|
68 | $results = $this->noteService->find($id); |
||
69 | if (!$results) { |
||
70 | return new NotFoundJSONResponse(); |
||
71 | } |
||
72 | return new JSONResponse($results); |
||
73 | } |
||
74 | |||
75 | |||
76 | /** |
||
77 | * @NoAdminRequired |
||
78 | * @NoCSRFRequired |
||
79 | */ |
||
80 | public function create($title, $group, $note) { |
||
90 | |||
91 | /** |
||
92 | * @NoAdminRequired |
||
93 | * @NoCSRFRequired |
||
94 | */ |
||
95 | public function update($id, $title, $group, $content) { |
||
112 | |||
113 | /** |
||
114 | * @NoAdminRequired |
||
115 | * @NoCSRFRequired |
||
116 | */ |
||
117 | View Code Duplication | public function delete($id) { |
|
126 | |||
127 | } |
||
128 |
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: