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