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:
Complex classes like ShareAPIController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ShareAPIController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 60 | class ShareAPIController extends OCSController { |
||
| 61 | |||
| 62 | /** @var IManager */ |
||
| 63 | private $shareManager; |
||
| 64 | /** @var IGroupManager */ |
||
| 65 | private $groupManager; |
||
| 66 | /** @var IUserManager */ |
||
| 67 | private $userManager; |
||
| 68 | /** @var IRequest */ |
||
| 69 | protected $request; |
||
| 70 | /** @var IRootFolder */ |
||
| 71 | private $rootFolder; |
||
| 72 | /** @var IURLGenerator */ |
||
| 73 | private $urlGenerator; |
||
| 74 | /** @var string */ |
||
| 75 | private $currentUser; |
||
| 76 | /** @var IL10N */ |
||
| 77 | private $l; |
||
| 78 | /** @var \OCP\Files\Node */ |
||
| 79 | private $lockedNode; |
||
| 80 | /** @var IConfig */ |
||
| 81 | private $config; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Share20OCS constructor. |
||
| 85 | * |
||
| 86 | * @param string $appName |
||
| 87 | * @param IRequest $request |
||
| 88 | * @param IManager $shareManager |
||
| 89 | * @param IGroupManager $groupManager |
||
| 90 | * @param IUserManager $userManager |
||
| 91 | * @param IRootFolder $rootFolder |
||
| 92 | * @param IURLGenerator $urlGenerator |
||
| 93 | * @param string $userId |
||
| 94 | * @param IL10N $l10n |
||
| 95 | * @param IConfig $config |
||
| 96 | */ |
||
| 97 | View Code Duplication | public function __construct( |
|
| 98 | $appName, |
||
| 99 | IRequest $request, |
||
| 100 | IManager $shareManager, |
||
| 101 | IGroupManager $groupManager, |
||
| 102 | IUserManager $userManager, |
||
| 103 | IRootFolder $rootFolder, |
||
| 104 | IURLGenerator $urlGenerator, |
||
| 105 | $userId, |
||
| 106 | IL10N $l10n, |
||
| 107 | IConfig $config |
||
| 108 | ) { |
||
| 109 | parent::__construct($appName, $request); |
||
| 110 | |||
| 111 | $this->shareManager = $shareManager; |
||
| 112 | $this->userManager = $userManager; |
||
| 113 | $this->groupManager = $groupManager; |
||
| 114 | $this->request = $request; |
||
| 115 | $this->rootFolder = $rootFolder; |
||
| 116 | $this->urlGenerator = $urlGenerator; |
||
| 117 | $this->currentUser = $userId; |
||
| 118 | $this->l = $l10n; |
||
| 119 | $this->config = $config; |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Convert an IShare to an array for OCS output |
||
| 124 | * |
||
| 125 | * @param \OCP\Share\IShare $share |
||
| 126 | * @param Node|null $recipientNode |
||
| 127 | * @return array |
||
| 128 | * @throws NotFoundException In case the node can't be resolved. |
||
| 129 | */ |
||
| 130 | protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Check if one of the users address books knows the exact property, if |
||
| 222 | * yes we return the full name. |
||
| 223 | * |
||
| 224 | * @param string $query |
||
| 225 | * @param string $property |
||
| 226 | * @return string |
||
| 227 | */ |
||
| 228 | private function getDisplayNameFromAddressBook($query, $property) { |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Get a specific share by id |
||
| 244 | * |
||
| 245 | * @NoAdminRequired |
||
| 246 | * |
||
| 247 | * @param string $id |
||
| 248 | * @return DataResponse |
||
| 249 | * @throws OCSNotFoundException |
||
| 250 | */ |
||
| 251 | public function getShare($id) { |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Delete a share |
||
| 272 | * |
||
| 273 | * @NoAdminRequired |
||
| 274 | * |
||
| 275 | * @param string $id |
||
| 276 | * @return DataResponse |
||
| 277 | * @throws OCSNotFoundException |
||
| 278 | */ |
||
| 279 | public function deleteShare($id) { |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @NoAdminRequired |
||
| 309 | * |
||
| 310 | * @param string $path |
||
| 311 | * @param int $permissions |
||
| 312 | * @param int $shareType |
||
| 313 | * @param string $shareWith |
||
| 314 | * @param string $publicUpload |
||
| 315 | * @param string $password |
||
| 316 | * @param string $expireDate |
||
| 317 | * |
||
| 318 | * @return DataResponse |
||
| 319 | * @throws OCSNotFoundException |
||
| 320 | * @throws OCSForbiddenException |
||
| 321 | * @throws OCSBadRequestException |
||
| 322 | * @throws OCSException |
||
| 323 | * |
||
| 324 | * @suppress PhanUndeclaredClassMethod |
||
| 325 | */ |
||
| 326 | public function createShare( |
||
| 327 | $path = null, |
||
| 328 | $permissions = null, |
||
| 329 | $shareType = -1, |
||
| 330 | $shareWith = null, |
||
| 331 | $publicUpload = 'false', |
||
| 332 | $password = '', |
||
| 333 | $expireDate = '' |
||
| 334 | ) { |
||
| 335 | $share = $this->shareManager->newShare(); |
||
| 336 | |||
| 337 | if ($permissions === null) { |
||
| 338 | $permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
||
| 339 | } |
||
| 340 | |||
| 341 | // Verify path |
||
| 342 | if ($path === null) { |
||
| 343 | throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
||
| 344 | } |
||
| 345 | |||
| 346 | $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
||
| 347 | try { |
||
| 348 | $path = $userFolder->get($path); |
||
| 349 | } catch (NotFoundException $e) { |
||
| 350 | throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
||
| 351 | } |
||
| 352 | |||
| 353 | $share->setNode($path); |
||
| 354 | |||
| 355 | try { |
||
| 356 | $this->lock($share->getNode()); |
||
| 357 | } catch (LockedException $e) { |
||
| 358 | throw new OCSNotFoundException($this->l->t('Could not create share')); |
||
| 359 | } |
||
| 360 | |||
| 361 | if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) { |
||
| 362 | throw new OCSNotFoundException($this->l->t('invalid permissions')); |
||
| 363 | } |
||
| 364 | |||
| 365 | // Shares always require read permissions |
||
| 366 | $permissions |= Constants::PERMISSION_READ; |
||
| 367 | |||
| 368 | if ($path instanceof \OCP\Files\File) { |
||
| 369 | // Single file shares should never have delete or create permissions |
||
| 370 | $permissions &= ~Constants::PERMISSION_DELETE; |
||
| 371 | $permissions &= ~Constants::PERMISSION_CREATE; |
||
| 372 | } |
||
| 373 | |||
| 374 | /* |
||
| 375 | * Hack for https://github.com/owncloud/core/issues/22587 |
||
| 376 | * We check the permissions via webdav. But the permissions of the mount point |
||
| 377 | * do not equal the share permissions. Here we fix that for federated mounts. |
||
| 378 | */ |
||
| 379 | if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
||
| 380 | $permissions &= ~($permissions & ~$path->getPermissions()); |
||
| 381 | } |
||
| 382 | |||
| 383 | if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
||
| 384 | // Valid user is required to share |
||
| 385 | if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
||
| 386 | throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
||
| 387 | } |
||
| 388 | $share->setSharedWith($shareWith); |
||
| 389 | $share->setPermissions($permissions); |
||
| 390 | } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
||
| 391 | if (!$this->shareManager->allowGroupSharing()) { |
||
| 392 | throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
||
| 393 | } |
||
| 394 | |||
| 395 | // Valid group is required to share |
||
| 396 | if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
||
| 397 | throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
||
| 398 | } |
||
| 399 | $share->setSharedWith($shareWith); |
||
| 400 | $share->setPermissions($permissions); |
||
| 401 | } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
||
| 402 | //Can we even share links? |
||
| 403 | if (!$this->shareManager->shareApiAllowLinks()) { |
||
| 404 | throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
||
| 405 | } |
||
| 406 | |||
| 407 | /* |
||
| 408 | * For now we only allow 1 link share. |
||
| 409 | * Return the existing link share if this is a duplicate |
||
| 410 | */ |
||
| 411 | $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
||
| 412 | if (!empty($existingShares)) { |
||
| 413 | return new DataResponse($this->formatShare($existingShares[0])); |
||
| 414 | } |
||
| 415 | |||
| 416 | if ($publicUpload === 'true') { |
||
| 417 | // Check if public upload is allowed |
||
| 418 | if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
||
| 419 | throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
||
| 420 | } |
||
| 421 | |||
| 422 | // Public upload can only be set for folders |
||
| 423 | if ($path instanceof \OCP\Files\File) { |
||
| 424 | throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
||
| 425 | } |
||
| 426 | |||
| 427 | $share->setPermissions( |
||
| 428 | Constants::PERMISSION_READ | |
||
| 429 | Constants::PERMISSION_CREATE | |
||
| 430 | Constants::PERMISSION_UPDATE | |
||
| 431 | Constants::PERMISSION_DELETE |
||
| 432 | ); |
||
| 433 | } else { |
||
| 434 | $share->setPermissions(Constants::PERMISSION_READ); |
||
| 435 | } |
||
| 436 | |||
| 437 | // Set password |
||
| 438 | if ($password !== '') { |
||
| 439 | $share->setPassword($password); |
||
| 440 | } |
||
| 441 | |||
| 442 | //Expire date |
||
| 443 | if ($expireDate !== '') { |
||
| 444 | try { |
||
| 445 | $expireDate = $this->parseDate($expireDate); |
||
| 446 | $share->setExpirationDate($expireDate); |
||
| 447 | } catch (\Exception $e) { |
||
| 448 | throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
||
| 449 | } |
||
| 450 | } |
||
| 451 | |||
| 452 | } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
||
| 453 | if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
||
| 454 | throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
||
| 455 | } |
||
| 456 | |||
| 457 | $share->setSharedWith($shareWith); |
||
| 458 | $share->setPermissions($permissions); |
||
| 459 | } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
||
| 460 | if ($share->getNodeType() === 'file') { |
||
| 461 | $share->setPermissions(Constants::PERMISSION_READ); |
||
| 462 | } else { |
||
| 463 | $share->setPermissions($permissions); |
||
| 464 | } |
||
| 465 | $share->setSharedWith($shareWith); |
||
| 466 | } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
||
| 467 | if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { |
||
| 468 | throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
||
| 469 | } |
||
| 470 | |||
| 471 | $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith); |
||
| 472 | |||
| 473 | // Valid circle is required to share |
||
| 474 | if ($circle === null) { |
||
| 475 | throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
||
| 476 | } |
||
| 477 | $share->setSharedWith($shareWith); |
||
| 478 | $share->setPermissions($permissions); |
||
| 479 | } else { |
||
| 480 | throw new OCSBadRequestException($this->l->t('Unknown share type')); |
||
| 481 | } |
||
| 482 | |||
| 483 | $share->setShareType($shareType); |
||
| 484 | $share->setSharedBy($this->currentUser); |
||
| 485 | |||
| 486 | try { |
||
| 487 | $share = $this->shareManager->createShare($share); |
||
| 488 | } catch (GenericShareException $e) { |
||
| 489 | $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
||
| 490 | throw new OCSException($e->getHint(), $code); |
||
| 491 | } catch (\Exception $e) { |
||
| 492 | throw new OCSForbiddenException($e->getMessage(), $e); |
||
| 493 | } |
||
| 494 | |||
| 495 | $output = $this->formatShare($share); |
||
| 496 | |||
| 497 | return new DataResponse($output); |
||
| 498 | } |
||
| 499 | |||
| 500 | /** |
||
| 501 | * @param \OCP\Files\File|\OCP\Files\Folder $node |
||
| 502 | * @param boolean $includeTags |
||
| 503 | * @return DataResponse |
||
| 504 | */ |
||
| 505 | private function getSharedWithMe($node = null, $includeTags) { |
||
| 534 | |||
| 535 | /** |
||
| 536 | * @param \OCP\Files\Folder $folder |
||
| 537 | * @return DataResponse |
||
| 538 | * @throws OCSBadRequestException |
||
| 539 | */ |
||
| 540 | private function getSharesInDir($folder) { |
||
| 571 | |||
| 572 | /** |
||
| 573 | * The getShares function. |
||
| 574 | * |
||
| 575 | * @NoAdminRequired |
||
| 576 | * |
||
| 577 | * @param string $shared_with_me |
||
| 578 | * @param string $reshares |
||
| 579 | * @param string $subfiles |
||
| 580 | * @param string $path |
||
| 581 | * |
||
| 582 | * - Get shares by the current user |
||
| 583 | * - Get shares by the current user and reshares (?reshares=true) |
||
| 584 | * - Get shares with the current user (?shared_with_me=true) |
||
| 585 | * - Get shares for a specific path (?path=...) |
||
| 586 | * - Get all shares in a folder (?subfiles=true&path=..) |
||
| 587 | * |
||
| 588 | * @return DataResponse |
||
| 589 | * @throws OCSNotFoundException |
||
| 590 | */ |
||
| 591 | public function getShares( |
||
| 664 | |||
| 665 | /** |
||
| 666 | * @NoAdminRequired |
||
| 667 | * |
||
| 668 | * @param int $id |
||
| 669 | * @param int $permissions |
||
| 670 | * @param string $password |
||
| 671 | * @param string $publicUpload |
||
| 672 | * @param string $expireDate |
||
| 673 | * @return DataResponse |
||
| 674 | * @throws OCSNotFoundException |
||
| 675 | * @throws OCSBadRequestException |
||
| 676 | * @throws OCSForbiddenException |
||
| 677 | */ |
||
| 678 | public function updateShare( |
||
| 679 | $id, |
||
| 680 | $permissions = null, |
||
| 681 | $password = null, |
||
| 682 | $publicUpload = null, |
||
| 683 | $expireDate = null |
||
| 684 | ) { |
||
| 685 | try { |
||
| 686 | $share = $this->getShareById($id); |
||
| 687 | } catch (ShareNotFound $e) { |
||
| 688 | throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
||
| 689 | } |
||
| 690 | |||
| 691 | $this->lock($share->getNode()); |
||
| 692 | |||
| 693 | if (!$this->canAccessShare($share, false)) { |
||
| 694 | throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
||
| 695 | } |
||
| 696 | |||
| 697 | if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
||
| 698 | throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
||
| 699 | } |
||
| 700 | |||
| 701 | /* |
||
| 702 | * expirationdate, password and publicUpload only make sense for link shares |
||
| 703 | */ |
||
| 704 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
||
| 705 | |||
| 706 | $newPermissions = null; |
||
| 707 | if ($publicUpload === 'true') { |
||
| 708 | $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
||
| 709 | } else if ($publicUpload === 'false') { |
||
| 710 | $newPermissions = Constants::PERMISSION_READ; |
||
| 711 | } |
||
| 712 | |||
| 713 | if ($permissions !== null) { |
||
| 714 | $newPermissions = (int)$permissions; |
||
| 715 | $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE; |
||
| 716 | } |
||
| 717 | |||
| 718 | if ($newPermissions !== null && |
||
| 719 | !in_array($newPermissions, [ |
||
| 720 | Constants::PERMISSION_READ, |
||
| 721 | Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy |
||
| 722 | Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct |
||
| 723 | Constants::PERMISSION_CREATE, // hidden file list |
||
| 724 | Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files |
||
| 725 | ]) |
||
| 726 | ) { |
||
| 727 | throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
||
| 728 | } |
||
| 729 | |||
| 730 | if ( |
||
| 731 | // legacy |
||
| 732 | $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) || |
||
| 733 | // correct |
||
| 734 | $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
||
| 735 | ) { |
||
| 736 | if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
||
| 737 | throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
||
| 738 | } |
||
| 739 | |||
| 740 | if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
||
| 741 | throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
||
| 742 | } |
||
| 743 | |||
| 744 | // normalize to correct public upload permissions |
||
| 745 | $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
||
| 746 | } |
||
| 747 | |||
| 748 | if ($newPermissions !== null) { |
||
| 749 | $share->setPermissions($newPermissions); |
||
| 750 | $permissions = $newPermissions; |
||
| 751 | } |
||
| 752 | |||
| 753 | View Code Duplication | if ($expireDate === '') { |
|
| 754 | $share->setExpirationDate(null); |
||
| 755 | } else if ($expireDate !== null) { |
||
| 756 | try { |
||
| 757 | $expireDate = $this->parseDate($expireDate); |
||
| 758 | } catch (\Exception $e) { |
||
| 759 | throw new OCSBadRequestException($e->getMessage(), $e); |
||
| 760 | } |
||
| 761 | $share->setExpirationDate($expireDate); |
||
| 762 | } |
||
| 763 | |||
| 764 | View Code Duplication | if ($password === '') { |
|
| 765 | $share->setPassword(null); |
||
| 766 | } else if ($password !== null) { |
||
| 767 | $share->setPassword($password); |
||
| 768 | } |
||
| 769 | |||
| 770 | } else { |
||
| 771 | if ($permissions !== null) { |
||
| 772 | $permissions = (int)$permissions; |
||
| 773 | $share->setPermissions($permissions); |
||
| 774 | } |
||
| 775 | |||
| 776 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
||
| 777 | View Code Duplication | if ($password === '') { |
|
| 778 | $share->setPassword(null); |
||
| 779 | } else if ($password !== null) { |
||
| 780 | $share->setPassword($password); |
||
| 781 | } |
||
| 782 | } |
||
| 783 | |||
| 784 | View Code Duplication | if ($expireDate === '') { |
|
| 785 | $share->setExpirationDate(null); |
||
| 786 | } else if ($expireDate !== null) { |
||
| 787 | try { |
||
| 788 | $expireDate = $this->parseDate($expireDate); |
||
| 789 | } catch (\Exception $e) { |
||
| 790 | throw new OCSBadRequestException($e->getMessage(), $e); |
||
| 791 | } |
||
| 792 | $share->setExpirationDate($expireDate); |
||
| 793 | } |
||
| 794 | |||
| 795 | } |
||
| 796 | |||
| 797 | if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
||
| 798 | /* Check if this is an incomming share */ |
||
| 799 | $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
||
| 800 | $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
||
| 801 | |||
| 802 | /** @var \OCP\Share\IShare[] $incomingShares */ |
||
| 803 | if (!empty($incomingShares)) { |
||
| 804 | $maxPermissions = 0; |
||
| 805 | foreach ($incomingShares as $incomingShare) { |
||
| 806 | $maxPermissions |= $incomingShare->getPermissions(); |
||
| 807 | } |
||
| 808 | |||
| 809 | if ($share->getPermissions() & ~$maxPermissions) { |
||
| 810 | throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
||
| 811 | } |
||
| 812 | } |
||
| 813 | } |
||
| 814 | |||
| 815 | |||
| 816 | try { |
||
| 817 | $share = $this->shareManager->updateShare($share); |
||
| 818 | } catch (\Exception $e) { |
||
| 819 | throw new OCSBadRequestException($e->getMessage(), $e); |
||
| 820 | } |
||
| 821 | |||
| 822 | return new DataResponse($this->formatShare($share)); |
||
| 823 | } |
||
| 824 | |||
| 825 | /** |
||
| 826 | * @param \OCP\Share\IShare $share |
||
| 827 | * @return bool |
||
| 828 | */ |
||
| 829 | protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
||
| 864 | |||
| 865 | /** |
||
| 866 | * Make sure that the passed date is valid ISO 8601 |
||
| 867 | * So YYYY-MM-DD |
||
| 868 | * If not throw an exception |
||
| 869 | * |
||
| 870 | * @param string $expireDate |
||
| 871 | * |
||
| 872 | * @throws \Exception |
||
| 873 | * @return \DateTime |
||
| 874 | */ |
||
| 875 | private function parseDate($expireDate) { |
||
| 890 | |||
| 891 | /** |
||
| 892 | * Since we have multiple providers but the OCS Share API v1 does |
||
| 893 | * not support this we need to check all backends. |
||
| 894 | * |
||
| 895 | * @param string $id |
||
| 896 | * @return \OCP\Share\IShare |
||
| 897 | * @throws ShareNotFound |
||
| 898 | */ |
||
| 899 | private function getShareById($id) { |
||
| 936 | |||
| 937 | /** |
||
| 938 | * Lock a Node |
||
| 939 | * |
||
| 940 | * @param \OCP\Files\Node $node |
||
| 941 | */ |
||
| 942 | private function lock(\OCP\Files\Node $node) { |
||
| 946 | |||
| 947 | /** |
||
| 948 | * Cleanup the remaining locks |
||
| 949 | */ |
||
| 950 | public function cleanup() { |
||
| 955 | } |
||
| 956 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.