| Conditions | 8 |
| Paths | 528 |
| Total Lines | 59 |
| Code Lines | 40 |
| 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 |
||
| 38 | public function status() : Response |
||
| 39 | {
|
||
| 40 | $response = []; |
||
| 41 | |||
| 42 | //Try to connect to Redis |
||
| 43 | try {
|
||
| 44 | $this->redis->hSet('htest', 'a', 'x');
|
||
| 45 | $this->redis->hSet('htest', 'b', 'y');
|
||
| 46 | $this->redis->hSet('htest', 'c', 'z');
|
||
| 47 | $this->redis->hSet('htest', 'd', 't');
|
||
| 48 | $this->redis->hGetAll('htest');
|
||
| 49 | |||
| 50 | //$this->redis->ping(); |
||
| 51 | } catch (\RedisException $e) {
|
||
| 52 | $this->log->error($e->getMessage(), $e->getTrace()); |
||
| 53 | $response['errors']['redis'] = $e->getMessage(); |
||
| 54 | } catch (Exception $e) {
|
||
| 55 | $this->log->error("Redis isn't working. {$e->getMessage()}", $e->getTrace());
|
||
| 56 | $response['errors']['redis'] = "Redis isn't working."; |
||
| 57 | } |
||
| 58 | |||
| 59 | //Try to connect to Beanstalk |
||
| 60 | try {
|
||
| 61 | $this->queue->connect(); |
||
| 62 | } catch (BeanstalkException $e) {
|
||
| 63 | $this->log->error($e->getMessage(), $e->getTrace()); |
||
| 64 | $response['errors']['beanstalk'] = $e->getMessage(); |
||
| 65 | } catch (Exception $e) {
|
||
| 66 | $this->log->error("Beanstalk isn't working. {$e->getMessage()}", $e->getTrace());
|
||
| 67 | $response['errors']['beanstalk'] = "Beanstalk isn't working."; |
||
| 68 | } finally {
|
||
| 69 | $this->queue->disconnect(); |
||
| 70 | } |
||
| 71 | |||
| 72 | //Try to connect to db |
||
| 73 | try {
|
||
| 74 | $this->db->connect(); |
||
| 75 | } catch (PDOException $e) {
|
||
| 76 | $this->log->error($e->getMessage(), $e->getTrace()); |
||
| 77 | $response['errors']['db'] = $e->getMessage(); |
||
| 78 | } catch (Exception $e) {
|
||
| 79 | $this->log->error("The database isn't working. {$e->getMessage()}", $e->getTrace());
|
||
| 80 | $response['errors']['db'] = "The database isn't working."; |
||
| 81 | } |
||
| 82 | |||
| 83 | if (!count($response)) {
|
||
| 84 | return $this->response(['OK']); |
||
| 85 | } |
||
| 86 | |||
| 87 | $request = new \Phalcon\Http\Request(); |
||
| 88 | $response = [ |
||
| 89 | 'status' => [ |
||
| 90 | 'type' => 'FAILED', |
||
| 91 | 'identifier' => $request->getServerAddress(), |
||
| 92 | 'errors' => $response['errors'], |
||
| 93 | ], |
||
| 94 | ]; |
||
| 95 | |||
| 96 | return $this->response($response, 400, 'Error'); |
||
| 97 | } |
||
| 99 |