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 |
||
| 43 | class CloudFederationProviderManager implements ICloudFederationProviderManager { |
||
| 44 | |||
| 45 | /** @var array list of available cloud federation providers */ |
||
| 46 | private $cloudFederationProvider; |
||
| 47 | |||
| 48 | /** @var IAppManager */ |
||
| 49 | private $appManager; |
||
| 50 | |||
| 51 | /** @var IClientService */ |
||
| 52 | private $httpClientService; |
||
| 53 | |||
| 54 | /** @var ICloudIdManager */ |
||
| 55 | private $cloudIdManager; |
||
| 56 | |||
| 57 | /** @var ILogger */ |
||
| 58 | private $logger; |
||
| 59 | |||
| 60 | /** @var array cache OCM end-points */ |
||
| 61 | private $ocmEndPoints = []; |
||
| 62 | |||
| 63 | private $supportedAPIVersion = '1.0-proposal1'; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * CloudFederationProviderManager constructor. |
||
| 67 | * |
||
| 68 | * @param IAppManager $appManager |
||
| 69 | * @param IClientService $httpClientService |
||
| 70 | * @param ICloudIdManager $cloudIdManager |
||
| 71 | * @param ILogger $logger |
||
| 72 | */ |
||
| 73 | public function __construct(IAppManager $appManager, |
||
| 83 | |||
| 84 | |||
| 85 | /** |
||
| 86 | * Registers an callback function which must return an cloud federation provider |
||
| 87 | * |
||
| 88 | * @param string $resourceType which resource type does the provider handles |
||
| 89 | * @param string $displayName user facing name of the federated share provider |
||
| 90 | * @param callable $callback |
||
| 91 | */ |
||
| 92 | public function addCloudFederationProvider($resourceType, $displayName, callable $callback) { |
||
| 100 | |||
| 101 | /** |
||
| 102 | * remove cloud federation provider |
||
| 103 | * |
||
| 104 | * @param string $providerId |
||
| 105 | */ |
||
| 106 | public function removeCloudFederationProvider($providerId) { |
||
| 109 | |||
| 110 | /** |
||
| 111 | * get a list of all cloudFederationProviders |
||
| 112 | * |
||
| 113 | * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
||
| 114 | */ |
||
| 115 | public function getAllCloudFederationProviders() { |
||
| 118 | |||
| 119 | /** |
||
| 120 | * get a specific cloud federation provider |
||
| 121 | * |
||
| 122 | * @param string $resourceType |
||
| 123 | * @return ICloudFederationProvider |
||
| 124 | * @throws ProviderDoesNotExistsException |
||
| 125 | */ |
||
| 126 | public function getCloudFederationProvider($resourceType) { |
||
| 133 | |||
| 134 | public function sendShare(ICloudFederationShare $share) { |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @param string $url |
||
| 170 | * @param ICloudFederationNotification $notification |
||
| 171 | * @return mixed |
||
| 172 | */ |
||
| 173 | public function sendNotification($url, ICloudFederationNotification $notification) { |
||
| 198 | |||
| 199 | /** |
||
| 200 | * check if the new cloud federation API is ready to be used |
||
| 201 | * |
||
| 202 | * @return bool |
||
| 203 | */ |
||
| 204 | public function isReady() { |
||
| 207 | /** |
||
| 208 | * check if server supports the new OCM api and ask for the correct end-point |
||
| 209 | * |
||
| 210 | * @param string $url full base URL of the cloud server |
||
| 211 | * @return string |
||
| 212 | */ |
||
| 213 | protected function getOCMEndPoint($url) { |
||
| 240 | |||
| 241 | |||
| 242 | } |
||
| 243 |