| Conditions | 2 |
| Paths | 2 |
| Total Lines | 59 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 21 | public function execute(\DOMElement $apiDocument) |
||
| 22 | { |
||
| 23 | $this->database = gGetDb(); |
||
| 24 | |||
| 25 | $statusElement = $this->document->createElement("status"); |
||
| 26 | $apiDocument->appendChild($statusElement); |
||
| 27 | |||
| 28 | $query = $this->database->prepare(<<<SQL |
||
| 29 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
||
| 30 | FROM request |
||
| 31 | WHERE |
||
| 32 | status = :pstatus |
||
| 33 | AND emailconfirm = 'Confirmed'; |
||
| 34 | SQL |
||
| 35 | ); |
||
| 36 | |||
| 37 | global $availableRequestStates; |
||
| 38 | foreach ($availableRequestStates as $key => $value) { |
||
| 39 | $query->bindValue(":pstatus", $key); |
||
| 40 | $query->execute(); |
||
| 41 | $sus = $query->fetchColumn(); |
||
| 42 | $statusElement->setAttribute($value['api'], $sus); |
||
| 43 | $query->closeCursor(); |
||
| 44 | } |
||
| 45 | |||
| 46 | $query = $this->database->prepare(<<<SQL |
||
| 47 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
||
| 48 | FROM ban |
||
| 49 | WHERE |
||
| 50 | (duration > UNIX_TIMESTAMP() OR duration = -1) |
||
| 51 | AND active = 1; |
||
| 52 | SQL |
||
| 53 | ); |
||
| 54 | |||
| 55 | $query->execute(); |
||
| 56 | $sus = $query->fetchColumn(); |
||
| 57 | $statusElement->setAttribute("bans", $sus); |
||
| 58 | $query->closeCursor(); |
||
| 59 | |||
| 60 | $query = $this->database->prepare("SELECT /* Api/StatusAction */ COUNT(*) AS count FROM user WHERE status = :ulevel;"); |
||
| 61 | $query->bindValue(":ulevel", "Admin"); |
||
| 62 | $query->execute(); |
||
| 63 | $sus = $query->fetchColumn(); |
||
| 64 | $statusElement->setAttribute("useradmin", $sus); |
||
| 65 | $query->closeCursor(); |
||
| 66 | |||
| 67 | $query->bindValue(":ulevel", "User"); |
||
| 68 | $query->execute(); |
||
| 69 | $sus = $query->fetchColumn(); |
||
| 70 | $statusElement->setAttribute("user", $sus); |
||
| 71 | $query->closeCursor(); |
||
| 72 | |||
| 73 | $query->bindValue(":ulevel", "New"); |
||
| 74 | $query->execute(); |
||
| 75 | $sus = $query->fetchColumn(); |
||
| 76 | $statusElement->setAttribute("usernew", $sus); |
||
| 77 | $query->closeCursor(); |
||
| 78 | |||
| 79 | return $apiDocument; |
||
| 80 | } |
||
| 82 |