| Conditions | 3 |
| Paths | 1 |
| Total Lines | 114 |
| Code Lines | 67 |
| Lines | 56 |
| Ratio | 49.12 % |
| Changes | 3 | ||
| 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 |
||
| 49 | private function registerRoutes() |
||
| 50 | { |
||
| 51 | $this->get( |
||
| 52 | '/status', |
||
| 53 | function (Request $request) { |
||
|
|
|||
| 54 | $response = new JsonResponse(); |
||
| 55 | $response->setBody($this->serverManager->status()); |
||
| 56 | |||
| 57 | return $response; |
||
| 58 | } |
||
| 59 | ); |
||
| 60 | |||
| 61 | $this->get( |
||
| 62 | '/load-stats', |
||
| 63 | function (Request $request) { |
||
| 64 | $response = new JsonResponse(); |
||
| 65 | $response->setBody($this->serverManager->loadStats()); |
||
| 66 | |||
| 67 | return $response; |
||
| 68 | } |
||
| 69 | ); |
||
| 70 | |||
| 71 | $this->get( |
||
| 72 | '/version', |
||
| 73 | function (Request $request) { |
||
| 74 | $response = new JsonResponse(); |
||
| 75 | $response->setBody($this->serverManager->version()); |
||
| 76 | |||
| 77 | return $response; |
||
| 78 | } |
||
| 79 | ); |
||
| 80 | |||
| 81 | $this->post( |
||
| 82 | '/kill', |
||
| 83 | View Code Duplication | function (Request $request) { |
|
| 84 | $commonName = $request->getPostParameter('common_name'); |
||
| 85 | Utils::validateCommonName($commonName); |
||
| 86 | |||
| 87 | $response = new JsonResponse(); |
||
| 88 | $response->setBody($this->serverManager->kill($commonName)); |
||
| 89 | |||
| 90 | return $response; |
||
| 91 | } |
||
| 92 | ); |
||
| 93 | |||
| 94 | $this->post( |
||
| 95 | '/ccd/disable', |
||
| 96 | View Code Duplication | function (Request $request) { |
|
| 97 | $commonName = $request->getPostParameter('common_name'); |
||
| 98 | if (is_null($commonName)) { |
||
| 99 | throw new BadRequestException('missing common_name'); |
||
| 100 | } |
||
| 101 | Utils::validateCommonName($commonName); |
||
| 102 | |||
| 103 | $response = new JsonResponse(); |
||
| 104 | $response->setBody( |
||
| 105 | array( |
||
| 106 | 'ok' => $this->ccdHandler->disableCommonName($commonName), |
||
| 107 | ) |
||
| 108 | ); |
||
| 109 | |||
| 110 | return $response; |
||
| 111 | } |
||
| 112 | ); |
||
| 113 | |||
| 114 | $this->delete( |
||
| 115 | '/ccd/disable', |
||
| 116 | View Code Duplication | function (Request $request) { |
|
| 117 | $commonName = $request->getUrl()->getQueryParameter('common_name'); |
||
| 118 | Utils::validateCommonName($commonName); |
||
| 119 | |||
| 120 | $response = new JsonResponse(); |
||
| 121 | $response->setBody( |
||
| 122 | array( |
||
| 123 | 'ok' => $this->ccdHandler->enableCommonName($commonName), |
||
| 124 | ) |
||
| 125 | ); |
||
| 126 | |||
| 127 | return $response; |
||
| 128 | } |
||
| 129 | ); |
||
| 130 | |||
| 131 | $this->get( |
||
| 132 | '/ccd/disable', |
||
| 133 | View Code Duplication | function (Request $request) { |
|
| 134 | // we typically deal with CNs, not user IDs, but the part of |
||
| 135 | // the CN before the first '_' is considered the user ID |
||
| 136 | $userId = $request->getUrl()->getQueryParameter('user_id'); |
||
| 137 | if (!is_null($userId)) { |
||
| 138 | Utils::validateUserId($userId); |
||
| 139 | } |
||
| 140 | |||
| 141 | $response = new JsonResponse(); |
||
| 142 | $response->setBody( |
||
| 143 | array( |
||
| 144 | 'ok' => true, |
||
| 145 | 'disabled' => $this->ccdHandler->getDisabledCommonNames($userId), |
||
| 146 | ) |
||
| 147 | ); |
||
| 148 | |||
| 149 | return $response; |
||
| 150 | } |
||
| 151 | ); |
||
| 152 | |||
| 153 | $this->post( |
||
| 154 | '/crl/fetch', |
||
| 155 | function (Request $request) { |
||
| 156 | $response = new JsonResponse(); |
||
| 157 | $response->setBody($this->crlFetcher->fetch()); |
||
| 158 | |||
| 159 | return $response; |
||
| 160 | } |
||
| 161 | ); |
||
| 162 | } |
||
| 163 | } |
||
| 164 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.