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 |
||
31 | class OwnNoteService { |
||
32 | |||
33 | private $noteMapper; |
||
34 | private $utils; |
||
35 | |||
36 | public function __construct(OwnNoteMapper $noteMapper, Utils $utils) { |
||
40 | |||
41 | /** |
||
42 | * Get vaults from a user. |
||
43 | * |
||
44 | * @param $userId |
||
45 | * @param int $deleted |
||
46 | * @return OwnNote[] |
||
47 | */ |
||
48 | public function findNotesFromUser($userId, $deleted = 0) { |
||
52 | |||
53 | /** |
||
54 | * Get a single vault |
||
55 | * |
||
56 | * @param $note_id |
||
57 | * @param $user_id |
||
58 | * @return OwnNote |
||
59 | * @internal param $vault_id |
||
60 | */ |
||
61 | public function find($note_id, $user_id = null) { |
||
65 | |||
66 | /** |
||
67 | * Creates a note |
||
68 | * |
||
69 | * @param array|OwnNote $note |
||
70 | * @param $userId |
||
71 | * @return OwnNote |
||
72 | * @throws \Exception |
||
73 | */ |
||
74 | View Code Duplication | public function create($note, $userId) { |
|
89 | |||
90 | /** |
||
91 | * Update vault |
||
92 | * |
||
93 | * @param $note array|OwnNote |
||
94 | * @return OwnNote|bool |
||
95 | * @throws \Exception |
||
96 | * @internal param $userId |
||
97 | * @internal param $vault |
||
98 | */ |
||
99 | View Code Duplication | public function update($note) { |
|
120 | |||
121 | public function renameNote($FOLDER, $id, $in_newname, $in_newgroup, $uid = null) { |
||
132 | |||
133 | /** |
||
134 | * Delete a vault from user |
||
135 | * |
||
136 | * @param $note_id |
||
137 | * @param string $user_id |
||
138 | * @return bool |
||
139 | * @internal param string $vault_guid |
||
140 | */ |
||
141 | public function delete($note_id, $user_id = null) { |
||
154 | |||
155 | |||
156 | /** |
||
157 | * @param $FOLDER |
||
158 | * @param boolean $showdel |
||
159 | * @return array |
||
160 | * @throws \Exception |
||
161 | */ |
||
162 | public function getListing($FOLDER, $showdel) { |
||
165 | |||
166 | private function checkPermissions($permission, $nid) { |
||
179 | } |
||
180 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.