@@ -49,7 +49,7 @@ |
||
49 | 49 | * @param string $uri |
50 | 50 | * @param array $bindings |
51 | 51 | * |
52 | - * @return mixed |
|
52 | + * @return string |
|
53 | 53 | */ |
54 | 54 | public static function replaceUrlParameterBindings(string $uri, array $bindings) |
55 | 55 | { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | protected function getAuthStatusFromDocBlock(array $tags) |
38 | 38 | { |
39 | 39 | $authTag = collect($tags) |
40 | - ->first(function ($tag) { |
|
40 | + ->first(function($tag) { |
|
41 | 41 | return $tag instanceof Tag && strtolower($tag->getName()) === 'authenticated'; |
42 | 42 | }); |
43 | 43 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | protected function getRouteGroupDescriptionAndTitle(DocBlock $methodDocBlock, DocBlock $controllerDocBlock) |
54 | 54 | { |
55 | 55 | // @group tag on the method overrides that on the controller |
56 | - if (! empty($methodDocBlock->getTags())) { |
|
56 | + if (!empty($methodDocBlock->getTags())) { |
|
57 | 57 | foreach ($methodDocBlock->getTags() as $tag) { |
58 | 58 | if ($tag->getName() === 'group') { |
59 | 59 | $routeGroupParts = explode("\n", trim($tag->getContent())); |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | private function getQueryParametersFromDocBlock($tags) |
56 | 56 | { |
57 | 57 | $parameters = collect($tags) |
58 | - ->filter(function ($tag) { |
|
58 | + ->filter(function($tag) { |
|
59 | 59 | return $tag instanceof Tag && $tag->getName() === 'queryParam'; |
60 | 60 | }) |
61 | - ->mapWithKeys(function ($tag) { |
|
61 | + ->mapWithKeys(function($tag) { |
|
62 | 62 | preg_match('/(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content); |
63 | 63 | $content = preg_replace('/\s?No-example.?/', '', $content); |
64 | 64 | if (empty($content)) { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | list($description, $value) = $this->parseParamDescription($description, 'string'); |
80 | - if (is_null($value) && ! $this->shouldExcludeExample($tag)) { |
|
80 | + if (is_null($value) && !$this->shouldExcludeExample($tag)) { |
|
81 | 81 | $value = str_contains($description, ['number', 'count', 'page']) |
82 | 82 | ? $this->generateDummyValue('integer') |
83 | 83 | : $this->generateDummyValue('string'); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | protected function getDocBlockResponses(array $tags) |
44 | 44 | { |
45 | 45 | $responseTags = array_values( |
46 | - array_filter($tags, function ($tag) { |
|
46 | + array_filter($tags, function($tag) { |
|
47 | 47 | return $tag instanceof Tag && strtolower($tag->getName()) === 'response'; |
48 | 48 | }) |
49 | 49 | ); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | return null; |
53 | 53 | } |
54 | 54 | |
55 | - $responses = array_map(function (Tag $responseTag) { |
|
55 | + $responses = array_map(function(Tag $responseTag) { |
|
56 | 56 | preg_match('/^(\d{3})?\s?([\s\S]*)$/', $responseTag->getContent(), $result); |
57 | 57 | |
58 | 58 | $status = $result[1] ?: 200; |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | public function __invoke(Route $route, \ReflectionClass $controller, \ReflectionMethod $method, array $routeRules, array $context = []) |
31 | 31 | { |
32 | 32 | $rulesToApply = $routeRules['response_calls'] ?? []; |
33 | - if (! $this->shouldMakeApiCall($route, $rulesToApply, $context)) { |
|
33 | + if (!$this->shouldMakeApiCall($route, $rulesToApply, $context)) { |
|
34 | 34 | return null; |
35 | 35 | } |
36 | 36 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | try { |
45 | 45 | $response = [200 => $this->makeApiCall($request)->getContent()]; |
46 | 46 | } catch (\Exception $e) { |
47 | - echo 'Exception thrown during response call for ['.implode(',', $route->methods)."] {$route->uri}.\n"; |
|
47 | + echo 'Exception thrown during response call for [' . implode(',', $route->methods) . "] {$route->uri}.\n"; |
|
48 | 48 | if (Flags::$shouldBeVerbose) { |
49 | 49 | Utils::dumpException($e); |
50 | 50 | } else { |
@@ -177,14 +177,14 @@ discard block |
||
177 | 177 | // set URL and query parameters |
178 | 178 | $uri = $request->getRequestUri(); |
179 | 179 | $query = $request->getQueryString(); |
180 | - if (! empty($query)) { |
|
180 | + if (!empty($query)) { |
|
181 | 181 | $uri .= "?$query"; |
182 | 182 | } |
183 | 183 | $response = call_user_func_array([$dispatcher, strtolower($request->method())], [$uri]); |
184 | 184 | |
185 | 185 | // the response from the Dingo dispatcher is the 'raw' response from the controller, |
186 | 186 | // so we have to ensure it's JSON first |
187 | - if (! $response instanceof Response) { |
|
187 | + if (!$response instanceof Response) { |
|
188 | 188 | $response = response()->json($response); |
189 | 189 | } |
190 | 190 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | return false; |
305 | 305 | } |
306 | 306 | |
307 | - if (! empty($context['responses'])) { |
|
307 | + if (!empty($context['responses'])) { |
|
308 | 308 | // Don't attempt a response call if there are already responses |
309 | 309 | return false; |
310 | 310 | } |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | $prefix = 'HTTP_'; |
339 | 339 | foreach ($headers as $name => $value) { |
340 | 340 | $name = strtr(strtoupper($name), '-', '_'); |
341 | - if (! starts_with($name, $prefix) && $name !== 'CONTENT_TYPE') { |
|
342 | - $name = $prefix.$name; |
|
341 | + if (!starts_with($name, $prefix) && $name !== 'CONTENT_TYPE') { |
|
342 | + $name = $prefix . $name; |
|
343 | 343 | } |
344 | 344 | $server[$name] = $value; |
345 | 345 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | // Avoid "holes" in the keys of the filtered array, by using array_values on the filtered array |
46 | 46 | $responseFileTags = array_values( |
47 | - array_filter($tags, function ($tag) { |
|
47 | + array_filter($tags, function($tag) { |
|
48 | 48 | return $tag instanceof Tag && strtolower($tag->getName()) === 'responsefile'; |
49 | 49 | }) |
50 | 50 | ); |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | return null; |
54 | 54 | } |
55 | 55 | |
56 | - $responses = array_map(function (Tag $responseFileTag) { |
|
56 | + $responses = array_map(function(Tag $responseFileTag) { |
|
57 | 57 | preg_match('/^(\d{3})?\s?([\S]*[\s]*?)(\{.*\})?$/', $responseFileTag->getContent(), $result); |
58 | 58 | $status = $result[1] ?: 200; |
59 | 59 | $content = $result[2] ? file_get_contents(storage_path(trim($result[2])), true) : '{}'; |
60 | - $json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}'; |
|
60 | + $json = !empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}'; |
|
61 | 61 | $merged = array_merge(json_decode($content, true), json_decode($json, true)); |
62 | 62 | |
63 | 63 | return [json_encode($merged), (int) $status]; |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | private function getBodyParametersFromDocBlock($tags) |
56 | 56 | { |
57 | 57 | $parameters = collect($tags) |
58 | - ->filter(function ($tag) { |
|
58 | + ->filter(function($tag) { |
|
59 | 59 | return $tag instanceof Tag && $tag->getName() === 'bodyParam'; |
60 | 60 | }) |
61 | - ->mapWithKeys(function ($tag) { |
|
61 | + ->mapWithKeys(function($tag) { |
|
62 | 62 | preg_match('/(.+?)\s+(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content); |
63 | 63 | $content = preg_replace('/\s?No-example.?/', '', $content); |
64 | 64 | if (empty($content)) { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $type = $this->normalizeParameterType($type); |
80 | 80 | list($description, $example) = $this->parseParamDescription($description, $type); |
81 | - $value = is_null($example) && ! $this->shouldExcludeExample($tag) ? $this->generateDummyValue($type) : $example; |
|
81 | + $value = is_null($example) && !$this->shouldExcludeExample($tag) ? $this->generateDummyValue($type) : $example; |
|
82 | 82 | |
83 | 83 | return [$name => compact('type', 'description', 'required', 'value')]; |
84 | 84 | })->toArray(); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $parsedRoutes = $this->processRoutes($generator, $routes); |
85 | 85 | $groupedRoutes = collect($parsedRoutes) |
86 | 86 | ->groupBy('groupName') |
87 | - ->sortBy(static function ($group) { |
|
87 | + ->sortBy(static function($group) { |
|
88 | 88 | /* @var $group Collection */ |
89 | 89 | return $group->first()['groupName']; |
90 | 90 | }, SORT_NATURAL); |
@@ -100,19 +100,19 @@ discard block |
||
100 | 100 | private function writeMarkdown($parsedRoutes) |
101 | 101 | { |
102 | 102 | $outputPath = $this->docConfig->get('output'); |
103 | - $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
|
104 | - $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md'; |
|
105 | - $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md'; |
|
106 | - $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md'; |
|
103 | + $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md'; |
|
104 | + $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md'; |
|
105 | + $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md'; |
|
106 | + $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md'; |
|
107 | 107 | |
108 | 108 | $infoText = view('apidoc::partials.info') |
109 | 109 | ->with('outputPath', ltrim($outputPath, 'public/')) |
110 | 110 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection()); |
111 | 111 | |
112 | 112 | $settings = ['languages' => $this->docConfig->get('example_languages')]; |
113 | - $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) use ($settings) { |
|
114 | - return $routeGroup->map(function ($route) use ($settings) { |
|
115 | - if (count($route['cleanBodyParameters']) && ! isset($route['headers']['Content-Type'])) { |
|
113 | + $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) use ($settings) { |
|
114 | + return $routeGroup->map(function($route) use ($settings) { |
|
115 | + if (count($route['cleanBodyParameters']) && !isset($route['headers']['Content-Type'])) { |
|
116 | 116 | $route['headers']['Content-Type'] = 'application/json'; |
117 | 117 | } |
118 | 118 | $route['output'] = (string) view('apidoc::partials.route') |
@@ -139,16 +139,16 @@ discard block |
||
139 | 139 | $frontmatter = trim($generatedFrontmatter[1], "\n"); |
140 | 140 | } |
141 | 141 | |
142 | - $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
143 | - return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) { |
|
144 | - if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
145 | - $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
142 | + $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
143 | + return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) { |
|
144 | + if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
145 | + $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
146 | 146 | if ($routeDocumentationChanged === false || $this->option('force')) { |
147 | 147 | if ($routeDocumentationChanged) { |
148 | - $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
148 | + $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
149 | 149 | } |
150 | 150 | } else { |
151 | - $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
151 | + $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
152 | 152 | $route['modified_output'] = $existingRouteDoc[0]; |
153 | 153 | } |
154 | 154 | } |
@@ -159,9 +159,9 @@ discard block |
||
159 | 159 | } |
160 | 160 | |
161 | 161 | $prependFileContents = file_exists($prependFile) |
162 | - ? file_get_contents($prependFile)."\n" : ''; |
|
162 | + ? file_get_contents($prependFile) . "\n" : ''; |
|
163 | 163 | $appendFileContents = file_exists($appendFile) |
164 | - ? "\n".file_get_contents($appendFile) : ''; |
|
164 | + ? "\n" . file_get_contents($appendFile) : ''; |
|
165 | 165 | |
166 | 166 | $documentarian = new Documentarian(); |
167 | 167 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection()) |
176 | 176 | ->with('parsedRoutes', $parsedRouteOutput); |
177 | 177 | |
178 | - if (! is_dir($outputPath)) { |
|
178 | + if (!is_dir($outputPath)) { |
|
179 | 179 | $documentarian->create($outputPath); |
180 | 180 | } |
181 | 181 | |
@@ -195,24 +195,24 @@ discard block |
||
195 | 195 | |
196 | 196 | file_put_contents($compareFile, $compareMarkdown); |
197 | 197 | |
198 | - $this->info('Wrote index.md to: '.$outputPath); |
|
198 | + $this->info('Wrote index.md to: ' . $outputPath); |
|
199 | 199 | |
200 | 200 | $this->info('Generating API HTML code'); |
201 | 201 | |
202 | 202 | $documentarian->generate($outputPath); |
203 | 203 | |
204 | - $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
204 | + $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
205 | 205 | |
206 | 206 | if ($this->shouldGeneratePostmanCollection()) { |
207 | 207 | $this->info('Generating Postman collection'); |
208 | 208 | |
209 | - file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
209 | + file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | if ($logo = $this->docConfig->get('logo')) { |
213 | 213 | copy( |
214 | 214 | $logo, |
215 | - $outputPath.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'logo.png' |
|
215 | + $outputPath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.png' |
|
216 | 216 | ); |
217 | 217 | } |
218 | 218 | } |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | /** @var Route $route */ |
232 | 232 | if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction())) { |
233 | 233 | $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply']); |
234 | - $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
234 | + $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
235 | 235 | } else { |
236 | - $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
236 | + $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | $action = implode('@', $action); |
253 | 253 | } |
254 | 254 | |
255 | - return ! is_callable($action) && ! is_null($action); |
|
255 | + return !is_callable($action) && !is_null($action); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | list($class, $method) = Utils::getRouteClassAndMethodNames($action); |
268 | 268 | $reflection = new ReflectionClass($class); |
269 | 269 | |
270 | - if (! $reflection->hasMethod($method)) { |
|
270 | + if (!$reflection->hasMethod($method)) { |
|
271 | 271 | return false; |
272 | 272 | } |
273 | 273 | |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | $phpdoc = new DocBlock($comment); |
278 | 278 | |
279 | 279 | return collect($phpdoc->getTags()) |
280 | - ->filter(function ($tag) { |
|
280 | + ->filter(function($tag) { |
|
281 | 281 | return $tag->getName() === 'hideFromAPIDocumentation'; |
282 | 282 | }) |
283 | 283 | ->isEmpty(); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $method = $controller->getMethod($methodName); |
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 | 'methods' => $this->getMethods($route), |
60 | 60 | 'uri' => $this->getUri($route), |
61 | 61 | 'boundUri' => Utils::getFullUrl($route, $rulesToApply['bindings'] ?? ($rulesToApply['response_calls']['bindings'] ?? [])), |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | $responses = $this->fetchResponses($controller, $method, $route, $rulesToApply, $parsedRoute); |
74 | 74 | $parsedRoute['response'] = $responses; |
75 | - $parsedRoute['showresponse'] = ! empty($responses); |
|
75 | + $parsedRoute['showresponse'] = !empty($responses); |
|
76 | 76 | |
77 | 77 | $parsedRoute['headers'] = $rulesToApply['headers'] ?? []; |
78 | 78 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | { |
111 | 111 | $responses = $this->iterateThroughStrategies('responses', $context, [$route, $controller, $method, $rulesToApply]); |
112 | 112 | if (count($responses)) { |
113 | - return collect($responses)->map(function (string $response, int $status) { |
|
113 | + return collect($responses)->map(function(string $response, int $status) { |
|
114 | 114 | return [ |
115 | 115 | 'status' => $status ?: 200, |
116 | 116 | 'content' => $response, |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | $strategy = new $strategyClass($this->config); |
130 | 130 | $arguments[] = $context; |
131 | 131 | $results = $strategy(...$arguments); |
132 | - if (! is_null($results)) { |
|
132 | + if (!is_null($results)) { |
|
133 | 133 | foreach ($results as $index => $item) { |
134 | 134 | // Using a for loop rather than array_merge or += |
135 | 135 | // so it does not renumber numeric keys |
136 | 136 | // and also allows values to be overwritten |
137 | 137 | |
138 | 138 | // Don't allow overwriting if an empty value is trying to replace a set one |
139 | - if (! in_array($context[$key], [null, ''], true) && in_array($item, [null, ''], true)) { |
|
139 | + if (!in_array($context[$key], [null, ''], true) && in_array($item, [null, ''], true)) { |
|
140 | 140 | continue; |
141 | 141 | } else { |
142 | 142 | $context[$key][$index] = $item; |