| Conditions | 12 |
| Paths | 83 |
| Total Lines | 84 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 74 | public function conversationLoad($msg, $para) |
||
| 75 | { |
||
| 76 | $msg = json_decode($msg); |
||
| 77 | if (!empty($msg)) { |
||
| 78 | $userId = $msg->userId; |
||
| 79 | $add_load = 0; |
||
| 80 | $details = $msg->details; |
||
| 81 | $load = $msg->load; |
||
| 82 | |||
| 83 | if ($para == true) { |
||
| 84 | $details = convert_uudecode(hex2bin($details)); |
||
| 85 | } |
||
| 86 | $fetch = $this->obUser->userDetails($details, $para); |
||
| 87 | |||
| 88 | if ($fetch != null) { |
||
| 89 | $login_id = (int)$fetch['login_id']; |
||
| 90 | |||
| 91 | // Unique Identifier |
||
| 92 | if ($login_id > $userId) { |
||
| 93 | $identifier = $userId.':'.$login_id; |
||
| 94 | } else { |
||
| 95 | $identifier = $login_id.':'.$userId; |
||
| 96 | } |
||
| 97 | |||
| 98 | $query = "SELECT total_messages from total_message |
||
| 99 | where identifier = '$identifier'"; |
||
| 100 | if ($result = $this->connect->query($query)) { |
||
| 101 | if ($result->num_rows > 0) { |
||
| 102 | $total = $result->fetch_assoc(); |
||
| 103 | $total = $total['total_messages']; |
||
| 104 | if ($total - $load > 0) { |
||
| 105 | if ($total - $load > 10) { |
||
| 106 | $add_load = $load + 10; |
||
| 107 | } else { |
||
| 108 | $add_load = $total; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | $query = "SELECT message, time, sent_by FROM messages WHERE |
||
| 115 | identifier_message_number = '$identifier' |
||
| 116 | ORDER BY id DESC limit ".$load; |
||
| 117 | |||
| 118 | if ($result = $this->connect->query($query)) { |
||
| 119 | if ($result->num_rows > 0) { |
||
| 120 | while ($row = $result->fetch_assoc()) { |
||
| 121 | $row['time'] = $this->obTime->timeConversion( |
||
| 122 | $row['time'] |
||
| 123 | ); |
||
| 124 | $row = array_merge($row, ['start' => $userId]); |
||
| 125 | $this->array = array_merge($this->array, [$row]); |
||
| 126 | } |
||
| 127 | |||
| 128 | $this->array = array_merge( |
||
| 129 | [[ |
||
| 130 | 'name' => $fetch['name'], |
||
| 131 | 'username' => $fetch['username'], |
||
| 132 | 'id' => bin2hex(convert_uuencode($fetch['login_id'])), |
||
| 133 | 'load' => $add_load, |
||
| 134 | 'login_status' => $fetch['login_status'], |
||
| 135 | 'type' => 1 |
||
| 136 | ]], |
||
| 137 | $this->array |
||
| 138 | ); |
||
| 139 | return json_encode($this->array); |
||
| 140 | } else { |
||
| 141 | return json_encode( |
||
| 142 | [[ |
||
| 143 | 'name' => $fetch['name'], |
||
| 144 | 'username' => $fetch['username'], |
||
| 145 | 'id' => bin2hex(convert_uuencode($fetch['login_id'])), |
||
| 146 | 'login_status' => $fetch['login_status'], |
||
| 147 | 'type' => 0 |
||
| 148 | ]] |
||
| 149 | ); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | return "Query Failed"; |
||
| 153 | } |
||
| 154 | return "Query Failed"; |
||
| 155 | } |
||
| 156 | return "Empty"; |
||
| 157 | } |
||
| 158 | } |
||
| 159 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.