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 |
||
53 | class FilesEvents { |
||
54 | |||
55 | |||
56 | use TArrayTools; |
||
57 | |||
58 | |||
59 | /** @var string */ |
||
60 | private $userId; |
||
61 | |||
62 | /** @var IAppManager */ |
||
63 | private $appManager; |
||
64 | |||
65 | /** @var IFullTextSearchManager */ |
||
66 | private $fullTextSearchManager; |
||
67 | |||
68 | /** @var FilesService */ |
||
69 | private $filesService; |
||
70 | |||
71 | /** @var ConfigService */ |
||
72 | private $configService; |
||
73 | |||
74 | /** @var MiscService */ |
||
75 | private $miscService; |
||
76 | |||
77 | |||
78 | /** |
||
79 | * FilesEvents constructor. |
||
80 | * |
||
81 | * @param string $userId |
||
82 | * @param IAppManager $appManager |
||
83 | * @param IFullTextSearchManager $fullTextSearchManager |
||
84 | * @param FilesService $filesService |
||
85 | * @param ConfigService $configService |
||
86 | * @param MiscService $miscService |
||
87 | */ |
||
88 | View Code Duplication | public function __construct( |
|
99 | |||
100 | |||
101 | /** |
||
102 | * @throws QueryException |
||
103 | */ |
||
104 | private function registerFullTextSearchServices() { |
||
118 | |||
119 | |||
120 | /** |
||
121 | * @param array $params |
||
122 | * |
||
123 | * @throws InvalidPathException |
||
124 | * @throws NotFoundException |
||
125 | * @throws QueryException |
||
126 | */ |
||
127 | public function onNewFile(array $params) { |
||
144 | |||
145 | |||
146 | /** |
||
147 | * @param array $params |
||
148 | * |
||
149 | * @throws InvalidPathException |
||
150 | * @throws NotFoundException |
||
151 | * @throws QueryException |
||
152 | */ |
||
153 | View Code Duplication | public function onFileUpdate(array $params) { |
|
168 | |||
169 | |||
170 | /** |
||
171 | * @param array $params |
||
172 | * |
||
173 | * @throws NotFoundException |
||
174 | * @throws InvalidPathException |
||
175 | * @throws QueryException |
||
176 | */ |
||
177 | View Code Duplication | public function onFileRename(array $params) { |
|
192 | |||
193 | |||
194 | /** |
||
195 | * @param array $params |
||
196 | * |
||
197 | * @throws InvalidPathException |
||
198 | * @throws NotFoundException |
||
199 | * @throws QueryException |
||
200 | */ |
||
201 | View Code Duplication | public function onFileTrash(array $params) { |
|
218 | |||
219 | |||
220 | /** |
||
221 | * @param array $params |
||
222 | * |
||
223 | * @throws InvalidPathException |
||
224 | * @throws NotFoundException |
||
225 | * @throws QueryException |
||
226 | */ |
||
227 | View Code Duplication | public function onFileRestore(array $params) { |
|
242 | |||
243 | |||
244 | /** |
||
245 | * @param array $params |
||
246 | */ |
||
247 | public function onFileDelete(array $params) { |
||
260 | |||
261 | |||
262 | /** |
||
263 | * @param array $params |
||
264 | * |
||
265 | * @throws QueryException |
||
266 | */ |
||
267 | View Code Duplication | public function onFileShare(array $params) { |
|
279 | |||
280 | |||
281 | /** |
||
282 | * @param array $params |
||
283 | * |
||
284 | * @throws QueryException |
||
285 | */ |
||
286 | View Code Duplication | public function onFileUnshare(array $params) { |
|
298 | |||
299 | |||
300 | /** |
||
301 | * @param CommentsEvent $event |
||
302 | * |
||
303 | * @throws QueryException |
||
304 | */ |
||
305 | public function onCommentNew(CommentsEvent $event) { |
||
315 | |||
316 | |||
317 | public function onNewScannedFile2(array $params) { |
||
319 | |||
320 | |||
321 | public function onNewScannedFile(array $params) { |
||
323 | } |
||
324 | |||
325 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.