| Conditions | 6 |
| Paths | 32 |
| Total Lines | 52 |
| Code Lines | 41 |
| 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> |
||
| 90 | function getUser($id, $connection) { |
||
| 91 | $userResult = array(); |
||
| 92 | $stmt = $connection->prepare("SELECT * FROM users WHERE id = ?"); |
||
| 93 | $stmt->bind_param("i", $id); |
||
| 94 | $stmt->execute(); |
||
| 95 | $result = $stmt->get_result(); |
||
| 96 | if($result->num_rows === 0) echo('That user does not exist.'); |
||
| 97 | while($row = $result->fetch_assoc()) { |
||
| 98 | $userResult['username'] = $row['username']; |
||
| 99 | $userResult['id'] = $row['id']; |
||
| 100 | $userResult['date'] = $row['date']; |
||
| 101 | $userResult['bio'] = $row['bio']; |
||
| 102 | $userResult['css'] = $row['css']; |
||
| 103 | $userResult['pfp'] = $row['pfp']; |
||
| 104 | $userResult['badges'] = explode(';', $row['badges']); |
||
| 105 | $userResult['music'] = $row['music']; |
||
| 106 | } |
||
| 107 | $stmt->close(); |
||
| 108 | |||
| 109 | $stmt = $connection->prepare("SELECT * FROM gamecomments WHERE author = ?"); |
||
| 110 | $stmt->bind_param("s", $userResult['username']); |
||
| 111 | $stmt->execute(); |
||
| 112 | $result = $stmt->get_result(); |
||
| 113 | |||
| 114 | $userResult['comments'] = 0; |
||
| 115 | while($row = $result->fetch_assoc()) { |
||
| 116 | $userResult['comments']++; |
||
| 117 | } |
||
| 118 | $stmt->close(); |
||
| 119 | |||
| 120 | $stmt = $connection->prepare("SELECT * FROM comments WHERE author = ?"); |
||
| 121 | $stmt->bind_param("s", $userResult['username']); |
||
| 122 | $stmt->execute(); |
||
| 123 | $result = $stmt->get_result(); |
||
| 124 | |||
| 125 | $userResult['profilecomments'] = 0; |
||
| 126 | while($row = $result->fetch_assoc()) { |
||
| 127 | $userResult['profilecomments']++; |
||
| 128 | } |
||
| 129 | $stmt->close(); |
||
| 130 | |||
| 131 | $stmt = $connection->prepare("SELECT * FROM files WHERE author = ? AND status='y'"); |
||
| 132 | $stmt->bind_param("s", $userResult['username']); |
||
| 133 | $stmt->execute(); |
||
| 134 | $result = $stmt->get_result(); |
||
| 135 | |||
| 136 | $userResult['filesuploaded'] = 0; |
||
| 137 | while($row = $result->fetch_assoc()) { |
||
| 138 | $userResult['filesuploaded']++; |
||
| 139 | } |
||
| 140 | $stmt->close(); |
||
| 141 | return $userResult; |
||
| 142 | } |
||
| 143 | ?> |