| Conditions | 7 |
| Paths | 9 |
| Total Lines | 64 |
| Code Lines | 44 |
| 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 |
||
| 78 | private function createInitConvs(){ |
||
| 79 | $initConvs = array(); |
||
| 80 | $convs = $this->userMapper->findByUser($this->app->getUserId()); |
||
| 81 | $usersAllreadyInConv = array(); |
||
| 82 | foreach($convs as $conv){ |
||
| 83 | $users = $this->userMapper->findUsersInConv($conv->getConversationId()); |
||
| 84 | // Find the correct contact for the correct user |
||
| 85 | $this->messages->setRequestData(array( |
||
| 86 | "conv_id" => $conv->getConversationId(), |
||
| 87 | 'user' => $this->app->getCurrentUser(), |
||
| 88 | "limit" => array(0,30) |
||
| 89 | )); |
||
| 90 | $messages = $this->messages->execute(); |
||
| 91 | $messages = $messages['messages']; |
||
| 92 | |||
| 93 | $files = $this->attachmentMapper->findRawByConv($conv->getConversationId()); |
||
| 94 | $initConvs[$conv->getConversationId()] = array( |
||
| 95 | "id" => $conv->getConversationId(), |
||
| 96 | "users"=> $users, |
||
| 97 | "backend" => "och", |
||
| 98 | "messages" => $messages, |
||
| 99 | "files" => $files |
||
| 100 | ); |
||
| 101 | if(count($users) === 2){ |
||
| 102 | foreach($users as $user){ |
||
| 103 | if($user !== \OCP\User::getUser()){ |
||
| 104 | $usersAllreadyInConv[] = $user; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | $this->join->setRequestData(array( |
||
| 110 | "conv_id" => $conv->getConversationId(), |
||
| 111 | "user" => $this->app->getCurrentUser(), |
||
| 112 | )); |
||
| 113 | $this->join->execute(); |
||
| 114 | } |
||
| 115 | |||
| 116 | $allUsers = \OCP\User::getUsers(); |
||
| 117 | $users = array_diff($allUsers, $usersAllreadyInConv); |
||
| 118 | |||
| 119 | foreach($users as $user){ |
||
| 120 | if($user !== \OCP\User::getUser()){ |
||
| 121 | $this->startconv->setRequestData(array( |
||
| 122 | "user" => $this->app->getCurrentUser(), |
||
| 123 | "user_to_invite" => array( |
||
| 124 | $this->app->getUserasContact($user), |
||
| 125 | ) |
||
| 126 | )); |
||
| 127 | $info = $this->startconv->execute(); |
||
| 128 | $initConvs[$info['conv_id']] = array( |
||
| 129 | "id" => $info['conv_id'], |
||
| 130 | "users"=> array( |
||
| 131 | \OCP\User::getUser(), |
||
| 132 | $user |
||
| 133 | ), |
||
| 134 | "backend" => "och", |
||
| 135 | "messages" => array() |
||
| 136 | ); |
||
| 137 | |||
| 138 | } |
||
| 139 | } |
||
| 140 | self::$initConvs = $initConvs; |
||
| 141 | } |
||
| 142 | |||
| 161 |