| Conditions | 8 |
| Paths | 4 |
| Total Lines | 63 |
| 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 |
||
| 133 | public function getCollection() |
||
| 134 | { |
||
| 135 | URL::forceRootUrl(config('app.url')); |
||
| 136 | |||
| 137 | $collection = [ |
||
| 138 | 'variables' => [], |
||
| 139 | 'info' => [ |
||
| 140 | 'name' => config('apidoc.postman.name') ?: config('app.name').' API', |
||
| 141 | '_postman_id' => Uuid::uuid4()->toString(), |
||
| 142 | 'description' => config('apidoc.postman.description') ?: '', |
||
| 143 | 'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json', |
||
| 144 | ], |
||
| 145 | 'item' => $this->routeGroups->map(function ($routes, $group) { |
||
| 146 | list($groupName, $groupDescription) = explode("\n\n", $group); |
||
| 147 | |||
| 148 | return [ |
||
| 149 | 'name' => $groupName, |
||
| 150 | 'description' => $groupDescription, |
||
| 151 | 'item' => $routes->map(function ($route) { |
||
| 152 | $mode = $route['methods'][0] === 'PUT' ? 'urlencoded' : 'formdata'; |
||
| 153 | |||
| 154 | return [ |
||
| 155 | 'name' => $route['title'] != '' ? $route['title'] : $this->getRouteUri($route), |
||
| 156 | 'event' => [[ |
||
| 157 | 'listen' => 'test', |
||
| 158 | 'script' => $this->usePostmanEnvironment ? [ |
||
| 159 | 'id' => Uuid::uuid4()->toString(), |
||
| 160 | 'exec' => [ |
||
| 161 | 'var response = JSON.parse(responseBody);', |
||
| 162 | 'tests["Successful request"] = responseCode.code === 200;', |
||
| 163 | 'if (response.'.$this->getResponseAccessTokenKey().') { postman.setEnvironmentVariable("'.$this->getAccessTokenVariable().'", response.'.$this->getResponseAccessTokenKey().'); }', |
||
| 164 | 'if (response.'.$this->getResponseRefreshTokenKey().') { postman.setEnvironmentVariable("'.$this->getRefreshTokenVariable().'", response.'.$this->getResponseRefreshTokenKey().'); }', |
||
| 165 | ], |
||
| 166 | 'type' => 'text/javascript', |
||
| 167 | ] : [], |
||
| 168 | ]], |
||
| 169 | 'request' => $this->getRequest($route, $mode), |
||
| 170 | 'response' => $this->addResponseExample ? [ |
||
| 171 | [ |
||
| 172 | 'name' => $route['title'] != '' ? $route['title'] : $this->getRouteUri($route), |
||
| 173 | 'originalRequest' => $this->getRequest($route, $mode), |
||
| 174 | 'status' => $route['response'][0]['statusText'], |
||
| 175 | 'code' => $route['response'][0]['status'], |
||
| 176 | '_postman_previewlanguage' => 'json', |
||
| 177 | 'header' => collect($route['response'][0]['headers'])->map(function ($header, $key) use ($route) { |
||
| 178 | return [ |
||
| 179 | 'key' => $key, |
||
| 180 | 'name' => $key, |
||
| 181 | 'type' => 'text', |
||
| 182 | 'value' => $header, |
||
| 183 | ]; |
||
| 184 | })->values()->toArray(), |
||
| 185 | 'body' => json_encode(json_decode($route['response'][0]['content']), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), |
||
| 186 | ], |
||
| 187 | ] : [], |
||
| 188 | ]; |
||
| 189 | })->toArray(), |
||
| 190 | ]; |
||
| 191 | })->values()->toArray(), |
||
| 192 | ]; |
||
| 193 | |||
| 194 | return json_encode($collection); |
||
| 195 | } |
||
| 196 | } |
||
| 197 |