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 |
||
33 | class NextNoteService { |
||
34 | |||
35 | private $noteMapper; |
||
36 | private $utils; |
||
37 | |||
38 | public function __construct(NextNoteMapper $noteMapper, Utils $utils, NextNoteShareBackend $shareBackend) { |
||
43 | |||
44 | /** |
||
45 | * Get vaults from a user. |
||
46 | * |
||
47 | * @param $userId |
||
48 | * @param int|bool $deleted |
||
49 | * @param string|bool $grouping |
||
50 | * @return NextNote[] |
||
51 | */ |
||
52 | public function findNotesFromUser($userId, $deleted = false, $grouping = false) { |
||
60 | |||
61 | /** |
||
62 | * Get a single vault |
||
63 | * |
||
64 | * @param $note_id |
||
65 | * @param $user_id |
||
66 | * @param bool|int $deleted |
||
67 | * @return NextNote |
||
68 | * @internal param $vault_id |
||
69 | */ |
||
70 | public function find($note_id, $user_id = null, $deleted = false) { |
||
74 | |||
75 | /** |
||
76 | * Creates a note |
||
77 | * |
||
78 | * @param array|NextNote $note |
||
79 | * @param $userId |
||
80 | * @return NextNote |
||
81 | * @throws \Exception |
||
82 | */ |
||
83 | View Code Duplication | public function create($note, $userId) { |
|
98 | |||
99 | /** |
||
100 | * Update vault |
||
101 | * |
||
102 | * @param $note array|NextNote |
||
103 | * @return NextNote|bool |
||
104 | * @throws \Exception |
||
105 | * @internal param $userId |
||
106 | * @internal param $vault |
||
107 | */ |
||
108 | View Code Duplication | public function update($note) { |
|
130 | |||
131 | public function renameNote($FOLDER, $id, $in_newname, $in_newgroup, $uid = null) { |
||
142 | |||
143 | /** |
||
144 | * Delete a vault from user |
||
145 | * |
||
146 | * @param $note_id |
||
147 | * @param string $user_id |
||
148 | * @return bool |
||
149 | * @internal param string $vault_guid |
||
150 | */ |
||
151 | public function delete($note_id, $user_id = null) { |
||
164 | |||
165 | |||
166 | /** |
||
167 | * @param $FOLDER |
||
168 | * @param boolean $showdel |
||
169 | * @return array |
||
170 | * @throws \Exception |
||
171 | */ |
||
172 | public function getListing($FOLDER, $showdel) { |
||
175 | |||
176 | private function checkPermissions($permission, $nid) { |
||
189 | } |
||
190 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: