@@ -11,6 +11,10 @@ |
||
11 | 11 | $this->data = $config; |
12 | 12 | } |
13 | 13 | |
14 | + /** |
|
15 | + * @param string $key |
|
16 | + * @param boolean $default |
|
17 | + */ |
|
14 | 18 | public function get($key, $default = null) |
15 | 19 | { |
16 | 20 | return data_get($this->data, $key, $default); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $generator = new Generator($this->docConfig); |
74 | 74 | $parsedRoutes = $this->processRoutes($generator, $routes); |
75 | 75 | $parsedRoutes = collect($parsedRoutes)->groupBy('group') |
76 | - ->sortBy(static function ($group) { |
|
76 | + ->sortBy(static function($group) { |
|
77 | 77 | /* @var $group Collection */ |
78 | 78 | return $group->first()['group']; |
79 | 79 | }, SORT_NATURAL); |
@@ -89,19 +89,19 @@ discard block |
||
89 | 89 | private function writeMarkdown($parsedRoutes) |
90 | 90 | { |
91 | 91 | $outputPath = $this->docConfig->get('output'); |
92 | - $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
|
93 | - $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md'; |
|
94 | - $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md'; |
|
95 | - $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md'; |
|
92 | + $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md'; |
|
93 | + $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md'; |
|
94 | + $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md'; |
|
95 | + $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md'; |
|
96 | 96 | |
97 | 97 | $infoText = view('apidoc::partials.info') |
98 | 98 | ->with('outputPath', ltrim($outputPath, 'public/')) |
99 | 99 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection()); |
100 | 100 | |
101 | 101 | $settings = ['languages' => $this->docConfig->get('example_languages')]; |
102 | - $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) use ($settings) { |
|
103 | - return $routeGroup->map(function ($route) use ($settings) { |
|
104 | - if (count($route['cleanBodyParameters']) && ! isset($route['headers']['Content-Type'])) { |
|
102 | + $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) use ($settings) { |
|
103 | + return $routeGroup->map(function($route) use ($settings) { |
|
104 | + if (count($route['cleanBodyParameters']) && !isset($route['headers']['Content-Type'])) { |
|
105 | 105 | $route['headers']['Content-Type'] = 'application/json'; |
106 | 106 | } |
107 | 107 | $route['output'] = (string) view('apidoc::partials.route') |
@@ -128,16 +128,16 @@ discard block |
||
128 | 128 | $frontmatter = trim($generatedFrontmatter[1], "\n"); |
129 | 129 | } |
130 | 130 | |
131 | - $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
132 | - return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) { |
|
133 | - if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
134 | - $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
131 | + $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
132 | + return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) { |
|
133 | + if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
134 | + $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
135 | 135 | if ($routeDocumentationChanged === false || $this->option('force')) { |
136 | 136 | if ($routeDocumentationChanged) { |
137 | - $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
137 | + $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
138 | 138 | } |
139 | 139 | } else { |
140 | - $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
140 | + $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
141 | 141 | $route['modified_output'] = $existingRouteDoc[0]; |
142 | 142 | } |
143 | 143 | } |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | } |
149 | 149 | |
150 | 150 | $prependFileContents = file_exists($prependFile) |
151 | - ? file_get_contents($prependFile)."\n" : ''; |
|
151 | + ? file_get_contents($prependFile) . "\n" : ''; |
|
152 | 152 | $appendFileContents = file_exists($appendFile) |
153 | - ? "\n".file_get_contents($appendFile) : ''; |
|
153 | + ? "\n" . file_get_contents($appendFile) : ''; |
|
154 | 154 | |
155 | 155 | $documentarian = new Documentarian(); |
156 | 156 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection()) |
165 | 165 | ->with('parsedRoutes', $parsedRouteOutput); |
166 | 166 | |
167 | - if (! is_dir($outputPath)) { |
|
167 | + if (!is_dir($outputPath)) { |
|
168 | 168 | $documentarian->create($outputPath); |
169 | 169 | } |
170 | 170 | |
@@ -184,24 +184,24 @@ discard block |
||
184 | 184 | |
185 | 185 | file_put_contents($compareFile, $compareMarkdown); |
186 | 186 | |
187 | - $this->info('Wrote index.md to: '.$outputPath); |
|
187 | + $this->info('Wrote index.md to: ' . $outputPath); |
|
188 | 188 | |
189 | 189 | $this->info('Generating API HTML code'); |
190 | 190 | |
191 | 191 | $documentarian->generate($outputPath); |
192 | 192 | |
193 | - $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
193 | + $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
194 | 194 | |
195 | 195 | if ($this->shouldGeneratePostmanCollection()) { |
196 | 196 | $this->info('Generating Postman collection'); |
197 | 197 | |
198 | - file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
198 | + file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | if ($logo = $this->docConfig->get('logo')) { |
202 | 202 | copy( |
203 | 203 | $logo, |
204 | - $outputPath.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'logo.png' |
|
204 | + $outputPath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.png' |
|
205 | 205 | ); |
206 | 206 | } |
207 | 207 | } |
@@ -220,9 +220,9 @@ discard block |
||
220 | 220 | /** @var Route $route */ |
221 | 221 | if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction())) { |
222 | 222 | $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply']); |
223 | - $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
223 | + $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
224 | 224 | } else { |
225 | - $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
225 | + $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
226 | 226 | } |
227 | 227 | } |
228 | 228 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $action = implode('@', $action); |
242 | 242 | } |
243 | 243 | |
244 | - return ! is_callable($action) && ! is_null($action); |
|
244 | + return !is_callable($action) && !is_null($action); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | list($class, $method) = Utils::getRouteActionUses($action); |
257 | 257 | $reflection = new ReflectionClass($class); |
258 | 258 | |
259 | - if (! $reflection->hasMethod($method)) { |
|
259 | + if (!$reflection->hasMethod($method)) { |
|
260 | 260 | return false; |
261 | 261 | } |
262 | 262 | |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $phpdoc = new DocBlock($comment); |
267 | 267 | |
268 | 268 | return collect($phpdoc->getTags()) |
269 | - ->filter(function ($tag) use ($action) { |
|
269 | + ->filter(function($tag) use ($action) { |
|
270 | 270 | return $tag->getName() === 'hideFromAPIDocumentation'; |
271 | 271 | }) |
272 | 272 | ->isEmpty(); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | ]); |
69 | 69 | |
70 | 70 | $parsedRoute = [ |
71 | - 'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))), |
|
71 | + 'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))), |
|
72 | 72 | 'group' => $routeGroup, |
73 | 73 | 'title' => $docBlock['short'], |
74 | 74 | 'description' => $docBlock['long'], |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'cleanQueryParameters' => $this->cleanParams($queryParameters), |
82 | 82 | 'authenticated' => $this->getAuthStatusFromDocBlock($docBlock['tags']), |
83 | 83 | 'response' => $content, |
84 | - 'showresponse' => ! empty($content), |
|
84 | + 'showresponse' => !empty($content), |
|
85 | 85 | ]; |
86 | 86 | $parsedRoute['headers'] = $rulesToApply['headers'] ?? []; |
87 | 87 | |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | protected function getBodyParametersFromDocBlock(array $tags) |
128 | 128 | { |
129 | 129 | $parameters = collect($tags) |
130 | - ->filter(function ($tag) { |
|
130 | + ->filter(function($tag) { |
|
131 | 131 | return $tag instanceof Tag && $tag->getName() === 'bodyParam'; |
132 | 132 | }) |
133 | - ->mapWithKeys(function ($tag) { |
|
133 | + ->mapWithKeys(function($tag) { |
|
134 | 134 | preg_match('/(.+?)\s+(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content); |
135 | 135 | if (empty($content)) { |
136 | 136 | // this means only name and type were supplied |
@@ -202,10 +202,10 @@ discard block |
||
202 | 202 | protected function getQueryParametersFromDocBlock(array $tags) |
203 | 203 | { |
204 | 204 | $parameters = collect($tags) |
205 | - ->filter(function ($tag) { |
|
205 | + ->filter(function($tag) { |
|
206 | 206 | return $tag instanceof Tag && $tag->getName() === 'queryParam'; |
207 | 207 | }) |
208 | - ->mapWithKeys(function ($tag) { |
|
208 | + ->mapWithKeys(function($tag) { |
|
209 | 209 | preg_match('/(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content); |
210 | 210 | if (empty($content)) { |
211 | 211 | // this means only name was supplied |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | protected function getAuthStatusFromDocBlock(array $tags) |
244 | 244 | { |
245 | 245 | $authTag = collect($tags) |
246 | - ->first(function ($tag) { |
|
246 | + ->first(function($tag) { |
|
247 | 247 | return $tag instanceof Tag && strtolower($tag->getName()) === 'authenticated'; |
248 | 248 | }); |
249 | 249 | |
@@ -317,25 +317,25 @@ discard block |
||
317 | 317 | $faker->seed($this->config->get('faker_seed')); |
318 | 318 | } |
319 | 319 | $fakeFactories = [ |
320 | - 'integer' => function () use ($faker) { |
|
320 | + 'integer' => function() use ($faker) { |
|
321 | 321 | return $faker->numberBetween(1, 20); |
322 | 322 | }, |
323 | - 'number' => function () use ($faker) { |
|
323 | + 'number' => function() use ($faker) { |
|
324 | 324 | return $faker->randomFloat(); |
325 | 325 | }, |
326 | - 'float' => function () use ($faker) { |
|
326 | + 'float' => function() use ($faker) { |
|
327 | 327 | return $faker->randomFloat(); |
328 | 328 | }, |
329 | - 'boolean' => function () use ($faker) { |
|
329 | + 'boolean' => function() use ($faker) { |
|
330 | 330 | return $faker->boolean(); |
331 | 331 | }, |
332 | - 'string' => function () use ($faker) { |
|
332 | + 'string' => function() use ($faker) { |
|
333 | 333 | return $faker->word; |
334 | 334 | }, |
335 | - 'array' => function () { |
|
335 | + 'array' => function() { |
|
336 | 336 | return []; |
337 | 337 | }, |
338 | - 'object' => function () { |
|
338 | + 'object' => function() { |
|
339 | 339 | return new \stdClass; |
340 | 340 | }, |
341 | 341 | ]; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | public function __invoke(Route $route, array $tags, array $routeProps) |
27 | 27 | { |
28 | 28 | $rulesToApply = $routeProps['rules']['response_calls'] ?? []; |
29 | - if (! $this->shouldMakeApiCall($route, $rulesToApply)) { |
|
29 | + if (!$this->shouldMakeApiCall($route, $rulesToApply)) { |
|
30 | 30 | return; |
31 | 31 | } |
32 | 32 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | try { |
37 | 37 | $response = [$this->makeApiCall($request)]; |
38 | 38 | } catch (\Exception $e) { |
39 | - echo 'Response call failed for ['.implode(',', $route->methods)."] {$route->uri}"; |
|
39 | + echo 'Response call failed for [' . implode(',', $route->methods) . "] {$route->uri}"; |
|
40 | 40 | // TODO |
41 | 41 | // echo "Run this again with the --debug flag for details |
42 | 42 | $response = null; |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | // set URL and query parameters |
171 | 171 | $uri = $request->getRequestUri(); |
172 | 172 | $query = $request->getQueryString(); |
173 | - if (! empty($query)) { |
|
173 | + if (!empty($query)) { |
|
174 | 174 | $uri .= "?$query"; |
175 | 175 | } |
176 | 176 | $response = call_user_func_array([$dispatcher, strtolower($request->method())], [$uri]); |
177 | 177 | |
178 | 178 | // the response from the Dingo dispatcher is the 'raw' response from the controller, |
179 | 179 | // so we have to ensure it's JSON first |
180 | - if (! $response instanceof Response) { |
|
180 | + if (!$response instanceof Response) { |
|
181 | 181 | $response = response()->json($response); |
182 | 182 | } |
183 | 183 | |
@@ -326,8 +326,8 @@ discard block |
||
326 | 326 | $prefix = 'HTTP_'; |
327 | 327 | foreach ($headers as $name => $value) { |
328 | 328 | $name = strtr(strtoupper($name), '-', '_'); |
329 | - if (! starts_with($name, $prefix) && $name !== 'CONTENT_TYPE') { |
|
330 | - $name = $prefix.$name; |
|
329 | + if (!starts_with($name, $prefix) && $name !== 'CONTENT_TYPE') { |
|
330 | + $name = $prefix . $name; |
|
331 | 331 | } |
332 | 332 | $server[$name] = $value; |
333 | 333 | } |