| Conditions | 12 |
| Paths | 60 |
| Total Lines | 84 |
| Code Lines | 56 |
| 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 |
||
| 40 | public static function pre_addToGroup($arguments) { |
||
| 41 | $currentUser = \OC::$server->getUserSession()->getUser(); |
||
| 42 | $currentUserID = is_null($currentUser) ? '' : $currentUser->getUID(); |
||
| 43 | |||
| 44 | // setup filesystem for added user if it isn't the current user |
||
| 45 | if($currentUserID !== $arguments['uid']) { |
||
| 46 | \OC_Util::tearDownFS(); |
||
| 47 | \OC_Util::setupFS($arguments['uid']); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** @var \OC\DB\Connection $db */ |
||
| 51 | $db = \OC::$server->getDatabaseConnection(); |
||
| 52 | |||
| 53 | $insert = $db->createQueryBuilder(); |
||
| 54 | |||
| 55 | $select = $db->createQueryBuilder(); |
||
| 56 | // Find the group shares and check if the user needs a unique target |
||
| 57 | $select->select('*') |
||
| 58 | ->from('`*PREFIX*share`') |
||
| 59 | ->where($select->expr()->andX( |
||
| 60 | $select->expr()->eq('`share_type`', ':shareType'), |
||
| 61 | $select->expr()->eq('`share_with`', ':shareWith') |
||
| 62 | )) |
||
| 63 | ->setParameter('shareType', self::SHARE_TYPE_GROUP) |
||
| 64 | ->setParameter('shareWith', $arguments['gid']); |
||
| 65 | |||
| 66 | $result = $select->execute(); |
||
| 67 | |||
| 68 | while ($item = $result->fetch()) { |
||
| 69 | |||
| 70 | $itemTarget = Helper::generateTarget( |
||
| 71 | $item['item_type'], |
||
| 72 | $item['item_source'], |
||
| 73 | self::SHARE_TYPE_USER, |
||
| 74 | $arguments['uid'], |
||
| 75 | $item['uid_owner'], |
||
| 76 | null, |
||
| 77 | $item['parent'] |
||
| 78 | ); |
||
| 79 | |||
| 80 | if ($item['item_type'] === 'file' || $item['item_type'] === 'folder') { |
||
| 81 | $fileTarget = Helper::generateTarget( |
||
| 82 | $item['item_type'], |
||
| 83 | $item['file_target'], |
||
| 84 | self::SHARE_TYPE_USER, |
||
| 85 | $arguments['uid'], |
||
| 86 | $item['uid_owner'], |
||
| 87 | null, |
||
| 88 | $item['parent'] |
||
| 89 | ); |
||
| 90 | } else { |
||
| 91 | $fileTarget = null; |
||
| 92 | } |
||
| 93 | |||
| 94 | |||
| 95 | // Insert an extra row for the group share if the item or file target is unique for this user |
||
| 96 | if ( |
||
| 97 | ($fileTarget === null && $itemTarget != $item['item_target']) |
||
| 98 | || ($fileTarget !== null && $fileTarget !== $item['file_target']) |
||
| 99 | ) { |
||
| 100 | self::$updateTargets[$arguments['gid']][] = [ |
||
| 101 | '`item_type`' => $insert->expr()->literal($item['item_type']), |
||
| 102 | '`item_source`' => $insert->expr()->literal($item['item_source']), |
||
| 103 | '`item_target`' => $insert->expr()->literal($itemTarget), |
||
| 104 | '`file_target`' => $insert->expr()->literal($fileTarget), |
||
| 105 | '`parent`' => $insert->expr()->literal($item['id']), |
||
| 106 | '`share_type`' => $insert->expr()->literal(self::$shareTypeGroupUserUnique), |
||
| 107 | '`share_with`' => $insert->expr()->literal($arguments['uid']), |
||
| 108 | '`uid_owner`' => $insert->expr()->literal($item['uid_owner']), |
||
| 109 | '`permissions`' => $insert->expr()->literal($item['permissions']), |
||
| 110 | '`stime`' => $insert->expr()->literal($item['stime']), |
||
| 111 | '`file_source`' => $insert->expr()->literal($item['file_source']), |
||
| 112 | ]; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | // re-setup old filesystem state |
||
| 117 | if($currentUserID !== $arguments['uid']) { |
||
| 118 | \OC_Util::tearDownFS(); |
||
| 119 | if($currentUserID !== '') { |
||
| 120 | \OC_Util::setupFS($currentUserID); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 178 |