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 |
||
| 22 | class LocationService implements LocationServiceInterface |
||
| 23 | { |
||
| 24 | /** @var \eZ\Publish\API\Repository\LocationService */ |
||
| 25 | protected $service; |
||
| 26 | |||
| 27 | /** @var \eZ\Publish\API\Repository\LanguageResolver */ |
||
| 28 | protected $languageResolver; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Construct service object from aggregated service and LanguageResolver. |
||
| 32 | * |
||
| 33 | * @param \eZ\Publish\API\Repository\LocationService $service |
||
| 34 | * @param \eZ\Publish\API\Repository\LanguageResolver $languageResolver |
||
| 35 | */ |
||
| 36 | public function __construct( |
||
| 43 | |||
| 44 | public function copySubtree(Location $subtree, Location $targetParentLocation) |
||
| 48 | |||
| 49 | View Code Duplication | public function loadLocation($locationId, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null) |
|
| 57 | |||
| 58 | public function loadLocationList(array $locationIds, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null): iterable |
||
| 66 | |||
| 67 | View Code Duplication | public function loadLocationByRemoteId($remoteId, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null) |
|
| 75 | |||
| 76 | public function loadLocations(ContentInfo $contentInfo, Location $rootLocation = null, array $prioritizedLanguages = null) |
||
| 84 | |||
| 85 | public function loadLocationChildren(Location $location, $offset = 0, $limit = 25, array $prioritizedLanguages = null) |
||
| 94 | |||
| 95 | public function loadParentLocationsForDraftContent(VersionInfo $versionInfo, array $prioritizedLanguages = null) |
||
| 102 | |||
| 103 | public function getLocationChildCount(Location $location) |
||
| 107 | |||
| 108 | public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $locationCreateStruct) |
||
| 112 | |||
| 113 | public function updateLocation(Location $location, LocationUpdateStruct $locationUpdateStruct) |
||
| 117 | |||
| 118 | public function swapLocation(Location $location1, Location $location2) |
||
| 122 | |||
| 123 | public function hideLocation(Location $location) |
||
| 127 | |||
| 128 | public function unhideLocation(Location $location) |
||
| 132 | |||
| 133 | public function moveSubtree(Location $location, Location $newParentLocation) |
||
| 137 | |||
| 138 | public function deleteLocation(Location $location) |
||
| 142 | |||
| 143 | public function newLocationCreateStruct($parentLocationId) |
||
| 147 | |||
| 148 | public function newLocationUpdateStruct() |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Get the total number of all existing Locations. Can be combined with loadAllLocations. |
||
| 155 | * |
||
| 156 | * @see loadAllLocations |
||
| 157 | * |
||
| 158 | * @return int Total number of Locations |
||
| 159 | */ |
||
| 160 | public function getAllLocationsCount(): int |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Bulk-load all existing Locations, constrained by $limit and $offset to paginate results. |
||
| 167 | * |
||
| 168 | * @param int $limit |
||
| 169 | * @param int $offset |
||
| 170 | * |
||
| 171 | * @return \eZ\Publish\API\Repository\Values\Content\Location[] |
||
| 172 | */ |
||
| 173 | public function loadAllLocations(int $offset = 0, int $limit = 25): array |
||
| 177 | |||
| 178 | public function loadFirstAvailableLocation(ContentInfo $contentInfo, array $prioritizedLanguages = null): Location |
||
| 182 | } |
||
| 183 |