| Conditions | 11 | 
| Paths | 65 | 
| Total Lines | 132 | 
| Lines | 14 | 
| Ratio | 10.61 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php | ||
| 280 | public function processNotification($notificationType, | ||
| 281 | $resourceType, | ||
| 282 | $providerId, | ||
| 283 | $notification | ||
| 284 | 	) { | ||
| 285 | 		try { | ||
| 286 | 			if (!\is_array($notification)) { | ||
| 287 | throw new BadRequestException( | ||
| 288 | 'server can not add remote share, missing parameter' | ||
| 289 | ); | ||
| 290 | } | ||
| 291 | |||
| 292 | $notification = \array_merge( | ||
| 293 | ['sharedSecret' => null], | ||
| 294 | $notification | ||
| 295 | ); | ||
| 296 | |||
| 297 | $this->ocmMiddleware->assertNotNull( | ||
| 298 | [ | ||
| 299 | 'notificationType' => $notificationType, | ||
| 300 | 'resourceType' => $resourceType, | ||
| 301 | 'providerId' => $providerId, | ||
| 302 | 'sharedSecret' => $notification['sharedSecret'] | ||
| 303 | ] | ||
| 304 | ); | ||
| 305 | |||
| 306 | 			if ($this->isSupportedResourceType($resourceType) === false) { | ||
| 307 | throw new NotImplementedException( | ||
| 308 | 					"ResourceType {$resourceType} is not supported" | ||
| 309 | ); | ||
| 310 | } | ||
| 311 | |||
| 312 | 			switch ($notificationType) { | ||
| 313 | View Code Duplication | case FileNotification::NOTIFICATION_TYPE_SHARE_ACCEPTED: | |
| 314 | $this->ocmMiddleware->assertOutgoingSharingEnabled(); | ||
| 315 | $share = $this->ocmMiddleware->getValidShare( | ||
| 316 | $providerId, $notification['sharedSecret'] | ||
| 317 | ); | ||
| 318 | $this->fedShareManager->acceptShare($share); | ||
| 319 | break; | ||
| 320 | View Code Duplication | case FileNotification::NOTIFICATION_TYPE_SHARE_DECLINED: | |
| 321 | $this->ocmMiddleware->assertOutgoingSharingEnabled(); | ||
| 322 | $share = $this->ocmMiddleware->getValidShare( | ||
| 323 | $providerId, $notification['sharedSecret'] | ||
| 324 | ); | ||
| 325 | $this->fedShareManager->declineShare($share); | ||
| 326 | break; | ||
| 327 | case FileNotification::NOTIFICATION_TYPE_REQUEST_RESHARE: | ||
| 328 | $this->ocmMiddleware->assertOutgoingSharingEnabled(); | ||
| 329 | $this->ocmMiddleware->assertNotNull( | ||
| 330 | [ | ||
| 331 | 'shareWith' => $notification['shareWith'], | ||
| 332 | 'senderId' => $notification['senderId'], | ||
| 333 | ] | ||
| 334 | ); | ||
| 335 | $share = $this->ocmMiddleware->getValidShare( | ||
| 336 | $providerId, $notification['sharedSecret'] | ||
| 337 | ); | ||
| 338 | |||
| 339 | // don't allow to share a file back to the owner | ||
| 340 | $owner = $share->getShareOwner(); | ||
| 341 | $ownerAddress = $this->addressHandler->getLocalUserFederatedAddress($owner); | ||
| 342 | $shareWithAddress = new Address($notification['shareWith']); | ||
| 343 | $this->ocmMiddleware->assertNotSameUser($ownerAddress, $shareWithAddress); | ||
| 344 | $this->ocmMiddleware->assertSharingPermissionSet($share); | ||
| 345 | |||
| 346 | $reShare = $this->fedShareManager->reShare( | ||
| 347 | $share, $notification['senderId'], | ||
| 348 | $notification['shareWith'] | ||
| 349 | ); | ||
| 350 | return new JSONResponse( | ||
| 351 | [ | ||
| 352 | 'sharedSecret' => $reShare->getToken(), | ||
| 353 | 'providerId' => $reShare->getId() | ||
| 354 | ], | ||
| 355 | Http::STATUS_CREATED | ||
| 356 | ); | ||
| 357 | break; | ||
| 358 | case FileNotification::NOTIFICATION_TYPE_RESHARE_CHANGE_PERMISSION: | ||
| 359 | $this->ocmMiddleware->assertNotNull( | ||
| 360 | [ | ||
| 361 | 'permission' => $notification['permission'] | ||
| 362 | ] | ||
| 363 | ); | ||
| 364 | $share = $this->ocmMiddleware->getValidShare( | ||
| 365 | $providerId, $notification['sharedSecret'] | ||
| 366 | ); | ||
| 367 | $this->fedShareManager->updateOcmPermissions( | ||
| 368 | $share, | ||
| 369 | $notification['permission'] | ||
| 370 | ); | ||
| 371 | break; | ||
| 372 | case FileNotification::NOTIFICATION_TYPE_SHARE_UNSHARED: | ||
| 373 | $this->fedShareManager->unshare( | ||
| 374 | $providerId, $notification['sharedSecret'] | ||
| 375 | ); | ||
| 376 | break; | ||
| 377 | case FileNotification::NOTIFICATION_TYPE_RESHARE_UNDO: | ||
| 378 | // owner or sender unshared a resource | ||
| 379 | $share = $this->ocmMiddleware->getValidShare( | ||
| 380 | $providerId, $notification['sharedSecret'] | ||
| 381 | ); | ||
| 382 | $this->fedShareManager->undoReshare($share); | ||
| 383 | break; | ||
| 384 | default: | ||
| 385 | return new JSONResponse( | ||
| 386 | 						['message' => "Notification of type {$notificationType} is not supported"], | ||
| 387 | Http::STATUS_NOT_IMPLEMENTED | ||
| 388 | ); | ||
| 389 | } | ||
| 390 | 		} catch (OcmException $e) { | ||
| 391 | return new JSONResponse( | ||
| 392 | ['message' => $e->getMessage()], | ||
| 393 | $e->getHttpStatusCode() | ||
| 394 | ); | ||
| 395 | 		} catch (\Exception $e) { | ||
| 396 | $this->logger->error( | ||
| 397 | 				"server can not process notification, {$e->getMessage()}", | ||
| 398 | ['app' => 'federatefilesharing'] | ||
| 399 | ); | ||
| 400 | return new JSONResponse( | ||
| 401 | [ | ||
| 402 | 'message' => "internal server error, was not able to process notification" | ||
| 403 | ], | ||
| 404 | Http::STATUS_INTERNAL_SERVER_ERROR | ||
| 405 | ); | ||
| 406 | } | ||
| 407 | return new JSONResponse( | ||
| 408 | [], | ||
| 409 | Http::STATUS_CREATED | ||
| 410 | ); | ||
| 411 | } | ||
| 412 | |||
| 452 | 
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.