| Conditions | 7 |
| Paths | 8 |
| Total Lines | 64 |
| 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 |
||
| 33 | public function getCollection() |
||
| 34 | { |
||
| 35 | URL::forceRootUrl($this->baseUrl); |
||
| 36 | if (Str::startsWith($this->baseUrl, 'https://')) { |
||
| 37 | URL::forceScheme('https'); |
||
| 38 | } |
||
| 39 | |||
| 40 | $collection = [ |
||
| 41 | 'variables' => [], |
||
| 42 | 'info' => [ |
||
| 43 | 'name' => config('apidoc.postman.name') ?: config('app.name').' API', |
||
| 44 | '_postman_id' => Uuid::uuid4()->toString(), |
||
| 45 | 'description' => config('apidoc.postman.description') ?: '', |
||
| 46 | 'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json', |
||
| 47 | ], |
||
| 48 | 'item' => $this->routeGroups->map(function ($routes, $groupName) { |
||
| 49 | return [ |
||
| 50 | 'name' => $groupName, |
||
| 51 | 'description' => '', |
||
| 52 | 'item' => $routes->map(function ($route) { |
||
| 53 | $mode = $route['methods'][0] === 'PUT' ? 'urlencoded' : 'formdata'; |
||
| 54 | |||
| 55 | return [ |
||
| 56 | 'name' => $route['metadata']['title'] != '' ? $route['metadata']['title'] : url($route['uri']), |
||
| 57 | 'request' => [ |
||
| 58 | 'url' => url($route['uri']).(collect($route['queryParameters'])->isEmpty() |
||
| 59 | ? '' |
||
| 60 | : ('?'.implode('&', collect($route['queryParameters'])->map(function ($parameter, $key) { |
||
| 61 | return urlencode($key).'='.urlencode($parameter['value'] ?? ''); |
||
| 62 | })->all()))), |
||
| 63 | 'method' => $route['methods'][0], |
||
| 64 | 'header' => collect($route['headers']) |
||
| 65 | ->union([ |
||
| 66 | 'Accept' => 'application/json', |
||
| 67 | ]) |
||
| 68 | ->map(function ($value, $header) { |
||
| 69 | return [ |
||
| 70 | 'key' => $header, |
||
| 71 | 'value' => $value, |
||
| 72 | ]; |
||
| 73 | }) |
||
| 74 | ->values()->all(), |
||
| 75 | 'body' => [ |
||
| 76 | 'mode' => $mode, |
||
| 77 | $mode => collect($route['bodyParameters'])->map(function ($parameter, $key) { |
||
| 78 | return [ |
||
| 79 | 'key' => $key, |
||
| 80 | 'value' => $parameter['value'] ?? '', |
||
| 81 | 'type' => 'text', |
||
| 82 | 'enabled' => true, |
||
| 83 | ]; |
||
| 84 | })->values()->toArray(), |
||
| 85 | ], |
||
| 86 | 'description' => $route['metadata']['description'], |
||
| 87 | 'response' => [], |
||
| 88 | ], |
||
| 89 | ]; |
||
| 90 | })->toArray(), |
||
| 91 | ]; |
||
| 92 | })->values()->toArray(), |
||
| 93 | ]; |
||
| 94 | |||
| 95 | return json_encode($collection); |
||
| 96 | } |
||
| 97 | } |
||
| 98 |