@@ -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 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | private function getClassToBeTransformed(array $tags, ReflectionMethod $transformerMethod) |
69 | 69 | { |
70 | - $modelTag = array_first(array_filter($tags, function ($tag) { |
|
70 | + $modelTag = array_first(array_filter($tags, function($tag) { |
|
71 | 71 | return ($tag instanceof Tag) && strtolower($tag->getName()) == 'transformermodel'; |
72 | 72 | })); |
73 | 73 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $type = $modelTag->getContent(); |
77 | 77 | } else { |
78 | 78 | $parameter = array_first($transformerMethod->getParameters()); |
79 | - if ($parameter->hasType() && ! $parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) { |
|
79 | + if ($parameter->hasType() && !$parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) { |
|
80 | 80 | // ladies and gentlemen, we have a type! |
81 | 81 | $type = (string) $parameter->getType(); |
82 | 82 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | private function getTransformerTag(array $tags) |
122 | 122 | { |
123 | - $transFormerTags = array_filter($tags, function ($tag) { |
|
123 | + $transFormerTags = array_filter($tags, function($tag) { |
|
124 | 124 | return ($tag instanceof Tag) && in_array(strtolower($tag->getName()), ['transformer', 'transformercollection']); |
125 | 125 | }); |
126 | 126 |
@@ -63,7 +63,7 @@ |
||
63 | 63 | * @param Route $route |
64 | 64 | * @param array $bindings |
65 | 65 | * |
66 | - * @return mixed |
|
66 | + * @return string |
|
67 | 67 | */ |
68 | 68 | protected function replaceUrlParameterBindings(Route $route, $bindings) |
69 | 69 | { |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | public function __invoke(Route $route, array $tags, array $routeProps) |
16 | 16 | { |
17 | 17 | $rulesToApply = $routeProps['rules']['response_calls'] ?? []; |
18 | - if (! $this->shouldMakeApiCall($route, $rulesToApply)) { |
|
18 | + if (!$this->shouldMakeApiCall($route, $rulesToApply)) { |
|
19 | 19 | return; |
20 | 20 | } |
21 | 21 | |
@@ -124,14 +124,14 @@ discard block |
||
124 | 124 | // set URL and query parameters |
125 | 125 | $uri = $request->getRequestUri(); |
126 | 126 | $query = $request->getQueryString(); |
127 | - if (! empty($query)) { |
|
127 | + if (!empty($query)) { |
|
128 | 128 | $uri .= "?$query"; |
129 | 129 | } |
130 | 130 | $response = call_user_func_array([$dispatcher, strtolower($request->method())], [$uri]); |
131 | 131 | |
132 | 132 | // the response from the Dingo dispatcher is the 'raw' response from the controller, |
133 | 133 | // so we have to ensure it's JSON first |
134 | - if (! $response instanceof Response) { |
|
134 | + if (!$response instanceof Response) { |
|
135 | 135 | $response = response()->json($response); |
136 | 136 | } |
137 | 137 | |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | $prefix = 'HTTP_'; |
239 | 239 | foreach ($headers as $name => $value) { |
240 | 240 | $name = strtr(strtoupper($name), '-', '_'); |
241 | - if (! starts_with($name, $prefix) && $name !== 'CONTENT_TYPE') { |
|
242 | - $name = $prefix.$name; |
|
241 | + if (!starts_with($name, $prefix) && $name !== 'CONTENT_TYPE') { |
|
242 | + $name = $prefix . $name; |
|
243 | 243 | } |
244 | 244 | $server[$name] = $value; |
245 | 245 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | ]); |
56 | 56 | |
57 | 57 | $parsedRoute = [ |
58 | - 'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))), |
|
58 | + 'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))), |
|
59 | 59 | 'group' => $routeGroup, |
60 | 60 | 'title' => $docBlock['short'], |
61 | 61 | 'description' => $docBlock['long'], |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | 'queryParameters' => $queryParameters, |
66 | 66 | 'authenticated' => $this->getAuthStatusFromDocBlock($docBlock['tags']), |
67 | 67 | 'response' => $content, |
68 | - 'showresponse' => ! empty($content), |
|
68 | + 'showresponse' => !empty($content), |
|
69 | 69 | ]; |
70 | 70 | $parsedRoute['headers'] = $rulesToApply['headers'] ?? []; |
71 | 71 | |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | protected function getBodyParametersFromDocBlock(array $tags) |
81 | 81 | { |
82 | 82 | $parameters = collect($tags) |
83 | - ->filter(function ($tag) { |
|
83 | + ->filter(function($tag) { |
|
84 | 84 | return $tag instanceof Tag && $tag->getName() === 'bodyParam'; |
85 | 85 | }) |
86 | - ->mapWithKeys(function ($tag) { |
|
86 | + ->mapWithKeys(function($tag) { |
|
87 | 87 | preg_match('/(.+?)\s+(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content); |
88 | 88 | if (empty($content)) { |
89 | 89 | // this means only name and type were supplied |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | protected function getQueryParametersFromDocBlock(array $tags) |
118 | 118 | { |
119 | 119 | $parameters = collect($tags) |
120 | - ->filter(function ($tag) { |
|
120 | + ->filter(function($tag) { |
|
121 | 121 | return $tag instanceof Tag && $tag->getName() === 'queryParam'; |
122 | 122 | }) |
123 | - ->mapWithKeys(function ($tag) { |
|
123 | + ->mapWithKeys(function($tag) { |
|
124 | 124 | preg_match('/(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content); |
125 | 125 | if (empty($content)) { |
126 | 126 | // this means only name was supplied |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | protected function getAuthStatusFromDocBlock(array $tags) |
158 | 158 | { |
159 | 159 | $authTag = collect($tags) |
160 | - ->first(function ($tag) { |
|
160 | + ->first(function($tag) { |
|
161 | 161 | return $tag instanceof Tag && strtolower($tag->getName()) === 'authenticated'; |
162 | 162 | }); |
163 | 163 | |
@@ -228,25 +228,25 @@ discard block |
||
228 | 228 | { |
229 | 229 | $faker = Factory::create(); |
230 | 230 | $fakes = [ |
231 | - 'integer' => function () { |
|
231 | + 'integer' => function() { |
|
232 | 232 | return rand(1, 20); |
233 | 233 | }, |
234 | - 'number' => function () use ($faker) { |
|
234 | + 'number' => function() use ($faker) { |
|
235 | 235 | return $faker->randomFloat(); |
236 | 236 | }, |
237 | - 'float' => function () use ($faker) { |
|
237 | + 'float' => function() use ($faker) { |
|
238 | 238 | return $faker->randomFloat(); |
239 | 239 | }, |
240 | - 'boolean' => function () use ($faker) { |
|
240 | + 'boolean' => function() use ($faker) { |
|
241 | 241 | return $faker->boolean(); |
242 | 242 | }, |
243 | - 'string' => function () use ($faker) { |
|
243 | + 'string' => function() use ($faker) { |
|
244 | 244 | return str_random(); |
245 | 245 | }, |
246 | - 'array' => function () { |
|
246 | + 'array' => function() { |
|
247 | 247 | return '[]'; |
248 | 248 | }, |
249 | - 'object' => function () { |
|
249 | + 'object' => function() { |
|
250 | 250 | return '{}'; |
251 | 251 | }, |
252 | 252 | ]; |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @param Route $route |
16 | 16 | * |
17 | - * @return mixed |
|
17 | + * @return string |
|
18 | 18 | */ |
19 | 19 | public function getUri(Route $route) |
20 | 20 | { |
@@ -33,7 +33,6 @@ discard block |
||
33 | 33 | |
34 | 34 | /** |
35 | 35 | * @param \Illuminate\Routing\Route $route |
36 | - * @param array $apply Rules to apply when generating documentation for this route |
|
37 | 36 | * |
38 | 37 | * @return array |
39 | 38 | */ |
@@ -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' => app()->basePath().'/config/apidoc.php', |
|
25 | + __DIR__ . '/../config/apidoc.php' => app()->basePath() . '/config/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([ |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $generator = new Generator(); |
57 | 57 | $parsedRoutes = $this->processRoutes($generator, $routes); |
58 | 58 | $parsedRoutes = collect($parsedRoutes)->groupBy('group') |
59 | - ->sort(function ($a, $b) { |
|
59 | + ->sort(function($a, $b) { |
|
60 | 60 | return strcmp($a->first()['group'], $b->first()['group']); |
61 | 61 | }); |
62 | 62 | |
@@ -71,17 +71,17 @@ discard block |
||
71 | 71 | private function writeMarkdown($parsedRoutes) |
72 | 72 | { |
73 | 73 | $outputPath = config('apidoc.output'); |
74 | - $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
|
75 | - $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md'; |
|
76 | - $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md'; |
|
77 | - $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md'; |
|
74 | + $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md'; |
|
75 | + $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md'; |
|
76 | + $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md'; |
|
77 | + $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md'; |
|
78 | 78 | |
79 | 79 | $infoText = view('apidoc::partials.info') |
80 | 80 | ->with('outputPath', ltrim($outputPath, 'public/')) |
81 | 81 | ->with('showPostmanCollectionButton', config('apidoc.postman')); |
82 | 82 | |
83 | - $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) { |
|
84 | - return $routeGroup->map(function ($route) { |
|
83 | + $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) { |
|
84 | + return $routeGroup->map(function($route) { |
|
85 | 85 | $route['output'] = (string) view('apidoc::partials.route')->with('route', $route)->render(); |
86 | 86 | |
87 | 87 | return $route; |
@@ -101,16 +101,16 @@ discard block |
||
101 | 101 | $frontmatter = trim($generatedFrontmatter[1], "\n"); |
102 | 102 | } |
103 | 103 | |
104 | - $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
105 | - return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) { |
|
106 | - if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
107 | - $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
104 | + $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
105 | + return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) { |
|
106 | + if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
107 | + $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
108 | 108 | if ($routeDocumentationChanged === false || $this->option('force')) { |
109 | 109 | if ($routeDocumentationChanged) { |
110 | - $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
110 | + $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
111 | 111 | } |
112 | 112 | } else { |
113 | - $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
113 | + $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
114 | 114 | $route['modified_output'] = $existingRouteDoc[0]; |
115 | 115 | } |
116 | 116 | } |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | $prependFileContents = file_exists($prependFile) |
124 | - ? file_get_contents($prependFile)."\n" : ''; |
|
124 | + ? file_get_contents($prependFile) . "\n" : ''; |
|
125 | 125 | $appendFileContents = file_exists($appendFile) |
126 | - ? "\n".file_get_contents($appendFile) : ''; |
|
126 | + ? "\n" . file_get_contents($appendFile) : ''; |
|
127 | 127 | |
128 | 128 | $documentarian = new Documentarian(); |
129 | 129 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | ->with('showPostmanCollectionButton', config('apidoc.postman')) |
138 | 138 | ->with('parsedRoutes', $parsedRouteOutput); |
139 | 139 | |
140 | - if (! is_dir($outputPath)) { |
|
140 | + if (!is_dir($outputPath)) { |
|
141 | 141 | $documentarian->create($outputPath); |
142 | 142 | } |
143 | 143 | |
@@ -157,24 +157,24 @@ discard block |
||
157 | 157 | |
158 | 158 | file_put_contents($compareFile, $compareMarkdown); |
159 | 159 | |
160 | - $this->info('Wrote index.md to: '.$outputPath); |
|
160 | + $this->info('Wrote index.md to: ' . $outputPath); |
|
161 | 161 | |
162 | 162 | $this->info('Generating API HTML code'); |
163 | 163 | |
164 | 164 | $documentarian->generate($outputPath); |
165 | 165 | |
166 | - $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
166 | + $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
167 | 167 | |
168 | 168 | if (config('apidoc.postman')) { |
169 | 169 | $this->info('Generating Postman collection'); |
170 | 170 | |
171 | - file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
171 | + file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | if ($logo = config('apidoc.logo')) { |
175 | 175 | copy( |
176 | 176 | $logo, |
177 | - $outputPath.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'logo.png' |
|
177 | + $outputPath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.png' |
|
178 | 178 | ); |
179 | 179 | } |
180 | 180 | } |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | /** @var Route $route */ |
194 | 194 | if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) { |
195 | 195 | $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply']); |
196 | - $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
196 | + $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
197 | 197 | } else { |
198 | - $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
198 | + $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | private function isValidRoute(Route $route) |
211 | 211 | { |
212 | - return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']); |
|
212 | + return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $phpdoc = new DocBlock($comment); |
227 | 227 | |
228 | 228 | return collect($phpdoc->getTags()) |
229 | - ->filter(function ($tag) use ($route) { |
|
229 | + ->filter(function($tag) use ($route) { |
|
230 | 230 | return $tag->getName() === 'hideFromAPIDocumentation'; |
231 | 231 | }) |
232 | 232 | ->isEmpty(); |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | |
51 | 51 | private function getAllRoutes(bool $usingDingoRouter, array $versions = []) |
52 | 52 | { |
53 | - if (! $usingDingoRouter) { |
|
53 | + if (!$usingDingoRouter) { |
|
54 | 54 | return RouteFacade::getRoutes(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | $allRouteCollections = app(\Dingo\Api\Routing\Router::class)->getRoutes(); |
58 | 58 | |
59 | 59 | return collect($allRouteCollections) |
60 | - ->flatMap(function (RouteCollection $collection) { |
|
60 | + ->flatMap(function(RouteCollection $collection) { |
|
61 | 61 | return $collection->getRoutes(); |
62 | 62 | })->toArray(); |
63 | 63 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | private function shouldIncludeRoute(Route $route, array $routeRule, array $mustIncludes, bool $usingDingoRouter) |
66 | 66 | { |
67 | 67 | $matchesVersion = $usingDingoRouter |
68 | - ? ! empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? [])) |
|
68 | + ? !empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? [])) |
|
69 | 69 | : true; |
70 | 70 | |
71 | 71 | return str_is($mustIncludes, $route->getName()) |
@@ -48,8 +48,8 @@ |
||
48 | 48 | /** @var Response[]|null $response */ |
49 | 49 | $responses = $strategy($this->route, $tags, $routeProps); |
50 | 50 | |
51 | - if (! is_null($responses)) { |
|
52 | - return array_map(function (Response $response) { |
|
51 | + if (!is_null($responses)) { |
|
52 | + return array_map(function(Response $response) { |
|
53 | 53 | return ['status' => $response->getStatusCode(), 'content' => $this->getResponseContent($response)]; |
54 | 54 | }, $responses); |
55 | 55 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | protected function getDocBlockResponses(array $tags) |
34 | 34 | { |
35 | - $responseTags = array_filter($tags, function ($tag) { |
|
35 | + $responseTags = array_filter($tags, function($tag) { |
|
36 | 36 | return $tag instanceof Tag && strtolower($tag->getName()) === 'response'; |
37 | 37 | }); |
38 | 38 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | return; |
41 | 41 | } |
42 | 42 | |
43 | - return array_map(function (Tag $responseTag) { |
|
43 | + return array_map(function(Tag $responseTag) { |
|
44 | 44 | preg_match('/^(\d{3})?\s?([\s\S]*)$/', $responseTag->getContent(), $result); |
45 | 45 | |
46 | 46 | $status = $result[1] ?: 200; |