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 |
||
| 41 | class OcmController extends Controller { |
||
| 42 | const API_VERSION = '1.0-proposal1'; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var IURLGenerator |
||
| 46 | */ |
||
| 47 | protected $urlGenerator; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var IUserManager |
||
| 51 | */ |
||
| 52 | protected $userManager; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var AddressHandler |
||
| 56 | */ |
||
| 57 | protected $addressHandler; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var FedShareManager |
||
| 61 | */ |
||
| 62 | protected $fedShareManager; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var ILogger |
||
| 66 | */ |
||
| 67 | protected $logger; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * OcmController constructor. |
||
| 71 | * |
||
| 72 | * @param string $appName |
||
| 73 | * @param IRequest $request |
||
| 74 | * @param IURLGenerator $urlGenerator |
||
| 75 | * @param IUserManager $userManager |
||
| 76 | * @param AddressHandler $addressHandler |
||
| 77 | * @param FedShareManager $fedShareManager |
||
| 78 | * @param ILogger $logger |
||
| 79 | */ |
||
| 80 | View Code Duplication | public function __construct($appName, |
|
| 96 | |||
| 97 | /** |
||
| 98 | * @NoCSRFRequired |
||
| 99 | * @PublicPage |
||
| 100 | * |
||
| 101 | * EndPoint discovery |
||
| 102 | * Responds to /ocm-provider/ requests |
||
| 103 | * |
||
| 104 | * @return array |
||
| 105 | */ |
||
| 106 | public function discovery() { |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @NoCSRFRequired |
||
| 122 | * @PublicPage |
||
| 123 | * |
||
| 124 | * |
||
| 125 | * |
||
| 126 | * @param string $shareWith identifier of the user or group |
||
| 127 | * to share the resource with |
||
| 128 | * @param string $name name of the shared resource |
||
| 129 | * @param string $description share description (optional) |
||
| 130 | * @param string $providerId Identifier of the resource at the provider side |
||
| 131 | * @param string $owner identifier of the user that owns the resource |
||
| 132 | * @param string $ownerDisplayName display name of the owner |
||
| 133 | * @param string $sender Provider specific identifier of the user that wants |
||
| 134 | * to share the resource |
||
| 135 | * @param string $senderDisplayName Display name of the user that wants |
||
| 136 | * to share the resource |
||
| 137 | * @param string $shareType Share type (user or group share) |
||
| 138 | * @param string $resourceType only 'file' is supported atm |
||
| 139 | * @param array $protocol |
||
| 140 | * [ |
||
| 141 | * 'name' => (string) protocol name. Only 'webdav' is supported atm, |
||
| 142 | * 'options' => [ |
||
| 143 | * protocol specific options |
||
| 144 | * only `webdav` options are supported atm |
||
| 145 | * e.g. `uri`, `access_token`, `password`, `permissions` etc. |
||
| 146 | * |
||
| 147 | * For backward compatibility the webdav protocol will use |
||
| 148 | * the 'sharedSecret" as username and password |
||
| 149 | * ] |
||
| 150 | * |
||
| 151 | */ |
||
| 152 | public function createShare($shareWith, |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param string $notificationType notification type (SHARE_REMOVED, etc) |
||
| 243 | * @param string $resourceType only 'file' is supported atm |
||
| 244 | * @param string $providerId Identifier of the resource at the provider side |
||
| 245 | * @param array $notification |
||
| 246 | * [ |
||
| 247 | * optional additional parameters, depending on the notification |
||
| 248 | * and the resource type |
||
| 249 | * ] |
||
| 250 | */ |
||
| 251 | public function processNotification($notificationType, |
||
| 258 | |||
| 259 | protected function getProtocols() { |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Check if value is null or an array has any null item |
||
| 267 | * |
||
| 268 | * @param mixed $param |
||
| 269 | * |
||
| 270 | * @return bool |
||
| 271 | */ |
||
| 272 | View Code Duplication | protected function hasNull($param) { |
|
| 279 | } |
||
| 280 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.