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 |
||
| 24 | class LocationService implements LocationServiceInterface |
||
| 25 | { |
||
| 26 | /** @var \eZ\Publish\API\Repository\LocationService */ |
||
| 27 | protected $service; |
||
| 28 | |||
| 29 | /** @var \eZ\Publish\Core\Repository\SiteAccessAware\Language\LanguageResolver */ |
||
| 30 | protected $languageResolver; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Construct service object from aggregated service and LanguageResolver. |
||
| 34 | * |
||
| 35 | * @param \eZ\Publish\API\Repository\LocationService $service |
||
| 36 | * @param \eZ\Publish\Core\Repository\SiteAccessAware\Language\LanguageResolver $languageResolver |
||
| 37 | */ |
||
| 38 | public function __construct( |
||
| 45 | |||
| 46 | public function copySubtree(Location $subtree, Location $targetParentLocation) |
||
| 50 | |||
| 51 | View Code Duplication | public function loadLocation($locationId, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null) |
|
| 59 | |||
| 60 | public function loadLocationList(array $locationIds, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null): iterable |
||
| 68 | |||
| 69 | View Code Duplication | public function loadLocationByRemoteId($remoteId, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null) |
|
| 77 | |||
| 78 | public function loadLocations(ContentInfo $contentInfo, Location $rootLocation = null, array $prioritizedLanguages = null) |
||
| 86 | |||
| 87 | public function loadLocationChildren(Location $location, $offset = 0, $limit = 25, array $prioritizedLanguages = null) |
||
| 96 | |||
| 97 | public function loadParentLocationsForDraftContent(VersionInfo $versionInfo, array $prioritizedLanguages = null) |
||
| 104 | |||
| 105 | public function getLocationChildCount(Location $location) |
||
| 109 | |||
| 110 | public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $locationCreateStruct) |
||
| 114 | |||
| 115 | public function updateLocation(Location $location, LocationUpdateStruct $locationUpdateStruct) |
||
| 119 | |||
| 120 | public function swapLocation(Location $location1, Location $location2) |
||
| 124 | |||
| 125 | public function hideLocation(Location $location) |
||
| 129 | |||
| 130 | public function unhideLocation(Location $location) |
||
| 134 | |||
| 135 | public function moveSubtree(Location $location, Location $newParentLocation) |
||
| 139 | |||
| 140 | public function deleteLocation(Location $location) |
||
| 144 | |||
| 145 | public function newLocationCreateStruct($parentLocationId) |
||
| 149 | |||
| 150 | public function newLocationUpdateStruct() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Get the total number of all existing Locations. Can be combined with loadAllLocations. |
||
| 157 | * |
||
| 158 | * @see loadAllLocations |
||
| 159 | * |
||
| 160 | * @return int Total number of Locations |
||
| 161 | */ |
||
| 162 | public function getAllLocationsCount(): int |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Bulk-load all existing Locations, constrained by $limit and $offset to paginate results. |
||
| 169 | * |
||
| 170 | * @param int $limit |
||
| 171 | * @param int $offset |
||
| 172 | * |
||
| 173 | * @return \eZ\Publish\API\Repository\Values\Content\Location[] |
||
| 174 | */ |
||
| 175 | public function loadAllLocations(int $offset = 0, int $limit = 25): array |
||
| 179 | } |
||
| 180 |