| Conditions | 14 |
| Paths | 73 |
| Total Lines | 77 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 96 | private function formatShare(IShare $share): array { |
||
| 97 | $result = [ |
||
| 98 | 'id' => $share->getFullId(), |
||
| 99 | 'share_type' => $share->getShareType(), |
||
| 100 | 'uid_owner' => $share->getSharedBy(), |
||
| 101 | 'displayname_owner' => $this->userManager->get($share->getSharedBy())->getDisplayName(), |
||
| 102 | 'permissions' => 0, |
||
| 103 | 'stime' => $share->getShareTime()->getTimestamp(), |
||
| 104 | 'parent' => null, |
||
| 105 | 'expiration' => null, |
||
| 106 | 'token' => null, |
||
| 107 | 'uid_file_owner' => $share->getShareOwner(), |
||
| 108 | 'displayname_file_owner' => $this->userManager->get($share->getShareOwner())->getDisplayName(), |
||
| 109 | 'path' => $share->getTarget(), |
||
| 110 | ]; |
||
| 111 | $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
||
| 112 | $nodes = $userFolder->getById($share->getNodeId()); |
||
| 113 | if (empty($nodes)) { |
||
| 114 | // fallback to guessing the path |
||
| 115 | $node = $userFolder->get($share->getTarget()); |
||
| 116 | if ($node === null || $share->getTarget() === '') { |
||
| 117 | throw new NotFoundException(); |
||
| 118 | } |
||
| 119 | } else { |
||
| 120 | $node = $nodes[0]; |
||
| 121 | } |
||
| 122 | |||
| 123 | $result['path'] = $userFolder->getRelativePath($node->getPath()); |
||
| 124 | if ($node instanceof \OCP\Files\Folder) { |
||
| 125 | $result['item_type'] = 'folder'; |
||
| 126 | } else { |
||
| 127 | $result['item_type'] = 'file'; |
||
| 128 | } |
||
| 129 | $result['mimetype'] = $node->getMimetype(); |
||
| 130 | $result['storage_id'] = $node->getStorage()->getId(); |
||
| 131 | $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
||
| 132 | $result['item_source'] = $node->getId(); |
||
| 133 | $result['file_source'] = $node->getId(); |
||
| 134 | $result['file_parent'] = $node->getParent()->getId(); |
||
| 135 | $result['file_target'] = $share->getTarget(); |
||
| 136 | |||
| 137 | $expiration = $share->getExpirationDate(); |
||
| 138 | if ($expiration !== null) { |
||
| 139 | $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
||
| 140 | } |
||
| 141 | |||
| 142 | if ($share->getShareType() === IShare::TYPE_GROUP) { |
||
| 143 | $group = $this->groupManager->get($share->getSharedWith()); |
||
| 144 | $result['share_with'] = $share->getSharedWith(); |
||
| 145 | $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
||
| 146 | } elseif ($share->getShareType() === IShare::TYPE_ROOM) { |
||
| 147 | $result['share_with'] = $share->getSharedWith(); |
||
| 148 | $result['share_with_displayname'] = ''; |
||
| 149 | |||
| 150 | try { |
||
| 151 | $result = array_merge($result, $this->getRoomShareHelper()->formatShare($share)); |
||
| 152 | } catch (QueryException $e) { |
||
|
|
|||
| 153 | } |
||
| 154 | } elseif ($share->getShareType() === IShare::TYPE_DECK) { |
||
| 155 | $result['share_with'] = $share->getSharedWith(); |
||
| 156 | $result['share_with_displayname'] = ''; |
||
| 157 | |||
| 158 | try { |
||
| 159 | $result = array_merge($result, $this->getDeckShareHelper()->formatShare($share)); |
||
| 160 | } catch (QueryException $e) { |
||
| 161 | } |
||
| 162 | } elseif ($share->getShareType() === IShare::TYPE_SCIENCEMESH) { |
||
| 163 | $result['share_with'] = $share->getSharedWith(); |
||
| 164 | $result['share_with_displayname'] = ''; |
||
| 165 | |||
| 166 | try { |
||
| 167 | $result = array_merge($result, $this->getSciencemeshShareHelper()->formatShare($share)); |
||
| 168 | } catch (QueryException $e) { |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | return $result; |
||
| 173 | } |
||
| 269 |