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 |
||
18 | class BookmarkHandler extends AbstractHandler implements BookmarkHandlerInterface |
||
19 | { |
||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | public function create(CreateStruct $createStruct): Bookmark |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | View Code Duplication | public function delete(int $bookmarkId): void |
|
36 | { |
||
37 | $this->logger->logCall(__METHOD__, [ |
||
38 | 'id' => $bookmarkId, |
||
39 | ]); |
||
40 | |||
41 | $this->persistenceHandler->bookmarkHandler()->delete($bookmarkId); |
||
42 | |||
43 | $this->cache->invalidateTags(['bookmark-' . $bookmarkId]); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | public function loadByUserIdAndLocationId(int $userId, array $locationIds): array |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function loadUserBookmarks(int $userId, int $offset = 0, int $limit = -1): array |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | public function countUserBookmarks(int $userId): int |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | public function locationSwapped(int $location1Id, int $location2Id): void |
||
110 | } |
||
111 |