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 |
||
46 | class OcmController extends Controller { |
||
47 | const API_VERSION = '1.0-proposal1'; |
||
48 | |||
49 | /** |
||
50 | * @var FederatedShareProvider |
||
51 | */ |
||
52 | private $federatedShareProvider; |
||
53 | |||
54 | /** |
||
55 | * @var IURLGenerator |
||
56 | */ |
||
57 | protected $urlGenerator; |
||
58 | |||
59 | /** |
||
60 | * @var IUserManager |
||
61 | */ |
||
62 | protected $userManager; |
||
63 | |||
64 | /** |
||
65 | * @var AddressHandler |
||
66 | */ |
||
67 | protected $addressHandler; |
||
68 | |||
69 | /** |
||
70 | * @var FedShareManager |
||
71 | */ |
||
72 | protected $fedShareManager; |
||
73 | |||
74 | /** |
||
75 | * @var ILogger |
||
76 | */ |
||
77 | protected $logger; |
||
78 | |||
79 | /** |
||
80 | * OcmController constructor. |
||
81 | * |
||
82 | * @param string $appName |
||
83 | * @param IRequest $request |
||
84 | * @param FederatedShareProvider $federatedShareProvider |
||
85 | * @param IURLGenerator $urlGenerator |
||
86 | * @param IUserManager $userManager |
||
87 | * @param AddressHandler $addressHandler |
||
88 | * @param FedShareManager $fedShareManager |
||
89 | * @param ILogger $logger |
||
90 | */ |
||
91 | View Code Duplication | public function __construct($appName, |
|
109 | |||
110 | /** |
||
111 | * @NoCSRFRequired |
||
112 | * @PublicPage |
||
113 | * |
||
114 | * EndPoint discovery |
||
115 | * Responds to /ocm-provider/ requests |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | public function discovery() { |
||
132 | |||
133 | /** |
||
134 | * @NoCSRFRequired |
||
135 | * @PublicPage |
||
136 | * |
||
137 | * |
||
138 | * |
||
139 | * @param string $shareWith identifier of the user or group |
||
140 | * to share the resource with |
||
141 | * @param string $name name of the shared resource |
||
142 | * @param string $description share description (optional) |
||
143 | * @param string $providerId Identifier of the resource at the provider side |
||
144 | * @param string $owner identifier of the user that owns the resource |
||
145 | * @param string $ownerDisplayName display name of the owner |
||
146 | * @param string $sender Provider specific identifier of the user that wants |
||
147 | * to share the resource |
||
148 | * @param string $senderDisplayName Display name of the user that wants |
||
149 | * to share the resource |
||
150 | * @param string $shareType Share type (user or group share) |
||
151 | * @param string $resourceType only 'file' is supported atm |
||
152 | * @param array $protocol |
||
153 | * [ |
||
154 | * 'name' => (string) protocol name. Only 'webdav' is supported atm, |
||
155 | * 'options' => [ |
||
156 | * protocol specific options |
||
157 | * only `webdav` options are supported atm |
||
158 | * e.g. `uri`, `access_token`, `password`, `permissions` etc. |
||
159 | * |
||
160 | * For backward compatibility the webdav protocol will use |
||
161 | * the 'sharedSecret" as username and password |
||
162 | * ] |
||
163 | * |
||
164 | * @return JSONResponse |
||
165 | */ |
||
166 | public function createShare($shareWith, |
||
256 | |||
257 | /** |
||
258 | * @param string $notificationType notification type (SHARE_REMOVED, etc) |
||
259 | * @param string $resourceType only 'file' is supported atm |
||
260 | * @param string $providerId Identifier of the resource at the provider side |
||
261 | * @param array $notification |
||
262 | * [ |
||
263 | * optional additional parameters, depending on the notification |
||
264 | * and the resource type |
||
265 | * ] |
||
266 | * |
||
267 | * @return JSONResponse |
||
268 | */ |
||
269 | public function processNotification($notificationType, |
||
342 | |||
343 | /** |
||
344 | * Get list of supported protocols |
||
345 | * |
||
346 | * @return array |
||
347 | */ |
||
348 | protected function getProtocols() { |
||
353 | |||
354 | /** |
||
355 | * Check if value is null or an array has any null item |
||
356 | * |
||
357 | * @param mixed $param |
||
358 | * |
||
359 | * @return bool |
||
360 | */ |
||
361 | View Code Duplication | protected function hasNull($param) { |
|
368 | |||
369 | /** |
||
370 | * Get share by id, validate it's type and token |
||
371 | * |
||
372 | * @param int $id |
||
373 | * @param string $sharedSecret |
||
374 | * |
||
375 | * @return IShare |
||
376 | * |
||
377 | * @throws InvalidShareException |
||
378 | * @throws Share\Exceptions\ShareNotFound |
||
379 | */ |
||
380 | View Code Duplication | protected function getValidShare($id, $sharedSecret) { |
|
389 | } |
||
390 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.