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 |
||
| 20 | class Bookmark extends RestController |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var \eZ\Publish\API\Repository\BookmarkService |
||
| 24 | */ |
||
| 25 | protected $bookmarkService; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var \eZ\Publish\API\Repository\LocationService |
||
| 29 | */ |
||
| 30 | protected $locationService; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Bookmark constructor. |
||
| 34 | * |
||
| 35 | * @param \eZ\Publish\API\Repository\BookmarkService $bookmarkService |
||
| 36 | * @param \eZ\Publish\API\Repository\LocationService $locationService |
||
| 37 | */ |
||
| 38 | public function __construct(BookmarkService $bookmarkService, LocationService $locationService) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Add given location to bookmarks. |
||
| 46 | * |
||
| 47 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
| 48 | * @param int $locationId |
||
| 49 | * |
||
| 50 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 51 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 52 | * |
||
| 53 | * @return \eZ\Publish\Core\REST\Common\Value |
||
| 54 | */ |
||
| 55 | public function createBookmark(Request $request, int $locationId): RestValue |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Deletes a given bookmark. |
||
| 77 | * |
||
| 78 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
| 79 | * @param int $locationId |
||
| 80 | * |
||
| 81 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 82 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 83 | * |
||
| 84 | * @return \eZ\Publish\Core\REST\Common\Value |
||
| 85 | */ |
||
| 86 | View Code Duplication | public function deleteBookmark(Request $request, int $locationId): RestValue |
|
| 98 | |||
| 99 | /** |
||
| 100 | * Checks if given location is bookmarked. |
||
| 101 | * |
||
| 102 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
| 103 | * @param int $locationId |
||
| 104 | * |
||
| 105 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 106 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 107 | * |
||
| 108 | * @return \eZ\Publish\Core\REST\Server\Values\OK |
||
| 109 | */ |
||
| 110 | View Code Duplication | public function isBookmarked(Request $request, int $locationId): Values\OK |
|
| 120 | |||
| 121 | /** |
||
| 122 | * List bookmarked locations. |
||
| 123 | * |
||
| 124 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
| 125 | * |
||
| 126 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 127 | * |
||
| 128 | * @return \eZ\Publish\Core\REST\Common\Value |
||
| 129 | */ |
||
| 130 | public function loadBookmarks(Request $request): RestValue |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Extracts and returns an item id from a path, e.g. /1/2/58 => 58. |
||
| 149 | * |
||
| 150 | * @param string $path |
||
| 151 | * |
||
| 152 | * @return mixed |
||
| 153 | */ |
||
| 154 | private function extractLocationIdFromPath(string $path) |
||
| 160 | } |
||
| 161 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.