Conditions | 9 |
Paths | 13 |
Total Lines | 60 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
75 | public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) { |
||
76 | |||
77 | $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1); |
||
|
|||
78 | $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1)); |
||
79 | $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)); |
||
80 | $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_ROOM, null, -1)); |
||
81 | |||
82 | // filter out excluded shares and group shares that includes self |
||
83 | $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |
||
84 | return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |
||
85 | }); |
||
86 | |||
87 | $superShares = $this->buildSuperShares($shares, $user); |
||
88 | |||
89 | $mounts = []; |
||
90 | $view = new View('/' . $user->getUID() . '/files'); |
||
91 | $ownerViews = []; |
||
92 | $sharingDisabledForUser = $this->shareManager->sharingDisabledForUser($user->getUID()); |
||
93 | $foldersExistCache = new CappedMemoryCache(); |
||
94 | foreach ($superShares as $share) { |
||
95 | try { |
||
96 | /** @var \OCP\Share\IShare $parentShare */ |
||
97 | $parentShare = $share[0]; |
||
98 | |||
99 | if ($parentShare->getStatus() !== IShare::STATUS_ACCEPTED && |
||
100 | ($parentShare->getShareType() === IShare::TYPE_GROUP || |
||
101 | $parentShare->getShareType() === IShare::TYPE_USERGROUP || |
||
102 | $parentShare->getShareType() === IShare::TYPE_USER)) { |
||
103 | continue; |
||
104 | } |
||
105 | |||
106 | $owner = $parentShare->getShareOwner(); |
||
107 | if (!isset($ownerViews[$owner])) { |
||
108 | $ownerViews[$owner] = new View('/' . $parentShare->getShareOwner() . '/files'); |
||
109 | } |
||
110 | $mount = new SharedMount( |
||
111 | '\OCA\Files_Sharing\SharedStorage', |
||
112 | $mounts, |
||
113 | [ |
||
114 | 'user' => $user->getUID(), |
||
115 | // parent share |
||
116 | 'superShare' => $parentShare, |
||
117 | // children/component of the superShare |
||
118 | 'groupedShares' => $share[1], |
||
119 | 'ownerView' => $ownerViews[$owner], |
||
120 | 'sharingDisabledForUser' => $sharingDisabledForUser |
||
121 | ], |
||
122 | $storageFactory, |
||
123 | $view, |
||
124 | $foldersExistCache |
||
125 | ); |
||
126 | $mounts[$mount->getMountPoint()] = $mount; |
||
127 | } catch (\Exception $e) { |
||
128 | $this->logger->logException($e); |
||
129 | $this->logger->error('Error while trying to create shared mount'); |
||
130 | } |
||
131 | } |
||
132 | |||
133 | // array_filter removes the null values from the array |
||
134 | return array_values(array_filter($mounts)); |
||
135 | } |
||
241 |
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.