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 |
||
32 | class NotebookService { |
||
33 | |||
34 | private $notebookMapper; |
||
35 | private $utils; |
||
36 | |||
37 | public function __construct(NotebookMapper $notebookMapper, Utils $utils) { |
||
41 | |||
42 | |||
43 | |||
44 | /** |
||
45 | * Get notebooks from a user. |
||
46 | * |
||
47 | * @param $userId |
||
48 | * @param int|bool $deleted |
||
49 | * @return Notebook[] |
||
50 | */ |
||
51 | View Code Duplication | public function findNotebooksFromUser($userId, $deleted = false) { |
|
66 | |||
67 | |||
68 | /** |
||
69 | * Find a notebook by id |
||
70 | * |
||
71 | * @param null|int $notebook_id |
||
72 | * @param null $user_id |
||
73 | * @param int|bool $deleted |
||
74 | * @return Notebook[]|Notebook |
||
75 | */ |
||
76 | public function find($notebook_id=null, $user_id = null, $deleted = false) { |
||
79 | /** |
||
80 | * Find a notebook by name |
||
81 | * |
||
82 | * @param $notebook_name string |
||
83 | * @param null $user_id |
||
84 | * @param bool $deleted |
||
85 | * @return Notebook[]|Notebook |
||
86 | */ |
||
87 | public function findByName($notebook_name=null, $user_id = null, $deleted = false) { |
||
90 | |||
91 | /** |
||
92 | * Creates a notebook |
||
93 | * |
||
94 | * @param array|Notebook $notebook |
||
95 | * @param $userId |
||
96 | * @return Notebook|Entity |
||
97 | * @throws \Exception |
||
98 | */ |
||
99 | public function create($notebook, $userId) { |
||
114 | |||
115 | /** |
||
116 | * Update a notebook |
||
117 | * |
||
118 | * @param $notebook array|Notebook |
||
119 | * @return Notebook|Entity|bool |
||
120 | * @throws \Exception |
||
121 | * @internal param $userId |
||
122 | * @internal param $vault |
||
123 | */ |
||
124 | public function update($notebook) { |
||
140 | |||
141 | /** |
||
142 | * Delete a notebook |
||
143 | * |
||
144 | * @param $notebook_id |
||
145 | * @param string $user_id |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function delete($notebook_id, $user_id = null) { |
||
161 | |||
162 | private function checkPermissions() { |
||
165 | } |
||
166 |