Conditions | 10 |
Paths | 41 |
Total Lines | 64 |
Lines | 18 |
Ratio | 28.13 % |
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 |
||
92 | private function formatShare(IShare $share): array { |
||
93 | |||
94 | $result = [ |
||
95 | 'id' => $share->getFullId(), |
||
96 | 'share_type' => $share->getShareType(), |
||
97 | 'uid_owner' => $share->getSharedBy(), |
||
98 | 'displayname_owner' => $this->userManager->get($share->getSharedBy())->getDisplayName(), |
||
99 | 'permissions' => 0, |
||
100 | 'stime' => $share->getShareTime()->getTimestamp(), |
||
101 | 'parent' => null, |
||
102 | 'expiration' => null, |
||
103 | 'token' => null, |
||
104 | 'uid_file_owner' => $share->getShareOwner(), |
||
105 | 'displayname_file_owner' => $this->userManager->get($share->getShareOwner())->getDisplayName(), |
||
106 | 'path' => $share->getTarget(), |
||
107 | ]; |
||
108 | $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
||
109 | $nodes = $userFolder->getById($share->getNodeId()); |
||
110 | View Code Duplication | if (empty($nodes)) { |
|
111 | // fallback to guessing the path |
||
112 | $node = $userFolder->get($share->getTarget()); |
||
113 | if ($node === null || $share->getTarget() === '') { |
||
114 | throw new NotFoundException(); |
||
115 | } |
||
116 | } else { |
||
117 | $node = $nodes[0]; |
||
118 | } |
||
119 | |||
120 | $result['path'] = $userFolder->getRelativePath($node->getPath()); |
||
121 | if ($node instanceOf \OCP\Files\Folder) { |
||
122 | $result['item_type'] = 'folder'; |
||
123 | } else { |
||
124 | $result['item_type'] = 'file'; |
||
125 | } |
||
126 | $result['mimetype'] = $node->getMimetype(); |
||
127 | $result['storage_id'] = $node->getStorage()->getId(); |
||
128 | $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
||
129 | $result['item_source'] = $node->getId(); |
||
130 | $result['file_source'] = $node->getId(); |
||
131 | $result['file_parent'] = $node->getParent()->getId(); |
||
132 | $result['file_target'] = $share->getTarget(); |
||
133 | |||
134 | $expiration = $share->getExpirationDate(); |
||
135 | if ($expiration !== null) { |
||
136 | $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
||
137 | } |
||
138 | |||
139 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
||
140 | $group = $this->groupManager->get($share->getSharedWith()); |
||
141 | $result['share_with'] = $share->getSharedWith(); |
||
142 | $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
||
143 | View Code Duplication | } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_ROOM) { |
|
144 | $result['share_with'] = $share->getSharedWith(); |
||
145 | $result['share_with_displayname'] = ''; |
||
146 | |||
147 | try { |
||
148 | $result = array_merge($result, $this->getRoomShareHelper()->formatShare($share)); |
||
149 | } catch (QueryException $e) { |
||
|
|||
150 | } |
||
151 | } |
||
152 | |||
153 | return $result; |
||
154 | |||
155 | } |
||
156 | |||
215 |