@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | 'description' => '', |
33 | 33 | 'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json', |
34 | 34 | ], |
35 | - 'item' => $this->routeGroups->map(function ($routes, $groupName) { |
|
35 | + 'item' => $this->routeGroups->map(function($routes, $groupName) { |
|
36 | 36 | return [ |
37 | 37 | 'name' => $groupName, |
38 | 38 | 'description' => '', |
39 | - 'item' => $routes->map(function ($route) { |
|
39 | + 'item' => $routes->map(function($route) { |
|
40 | 40 | return [ |
41 | 41 | 'name' => $route['title'] != '' ? $route['title'] : url($route['uri']), |
42 | 42 | 'request' => [ |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | 'method' => $route['methods'][0], |
45 | 45 | 'body' => [ |
46 | 46 | 'mode' => 'formdata', |
47 | - 'formdata' => collect($route['parameters'])->map(function ($parameter, $key) { |
|
47 | + 'formdata' => collect($route['parameters'])->map(function($parameter, $key) { |
|
48 | 48 | return [ |
49 | 49 | 'key' => $key, |
50 | 50 | 'value' => isset($parameter['value']) ? $parameter['value'] : '', |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | |
49 | 49 | private function getAllRoutes(bool $usingDingoRouter, array $versions = []) |
50 | 50 | { |
51 | - if (! $usingDingoRouter) { |
|
51 | + if (!$usingDingoRouter) { |
|
52 | 52 | return RouteFacade::getRoutes(); |
53 | 53 | } |
54 | 54 | |
55 | 55 | $allRouteCollections = app(\Dingo\Api\Routing\Router::class)->getRoutes(); |
56 | 56 | |
57 | 57 | return collect($allRouteCollections) |
58 | - ->flatMap(function (RouteCollection $collection) { |
|
58 | + ->flatMap(function(RouteCollection $collection) { |
|
59 | 59 | return $collection->getRoutes(); |
60 | 60 | })->toArray(); |
61 | 61 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | private function shouldIncludeRoute(Route $route, array $routeRule, array $mustIncludes, bool $usingDingoRouter) |
64 | 64 | { |
65 | 65 | $matchesVersion = $usingDingoRouter |
66 | - ? ! empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? [])) |
|
66 | + ? !empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? [])) |
|
67 | 67 | : true; |
68 | 68 | |
69 | 69 | return in_array($route->getName(), $mustIncludes) |
@@ -15,17 +15,17 @@ |
||
15 | 15 | */ |
16 | 16 | public function boot() |
17 | 17 | { |
18 | - $this->loadViewsFrom(__DIR__.'/../resources/views/', 'apidoc'); |
|
18 | + $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'apidoc'); |
|
19 | 19 | |
20 | 20 | $this->publishes([ |
21 | - __DIR__.'/../resources/views' => app()->basePath().'/resources/views/vendor/apidoc', |
|
21 | + __DIR__ . '/../resources/views' => app()->basePath() . '/resources/views/vendor/apidoc', |
|
22 | 22 | ], 'views'); |
23 | 23 | |
24 | 24 | $this->publishes([ |
25 | - __DIR__.'/../config/apidoc.php' => config_path('apidoc.php'), |
|
25 | + __DIR__ . '/../config/apidoc.php' => config_path('apidoc.php'), |
|
26 | 26 | ], 'config'); |
27 | 27 | |
28 | - $this->mergeConfigFrom(__DIR__.'/../config/apidoc.php', 'apidoc'); |
|
28 | + $this->mergeConfigFrom(__DIR__ . '/../config/apidoc.php', 'apidoc'); |
|
29 | 29 | |
30 | 30 | if ($this->app->runningInConsole()) { |
31 | 31 | $this->commands([ |
@@ -42,15 +42,15 @@ |
||
42 | 42 | |
43 | 43 | $documentarian = new Documentarian(); |
44 | 44 | |
45 | - if (! is_dir($outputPath)) { |
|
46 | - $this->error('There is no existing documentation available at '.$outputPath.'.'); |
|
45 | + if (!is_dir($outputPath)) { |
|
46 | + $this->error('There is no existing documentation available at ' . $outputPath . '.'); |
|
47 | 47 | |
48 | 48 | return false; |
49 | 49 | } |
50 | - $this->info('Rebuilding API HTML code from '.$outputPath.'/source/index.md'); |
|
50 | + $this->info('Rebuilding API HTML code from ' . $outputPath . '/source/index.md'); |
|
51 | 51 | |
52 | 52 | $documentarian->generate($outputPath); |
53 | 53 | |
54 | - $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
54 | + $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
55 | 55 | } |
56 | 56 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | */ |
25 | 25 | protected function getDocBlockResponse(array $tags) |
26 | 26 | { |
27 | - $responseTags = array_filter($tags, function ($tag) { |
|
27 | + $responseTags = array_filter($tags, function($tag) { |
|
28 | 28 | return $tag instanceof Tag && strtolower($tag->getName()) == 'response'; |
29 | 29 | }); |
30 | 30 | if (empty($responseTags)) { |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $content = ResponseResolver::getResponse($route, $docBlock['tags'], $rulesToApply); |
61 | 61 | |
62 | 62 | $parsedRoute = [ |
63 | - 'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))), |
|
63 | + 'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))), |
|
64 | 64 | 'group' => $routeGroup, |
65 | 65 | 'title' => $docBlock['short'], |
66 | 66 | 'description' => $docBlock['long'], |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | 'parameters' => $this->getParametersFromDocBlock($docBlock['tags']), |
70 | 70 | 'authenticated' => $this->getAuthStatusFromDocBlock($docBlock['tags']), |
71 | 71 | 'response' => $content, |
72 | - 'showresponse' => ! empty($content), |
|
72 | + 'showresponse' => !empty($content), |
|
73 | 73 | ]; |
74 | 74 | $parsedRoute['headers'] = $rulesToApply['headers'] ?? []; |
75 | 75 | |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | protected function getParametersFromDocBlock(array $tags) |
94 | 94 | { |
95 | 95 | $parameters = collect($tags) |
96 | - ->filter(function ($tag) { |
|
96 | + ->filter(function($tag) { |
|
97 | 97 | return $tag instanceof Tag && $tag->getName() === 'bodyParam'; |
98 | 98 | }) |
99 | - ->mapWithKeys(function ($tag) { |
|
99 | + ->mapWithKeys(function($tag) { |
|
100 | 100 | preg_match('/(.+?)\s+(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content); |
101 | 101 | if (empty($content)) { |
102 | 102 | // this means only name and type were supplied |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | protected function getAuthStatusFromDocBlock(array $tags) |
131 | 131 | { |
132 | 132 | $authTag = collect($tags) |
133 | - ->first(function ($tag) { |
|
133 | + ->first(function($tag) { |
|
134 | 134 | return $tag instanceof Tag && strtolower($tag->getName()) === 'authenticated'; |
135 | 135 | }); |
136 | 136 | |
@@ -202,25 +202,25 @@ discard block |
||
202 | 202 | { |
203 | 203 | $faker = Factory::create(); |
204 | 204 | $fakes = [ |
205 | - 'integer' => function () { |
|
205 | + 'integer' => function() { |
|
206 | 206 | return rand(1, 20); |
207 | 207 | }, |
208 | - 'number' => function () use ($faker) { |
|
208 | + 'number' => function() use ($faker) { |
|
209 | 209 | return $faker->randomFloat(); |
210 | 210 | }, |
211 | - 'float' => function () use ($faker) { |
|
211 | + 'float' => function() use ($faker) { |
|
212 | 212 | return $faker->randomFloat(); |
213 | 213 | }, |
214 | - 'boolean' => function () use ($faker) { |
|
214 | + 'boolean' => function() use ($faker) { |
|
215 | 215 | return $faker->boolean(); |
216 | 216 | }, |
217 | - 'string' => function () use ($faker) { |
|
217 | + 'string' => function() use ($faker) { |
|
218 | 218 | return str_random(); |
219 | 219 | }, |
220 | - 'array' => function () { |
|
220 | + 'array' => function() { |
|
221 | 221 | return '[]'; |
222 | 222 | }, |
223 | - 'object' => function () { |
|
223 | + 'object' => function() { |
|
224 | 224 | return '{}'; |
225 | 225 | }, |
226 | 226 | ]; |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $generator = new Generator(); |
56 | 56 | $parsedRoutes = $this->processRoutes($generator, $routes); |
57 | 57 | $parsedRoutes = collect($parsedRoutes)->groupBy('group') |
58 | - ->sort(function ($a, $b) { |
|
58 | + ->sort(function($a, $b) { |
|
59 | 59 | return strcmp($a->first()['group'], $b->first()['group']); |
60 | 60 | }); |
61 | 61 | |
@@ -70,17 +70,17 @@ discard block |
||
70 | 70 | private function writeMarkdown($parsedRoutes) |
71 | 71 | { |
72 | 72 | $outputPath = config('apidoc.output'); |
73 | - $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
|
74 | - $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md'; |
|
75 | - $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md'; |
|
76 | - $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md'; |
|
73 | + $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md'; |
|
74 | + $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md'; |
|
75 | + $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md'; |
|
76 | + $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md'; |
|
77 | 77 | |
78 | 78 | $infoText = view('apidoc::partials.info') |
79 | 79 | ->with('outputPath', ltrim($outputPath, 'public/')) |
80 | 80 | ->with('showPostmanCollectionButton', config('apidoc.postman')); |
81 | 81 | |
82 | - $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) { |
|
83 | - return $routeGroup->map(function ($route) { |
|
82 | + $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) { |
|
83 | + return $routeGroup->map(function($route) { |
|
84 | 84 | $route['output'] = (string) view('apidoc::partials.route')->with('route', $route)->render(); |
85 | 85 | |
86 | 86 | return $route; |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | $frontmatter = trim($generatedFrontmatter[1], "\n"); |
101 | 101 | } |
102 | 102 | |
103 | - $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
104 | - return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) { |
|
105 | - if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
106 | - $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
103 | + $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
104 | + return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) { |
|
105 | + if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
106 | + $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
107 | 107 | if ($routeDocumentationChanged === false || $this->option('force')) { |
108 | 108 | if ($routeDocumentationChanged) { |
109 | - $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
109 | + $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
110 | 110 | } |
111 | 111 | } else { |
112 | - $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
112 | + $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
113 | 113 | $route['modified_output'] = $existingRouteDoc[0]; |
114 | 114 | } |
115 | 115 | } |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | } |
121 | 121 | |
122 | 122 | $prependFileContents = file_exists($prependFile) |
123 | - ? file_get_contents($prependFile)."\n" : ''; |
|
123 | + ? file_get_contents($prependFile) . "\n" : ''; |
|
124 | 124 | $appendFileContents = file_exists($appendFile) |
125 | - ? "\n".file_get_contents($appendFile) : ''; |
|
125 | + ? "\n" . file_get_contents($appendFile) : ''; |
|
126 | 126 | |
127 | 127 | $documentarian = new Documentarian(); |
128 | 128 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | ->with('showPostmanCollectionButton', config('apidoc.postman')) |
137 | 137 | ->with('parsedRoutes', $parsedRouteOutput); |
138 | 138 | |
139 | - if (! is_dir($outputPath)) { |
|
139 | + if (!is_dir($outputPath)) { |
|
140 | 140 | $documentarian->create($outputPath); |
141 | 141 | } |
142 | 142 | |
@@ -156,18 +156,18 @@ discard block |
||
156 | 156 | |
157 | 157 | file_put_contents($compareFile, $compareMarkdown); |
158 | 158 | |
159 | - $this->info('Wrote index.md to: '.$outputPath); |
|
159 | + $this->info('Wrote index.md to: ' . $outputPath); |
|
160 | 160 | |
161 | 161 | $this->info('Generating API HTML code'); |
162 | 162 | |
163 | 163 | $documentarian->generate($outputPath); |
164 | 164 | |
165 | - $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
165 | + $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
166 | 166 | |
167 | 167 | if (config('apidoc.postman')) { |
168 | 168 | $this->info('Generating Postman collection'); |
169 | 169 | |
170 | - file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
170 | + file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | /** @var Route $route */ |
186 | 186 | if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) { |
187 | 187 | $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply']); |
188 | - $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
188 | + $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
189 | 189 | } else { |
190 | - $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
190 | + $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | private function isValidRoute(Route $route) |
203 | 203 | { |
204 | - return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']); |
|
204 | + return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $phpdoc = new DocBlock($comment); |
219 | 219 | |
220 | 220 | return collect($phpdoc->getTags()) |
221 | - ->filter(function ($tag) use ($route) { |
|
221 | + ->filter(function($tag) use ($route) { |
|
222 | 222 | return $tag->getName() === 'hideFromAPIDocumentation'; |
223 | 223 | }) |
224 | 224 | ->isEmpty(); |
@@ -31,7 +31,7 @@ |
||
31 | 31 | foreach (static::$strategies as $strategy) { |
32 | 32 | $strategy = new $strategy(); |
33 | 33 | $response = $strategy($this->route, $tags, $rulesToApply); |
34 | - if (! is_null($response)) { |
|
34 | + if (!is_null($response)) { |
|
35 | 35 | return $this->getResponseContent($response); |
36 | 36 | } |
37 | 37 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | public function __invoke(Route $route, array $tags, array $rulesToApply) |
16 | 16 | { |
17 | 17 | $rulesToApply = $rulesToApply['response_calls'] ?? []; |
18 | - if (! $this->shouldMakeApiCall($route, $rulesToApply)) { |
|
18 | + if (!$this->shouldMakeApiCall($route, $rulesToApply)) { |
|
19 | 19 | return; |
20 | 20 | } |
21 | 21 | |
@@ -119,14 +119,14 @@ discard block |
||
119 | 119 | // set URL and query parameters |
120 | 120 | $uri = $request->getRequestUri(); |
121 | 121 | $query = $request->getQueryString(); |
122 | - if (! empty($query)) { |
|
122 | + if (!empty($query)) { |
|
123 | 123 | $uri .= "?$query"; |
124 | 124 | } |
125 | 125 | $response = call_user_func_array([$dispatcher, strtolower($request->method())], [$uri]); |
126 | 126 | |
127 | 127 | // the response from the Dingo dispatcher is the 'raw' response from the controller, |
128 | 128 | // so we have to ensure it's JSON first |
129 | - if (! $response instanceof Response) { |
|
129 | + if (!$response instanceof Response) { |
|
130 | 130 | $response = response()->json($response); |
131 | 131 | } |
132 | 132 | |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | $prefix = 'HTTP_'; |
234 | 234 | foreach ($headers as $name => $value) { |
235 | 235 | $name = strtr(strtoupper($name), '-', '_'); |
236 | - if (! starts_with($name, $prefix) && $name !== 'CONTENT_TYPE') { |
|
237 | - $name = $prefix.$name; |
|
236 | + if (!starts_with($name, $prefix) && $name !== 'CONTENT_TYPE') { |
|
237 | + $name = $prefix . $name; |
|
238 | 238 | } |
239 | 239 | $server[$name] = $value; |
240 | 240 | } |