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 |
||
29 | class LocationService implements LocationServiceInterface |
||
30 | { |
||
31 | /** |
||
32 | * Aggregated service. |
||
33 | * |
||
34 | * @var \eZ\Publish\API\Repository\LocationService |
||
35 | */ |
||
36 | protected $service; |
||
37 | |||
38 | /** |
||
39 | * SignalDispatcher. |
||
40 | * |
||
41 | * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher |
||
42 | */ |
||
43 | protected $signalDispatcher; |
||
44 | |||
45 | /** |
||
46 | * Constructor. |
||
47 | * |
||
48 | * Construct service object from aggregated service and signal |
||
49 | * dispatcher |
||
50 | * |
||
51 | * @param \eZ\Publish\API\Repository\LocationService $service |
||
52 | * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher |
||
53 | */ |
||
54 | public function __construct(LocationServiceInterface $service, SignalDispatcher $signalDispatcher) |
||
59 | |||
60 | /** |
||
61 | * Copies the subtree starting from $subtree as a new subtree of $targetLocation. |
||
62 | * |
||
63 | * Only the items on which the user has read access are copied. |
||
64 | * |
||
65 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed copy the subtree to the given parent location |
||
66 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user does not have read access to the whole source subtree |
||
67 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the target location is a sub location of the given location |
||
68 | * |
||
69 | * @param \eZ\Publish\API\Repository\Values\Content\Location $subtree - the subtree denoted by the location to copy |
||
70 | * @param \eZ\Publish\API\Repository\Values\Content\Location $targetParentLocation - the target parent location for the copy operation |
||
71 | * |
||
72 | * @return \eZ\Publish\API\Repository\Values\Content\Location The newly created location of the copied subtree |
||
73 | */ |
||
74 | View Code Duplication | public function copySubtree(Location $subtree, Location $targetParentLocation) |
|
89 | |||
90 | /** |
||
91 | * Loads a location object from its $locationId. |
||
92 | * |
||
93 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read this location |
||
94 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found |
||
95 | * |
||
96 | * @param mixed $locationId |
||
97 | * |
||
98 | * @return \eZ\Publish\API\Repository\Values\Content\Location |
||
99 | */ |
||
100 | public function loadLocation($locationId) |
||
104 | |||
105 | /** |
||
106 | * Loads a location object from its $remoteId. |
||
107 | * |
||
108 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read this location |
||
109 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found |
||
110 | * |
||
111 | * @param string $remoteId |
||
112 | * |
||
113 | * @return \eZ\Publish\API\Repository\Values\Content\Location |
||
114 | */ |
||
115 | public function loadLocationByRemoteId($remoteId) |
||
119 | |||
120 | /** |
||
121 | * Loads the locations for the given content object. |
||
122 | * |
||
123 | * If a $rootLocation is given, only locations that belong to this location are returned. |
||
124 | * The location list is also filtered by permissions on reading locations. |
||
125 | * |
||
126 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if there is no published version yet |
||
127 | * |
||
128 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
129 | * @param \eZ\Publish\API\Repository\Values\Content\Location $rootLocation |
||
130 | * |
||
131 | * @return \eZ\Publish\API\Repository\Values\Content\Location[] An array of {@link Location} |
||
132 | */ |
||
133 | public function loadLocations(ContentInfo $contentInfo, Location $rootLocation = null) |
||
137 | |||
138 | /** |
||
139 | * Loads children which are readable by the current user of a location object sorted by sortField and sortOrder. |
||
140 | * |
||
141 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
142 | * @param int $offset the start offset for paging |
||
143 | * @param int $limit the number of locations returned |
||
144 | * |
||
145 | * @return \eZ\Publish\API\Repository\Values\Content\LocationList |
||
146 | */ |
||
147 | public function loadLocationChildren(Location $location, $offset = 0, $limit = 25) |
||
151 | |||
152 | /** |
||
153 | * {@inheritdoc} |
||
154 | */ |
||
155 | public function loadParentLocationsForDraftContent(VersionInfo $versionInfo) |
||
156 | { |
||
157 | return $this->service->loadParentLocationsForDraftContent($versionInfo); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Returns the number of children which are readable by the current user of a location object. |
||
162 | * |
||
163 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
164 | * |
||
165 | * @return int |
||
166 | */ |
||
167 | public function getLocationChildCount(Location $location) |
||
171 | |||
172 | /** |
||
173 | * Creates the new $location in the content repository for the given content. |
||
174 | * |
||
175 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create this location |
||
176 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the content is already below the specified parent |
||
177 | * or the parent is a sub location of the location of the content |
||
178 | * or if set the remoteId exists already |
||
179 | * |
||
180 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
181 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct |
||
182 | * |
||
183 | * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created Location |
||
184 | */ |
||
185 | public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $locationCreateStruct) |
||
199 | |||
200 | /** |
||
201 | * Updates $location in the content repository. |
||
202 | * |
||
203 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location |
||
204 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if if set the remoteId exists already |
||
205 | * |
||
206 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
207 | * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct |
||
208 | * |
||
209 | * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location |
||
210 | */ |
||
211 | public function updateLocation(Location $location, LocationUpdateStruct $locationUpdateStruct) |
||
225 | |||
226 | /** |
||
227 | * Swaps the contents held by $location1 and $location2. |
||
228 | * |
||
229 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to swap content |
||
230 | * |
||
231 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location1 |
||
232 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location2 |
||
233 | */ |
||
234 | View Code Duplication | public function swapLocation(Location $location1, Location $location2) |
|
250 | |||
251 | /** |
||
252 | * Hides the $location and marks invisible all descendants of $location. |
||
253 | * |
||
254 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to hide this location |
||
255 | * |
||
256 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
257 | * |
||
258 | * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value |
||
259 | */ |
||
260 | View Code Duplication | public function hideLocation(Location $location) |
|
275 | |||
276 | /** |
||
277 | * Unhides the $location. |
||
278 | * |
||
279 | * This method and marks visible all descendants of $locations |
||
280 | * until a hidden location is found. |
||
281 | * |
||
282 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to unhide this location |
||
283 | * |
||
284 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
285 | * |
||
286 | * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value |
||
287 | */ |
||
288 | View Code Duplication | public function unhideLocation(Location $location) |
|
303 | |||
304 | /** |
||
305 | * Moves the subtree to $newParentLocation. |
||
306 | * |
||
307 | * If a user has the permission to move the location to a target location |
||
308 | * he can do it regardless of an existing descendant on which the user has no permission. |
||
309 | * |
||
310 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to move this location to the target |
||
311 | * |
||
312 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
313 | * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation |
||
314 | */ |
||
315 | View Code Duplication | public function moveSubtree(Location $location, Location $newParentLocation) |
|
329 | |||
330 | /** |
||
331 | * Deletes $location and all its descendants. |
||
332 | * |
||
333 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this location or a descendant |
||
334 | * |
||
335 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
336 | */ |
||
337 | public function deleteLocation(Location $location) |
||
350 | |||
351 | /** |
||
352 | * Instantiates a new location create class. |
||
353 | * |
||
354 | * @param mixed $parentLocationId the parent under which the new location should be created |
||
355 | * |
||
356 | * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct |
||
357 | */ |
||
358 | public function newLocationCreateStruct($parentLocationId) |
||
362 | |||
363 | /** |
||
364 | * Instantiates a new location update class. |
||
365 | * |
||
366 | * @return \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct |
||
367 | */ |
||
368 | public function newLocationUpdateStruct() |
||
372 | } |
||
373 |