| Conditions | 7 |
| Paths | 19 |
| Total Lines | 68 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 49 | public static function start($uid, $file){ |
||
| 50 | // Create a directory to store genesis |
||
| 51 | $genesis = new \OCA\Documents\Genesis($file); |
||
| 52 | |||
| 53 | $oldSession = new Session(); |
||
| 54 | $oldSession->loadBy('file_id', $file->getFileId()); |
||
| 55 | |||
| 56 | //If there is no existing session we need to start a new one |
||
| 57 | if (!$oldSession->hasData()){ |
||
| 58 | $newSession = new Session(array( |
||
| 59 | $genesis->getPath(), |
||
| 60 | $genesis->getHash(), |
||
| 61 | $file->getOwner(), |
||
| 62 | $file->getFileId() |
||
| 63 | )); |
||
| 64 | |||
| 65 | if (!$newSession->insert()){ |
||
| 66 | throw new \Exception('Failed to add session into database'); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | $sessionData = $oldSession |
||
| 71 | ->loadBy('file_id', $file->getFileId()) |
||
| 72 | ->getData() |
||
| 73 | ; |
||
| 74 | |||
| 75 | $memberColor = \OCA\Documents\Helper::getMemberColor($uid); |
||
| 76 | $member = new \OCA\Documents\Db\Member([ |
||
| 77 | $sessionData['es_id'], |
||
| 78 | $uid, |
||
| 79 | $memberColor, |
||
| 80 | time(), |
||
| 81 | intval($file->isPublicShare()), |
||
| 82 | $file->getToken() |
||
| 83 | ]); |
||
| 84 | |||
| 85 | if (!$member->insert()){ |
||
| 86 | throw new \Exception('Failed to add member into database'); |
||
| 87 | } |
||
| 88 | $sessionData['member_id'] = (string) $member->getLastInsertId(); |
||
| 89 | |||
| 90 | // Do we have OC_Avatar in out disposal? |
||
| 91 | if (\OC::$server->getConfig()->getSystemValue('enable_avatars', true) !== true){ |
||
| 92 | $imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw=='; |
||
| 93 | } else { |
||
| 94 | $imageUrl = $uid; |
||
| 95 | } |
||
| 96 | |||
| 97 | $displayName = $file->isPublicShare() |
||
| 98 | ? $uid . ' ' . \OCA\Documents\Db\Member::getGuestPostfix() |
||
| 99 | : \OC::$server->getUserSession()->getUser()->getDisplayName($uid) |
||
| 100 | ; |
||
| 101 | $userId = $file->isPublicShare() ? $displayName : \OC::$server->getUserSession()->getUser()->getUID(); |
||
| 102 | $op = new \OCA\Documents\Db\Op(); |
||
| 103 | $op->addMember( |
||
| 104 | $sessionData['es_id'], |
||
| 105 | $sessionData['member_id'], |
||
| 106 | $displayName, |
||
| 107 | $userId, |
||
| 108 | $memberColor, |
||
| 109 | $imageUrl |
||
| 110 | ); |
||
| 111 | |||
| 112 | $sessionData['title'] = basename($file->getPath()); |
||
| 113 | $sessionData['permissions'] = $file->getPermissions(); |
||
| 114 | |||
| 115 | return $sessionData; |
||
| 116 | } |
||
| 117 | |||
| 213 |