| Conditions | 6 |
| Paths | 32 |
| Total Lines | 54 |
| Code Lines | 43 |
| 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 | <script type='text/javascript' src='//www.midijs.net/lib/midi.js'></script> |
||
| 117 | function getUser($id, $connection) { |
||
| 118 | $userResult = array(); |
||
| 119 | $stmt = $connection->prepare("SELECT * FROM users WHERE id = ?"); |
||
| 120 | $stmt->bind_param("i", $id); |
||
| 121 | $stmt->execute(); |
||
| 122 | $result = $stmt->get_result(); |
||
| 123 | if($result->num_rows === 0) echo('That user does not exist.'); |
||
| 124 | while($row = $result->fetch_assoc()) { |
||
| 125 | $userResult['username'] = $row['username']; |
||
| 126 | $userResult['id'] = $row['id']; |
||
| 127 | $userResult['date'] = $row['date']; |
||
| 128 | $userResult['bio'] = $row['bio']; |
||
| 129 | $userResult['css'] = $row['css']; |
||
| 130 | $userResult['pfp'] = $row['pfp']; |
||
| 131 | $userResult['badges'] = explode(';', $row['badges']); |
||
| 132 | $userResult['music'] = $row['music']; |
||
| 133 | $userResult['rank'] = $row['rank']; |
||
| 134 | $userResult['currentgroup'] = $row['currentgroup']; |
||
| 135 | } |
||
| 136 | $stmt->close(); |
||
| 137 | |||
| 138 | $stmt = $connection->prepare("SELECT * FROM gamecomments WHERE author = ?"); |
||
| 139 | $stmt->bind_param("s", $userResult['username']); |
||
| 140 | $stmt->execute(); |
||
| 141 | $result = $stmt->get_result(); |
||
| 142 | |||
| 143 | $userResult['comments'] = 0; |
||
| 144 | while($row = $result->fetch_assoc()) { |
||
| 145 | $userResult['comments']++; |
||
| 146 | } |
||
| 147 | $stmt->close(); |
||
| 148 | |||
| 149 | $stmt = $connection->prepare("SELECT * FROM comments WHERE author = ?"); |
||
| 150 | $stmt->bind_param("s", $userResult['username']); |
||
| 151 | $stmt->execute(); |
||
| 152 | $result = $stmt->get_result(); |
||
| 153 | |||
| 154 | $userResult['profilecomments'] = 0; |
||
| 155 | while($row = $result->fetch_assoc()) { |
||
| 156 | $userResult['profilecomments']++; |
||
| 157 | } |
||
| 158 | $stmt->close(); |
||
| 159 | |||
| 160 | $stmt = $connection->prepare("SELECT * FROM files WHERE author = ? AND status='y'"); |
||
| 161 | $stmt->bind_param("s", $userResult['username']); |
||
| 162 | $stmt->execute(); |
||
| 163 | $result = $stmt->get_result(); |
||
| 164 | |||
| 165 | $userResult['filesuploaded'] = 0; |
||
| 166 | while($row = $result->fetch_assoc()) { |
||
| 167 | $userResult['filesuploaded']++; |
||
| 168 | } |
||
| 169 | $stmt->close(); |
||
| 170 | return $userResult; |
||
| 171 | } |
||
| 172 | ?> |