@@ -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 | ], 'apidoc-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 | ], 'apidoc-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 | } |
@@ -40,32 +40,32 @@ discard block |
||
40 | 40 | $collection = [ |
41 | 41 | 'variables' => [], |
42 | 42 | 'info' => [ |
43 | - 'name' => config('apidoc.postman.name') ?: config('app.name').' API', |
|
43 | + 'name' => config('apidoc.postman.name') ?: config('app.name') . ' API', |
|
44 | 44 | '_postman_id' => Uuid::uuid4()->toString(), |
45 | 45 | 'description' => config('apidoc.postman.description') ?: '', |
46 | 46 | 'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json', |
47 | 47 | ], |
48 | - 'item' => $this->routeGroups->map(function ($routes, $groupName) { |
|
48 | + 'item' => $this->routeGroups->map(function($routes, $groupName) { |
|
49 | 49 | return [ |
50 | 50 | 'name' => $groupName, |
51 | 51 | 'description' => '', |
52 | - 'item' => $routes->map(function ($route) { |
|
52 | + 'item' => $routes->map(function($route) { |
|
53 | 53 | $mode = $route['methods'][0] === 'PUT' ? 'urlencoded' : 'formdata'; |
54 | 54 | |
55 | 55 | return [ |
56 | 56 | 'name' => $route['metadata']['title'] != '' ? $route['metadata']['title'] : url($route['uri']), |
57 | 57 | 'request' => [ |
58 | - 'url' => url($route['uri']).(collect($route['queryParameters'])->isEmpty() |
|
58 | + 'url' => url($route['uri']) . (collect($route['queryParameters'])->isEmpty() |
|
59 | 59 | ? '' |
60 | - : ('?'.implode('&', collect($route['queryParameters'])->map(function ($parameter, $key) { |
|
61 | - return urlencode($key).'='.urlencode($parameter['value'] ?? ''); |
|
60 | + : ('?' . implode('&', collect($route['queryParameters'])->map(function($parameter, $key) { |
|
61 | + return urlencode($key) . '=' . urlencode($parameter['value'] ?? ''); |
|
62 | 62 | })->all()))), |
63 | 63 | 'method' => $route['methods'][0], |
64 | 64 | 'header' => collect($route['headers']) |
65 | 65 | ->union([ |
66 | 66 | 'Accept' => 'application/json', |
67 | 67 | ]) |
68 | - ->map(function ($value, $header) { |
|
68 | + ->map(function($value, $header) { |
|
69 | 69 | return [ |
70 | 70 | 'key' => $header, |
71 | 71 | 'value' => $value, |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | ->values()->all(), |
75 | 75 | 'body' => [ |
76 | 76 | 'mode' => $mode, |
77 | - $mode => collect($route['bodyParameters'])->map(function ($parameter, $key) { |
|
77 | + $mode => collect($route['bodyParameters'])->map(function($parameter, $key) { |
|
78 | 78 | return [ |
79 | 79 | 'key' => $key, |
80 | 80 | 'value' => $parameter['value'] ?? '', |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function writeMarkdownAndSourceFiles(Collection $parsedRoutes, string $sourceOutputPath) |
85 | 85 | { |
86 | - $targetFile = $sourceOutputPath.'/source/index.md'; |
|
87 | - $compareFile = $sourceOutputPath.'/source/.compare.md'; |
|
86 | + $targetFile = $sourceOutputPath . '/source/index.md'; |
|
87 | + $compareFile = $sourceOutputPath . '/source/.compare.md'; |
|
88 | 88 | |
89 | 89 | $infoText = view('apidoc::partials.info') |
90 | 90 | ->with('outputPath', 'docs') |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | $generatedDocumentation = file_get_contents($targetFile); |
107 | 107 | $compareDocumentation = file_get_contents($compareFile); |
108 | 108 | |
109 | - $parsedRouteOutput->transform(function (Collection $routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
110 | - return $routeGroup->transform(function (array $route) use ($generatedDocumentation, $compareDocumentation) { |
|
111 | - if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
112 | - $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
109 | + $parsedRouteOutput->transform(function(Collection $routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
110 | + return $routeGroup->transform(function(array $route) use ($generatedDocumentation, $compareDocumentation) { |
|
111 | + if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
112 | + $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
113 | 113 | if ($routeDocumentationChanged === false || $this->forceIt) { |
114 | 114 | if ($routeDocumentationChanged) { |
115 | - $this->output->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
115 | + $this->output->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
116 | 116 | } |
117 | 117 | } else { |
118 | - $this->output->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
118 | + $this->output->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
119 | 119 | $route['modified_output'] = $existingRouteDoc[0]; |
120 | 120 | } |
121 | 121 | } |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection) |
139 | 139 | ->with('parsedRoutes', $parsedRouteOutput); |
140 | 140 | |
141 | - $this->output->info('Writing index.md and source files to: '.$sourceOutputPath); |
|
141 | + $this->output->info('Writing index.md and source files to: ' . $sourceOutputPath); |
|
142 | 142 | |
143 | - if (! is_dir($sourceOutputPath)) { |
|
143 | + if (!is_dir($sourceOutputPath)) { |
|
144 | 144 | $documentarian = new Documentarian(); |
145 | 145 | $documentarian->create($sourceOutputPath); |
146 | 146 | } |
@@ -161,14 +161,14 @@ discard block |
||
161 | 161 | |
162 | 162 | file_put_contents($compareFile, $compareMarkdown); |
163 | 163 | |
164 | - $this->output->info('Wrote index.md and source files to: '.$sourceOutputPath); |
|
164 | + $this->output->info('Wrote index.md and source files to: ' . $sourceOutputPath); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | public function generateMarkdownOutputForEachRoute(Collection $parsedRoutes, array $settings): Collection |
168 | 168 | { |
169 | - $parsedRouteOutput = $parsedRoutes->map(function (Collection $routeGroup) use ($settings) { |
|
170 | - return $routeGroup->map(function (array $route) use ($settings) { |
|
171 | - if (count($route['cleanBodyParameters']) && ! isset($route['headers']['Content-Type'])) { |
|
169 | + $parsedRouteOutput = $parsedRoutes->map(function(Collection $routeGroup) use ($settings) { |
|
170 | + return $routeGroup->map(function(array $route) use ($settings) { |
|
171 | + if (count($route['cleanBodyParameters']) && !isset($route['headers']['Content-Type'])) { |
|
172 | 172 | // Set content type if the user forgot to set it |
173 | 173 | $route['headers']['Content-Type'] = 'application/json'; |
174 | 174 | } |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | */ |
225 | 225 | protected function getMarkdownToPrepend(string $sourceOutputPath): string |
226 | 226 | { |
227 | - $prependFile = $sourceOutputPath.'/source/prepend.md'; |
|
227 | + $prependFile = $sourceOutputPath . '/source/prepend.md'; |
|
228 | 228 | $prependFileContents = file_exists($prependFile) |
229 | - ? file_get_contents($prependFile)."\n" : ''; |
|
229 | + ? file_get_contents($prependFile) . "\n" : ''; |
|
230 | 230 | |
231 | 231 | return $prependFileContents; |
232 | 232 | } |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | */ |
239 | 239 | protected function getMarkdownToAppend(string $sourceOutputPath): string |
240 | 240 | { |
241 | - $appendFile = $sourceOutputPath.'/source/append.md'; |
|
241 | + $appendFile = $sourceOutputPath . '/source/append.md'; |
|
242 | 242 | $appendFileContents = file_exists($appendFile) |
243 | - ? "\n".file_get_contents($appendFile) : ''; |
|
243 | + ? "\n" . file_get_contents($appendFile) : ''; |
|
244 | 244 | |
245 | 245 | return $appendFileContents; |
246 | 246 | } |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | protected function copyAssetsFromSourceFolderToPublicFolder(string $sourceOutputPath, bool $isStatic = true): void |
249 | 249 | { |
250 | 250 | $publicPath = 'public/docs'; |
251 | - if (! is_dir($publicPath)) { |
|
251 | + if (!is_dir($publicPath)) { |
|
252 | 252 | mkdir($publicPath, 0777, true); |
253 | 253 | mkdir("{$publicPath}/css"); |
254 | 254 | mkdir("{$publicPath}/js"); |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | rename("{$sourceOutputPath}/index.html", "{$outputPath}/index.html"); |
272 | 272 | } else { |
273 | 273 | // Move output to resources/views |
274 | - if (! is_dir($outputPath)) { |
|
274 | + if (!is_dir($outputPath)) { |
|
275 | 275 | mkdir($outputPath); |
276 | 276 | } |
277 | 277 | rename("{$sourceOutputPath}/index.html", "$outputPath/index.blade.php"); |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | |
65 | 65 | private function getAllRoutes(bool $usingDingoRouter) |
66 | 66 | { |
67 | - if (! $usingDingoRouter) { |
|
67 | + if (!$usingDingoRouter) { |
|
68 | 68 | return RouteFacade::getRoutes(); |
69 | 69 | } |
70 | 70 | |
71 | 71 | $allRouteCollections = app(\Dingo\Api\Routing\Router::class)->getRoutes(); |
72 | 72 | |
73 | 73 | return collect($allRouteCollections) |
74 | - ->flatMap(function (RouteCollection $collection) { |
|
74 | + ->flatMap(function(RouteCollection $collection) { |
|
75 | 75 | return $collection->getRoutes(); |
76 | 76 | })->toArray(); |
77 | 77 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | private function shouldIncludeRoute(Route $route, array $routeRule, array $mustIncludes, bool $usingDingoRouter) |
80 | 80 | { |
81 | 81 | $matchesVersion = $usingDingoRouter |
82 | - ? ! empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? [])) |
|
82 | + ? !empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? [])) |
|
83 | 83 | : true; |
84 | 84 | |
85 | 85 | return Str::is($mustIncludes, $route->getName()) |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $method = $controller->getMethod($methodName); |
57 | 57 | |
58 | 58 | $parsedRoute = [ |
59 | - 'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))), |
|
59 | + 'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))), |
|
60 | 60 | 'methods' => $this->getMethods($route), |
61 | 61 | 'uri' => $this->getUri($route), |
62 | 62 | ]; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $responses = $this->fetchResponses($controller, $method, $route, $routeRules, $parsedRoute); |
80 | 80 | $parsedRoute['responses'] = $responses; |
81 | - $parsedRoute['showresponse'] = ! empty($responses); |
|
81 | + $parsedRoute['showresponse'] = !empty($responses); |
|
82 | 82 | |
83 | 83 | $parsedRoute['headers'] = $routeRules['headers'] ?? []; |
84 | 84 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | { |
118 | 118 | $responses = $this->iterateThroughStrategies('responses', $context, [$route, $controller, $method, $rulesToApply]); |
119 | 119 | if (count($responses)) { |
120 | - return array_filter($responses, function ($response) { |
|
120 | + return array_filter($responses, function($response) { |
|
121 | 121 | return $response['content'] != null; |
122 | 122 | }); |
123 | 123 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $strategyArgs = $arguments; |
158 | 158 | $strategyArgs[] = $context; |
159 | 159 | $results = $strategy(...$strategyArgs); |
160 | - if (! is_null($results)) { |
|
160 | + if (!is_null($results)) { |
|
161 | 161 | foreach ($results as $index => $item) { |
162 | 162 | if ($stage == 'responses') { |
163 | 163 | // Responses are additive |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | // and also allows values to be overwritten |
170 | 170 | |
171 | 171 | // Don't allow overwriting if an empty value is trying to replace a set one |
172 | - if (! in_array($context[$stage], [null, ''], true) && in_array($item, [null, ''], true)) { |
|
172 | + if (!in_array($context[$stage], [null, ''], true) && in_array($item, [null, ''], true)) { |
|
173 | 173 | continue; |
174 | 174 | } else { |
175 | 175 | $context[$stage][$index] = $item; |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | $values = []; |
195 | 195 | |
196 | 196 | // Remove params which have no examples. |
197 | - $params = array_filter($params, function ($details) { |
|
198 | - return ! is_null($details['value']); |
|
197 | + $params = array_filter($params, function($details) { |
|
198 | + return !is_null($details['value']); |
|
199 | 199 | }); |
200 | 200 | |
201 | 201 | foreach ($params as $paramName => $details) { |
@@ -20,7 +20,7 @@ |
||
20 | 20 | |
21 | 21 | $class = new ReflectionClass($className); |
22 | 22 | |
23 | - if (! $class->hasMethod($methodName)) { |
|
23 | + if (!$class->hasMethod($methodName)) { |
|
24 | 24 | throw new \Exception("Error while fetching docblock for route: Class $className does not contain method $methodName"); |
25 | 25 | } |
26 | 26 |
@@ -13,25 +13,25 @@ |
||
13 | 13 | $faker->seed($this->config->get('faker_seed')); |
14 | 14 | } |
15 | 15 | $fakeFactories = [ |
16 | - 'integer' => function () use ($faker) { |
|
16 | + 'integer' => function() use ($faker) { |
|
17 | 17 | return $faker->numberBetween(1, 20); |
18 | 18 | }, |
19 | - 'number' => function () use ($faker) { |
|
19 | + 'number' => function() use ($faker) { |
|
20 | 20 | return $faker->randomFloat(); |
21 | 21 | }, |
22 | - 'float' => function () use ($faker) { |
|
22 | + 'float' => function() use ($faker) { |
|
23 | 23 | return $faker->randomFloat(); |
24 | 24 | }, |
25 | - 'boolean' => function () use ($faker) { |
|
25 | + 'boolean' => function() use ($faker) { |
|
26 | 26 | return $faker->boolean(); |
27 | 27 | }, |
28 | - 'string' => function () use ($faker) { |
|
28 | + 'string' => function() use ($faker) { |
|
29 | 29 | return $faker->word; |
30 | 30 | }, |
31 | - 'array' => function () { |
|
31 | + 'array' => function() { |
|
32 | 32 | return []; |
33 | 33 | }, |
34 | - 'object' => function () { |
|
34 | + 'object' => function() { |
|
35 | 35 | return new \stdClass; |
36 | 36 | }, |
37 | 37 | ]; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | $fractal = new Manager(); |
65 | 65 | |
66 | - if (! is_null(config('apidoc.fractal.serializer'))) { |
|
66 | + if (!is_null(config('apidoc.fractal.serializer'))) { |
|
67 | 67 | $fractal->setSerializer(app(config('apidoc.fractal.serializer'))); |
68 | 68 | } |
69 | 69 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | ], |
83 | 83 | ]; |
84 | 84 | } catch (\Exception $e) { |
85 | - echo 'Exception thrown when fetching transformer response for ['.implode(',', $route->methods)."] {$route->uri}.\n"; |
|
85 | + echo 'Exception thrown when fetching transformer response for [' . implode(',', $route->methods) . "] {$route->uri}.\n"; |
|
86 | 86 | if (Flags::$shouldBeVerbose) { |
87 | 87 | Utils::dumpException($e); |
88 | 88 | } else { |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | private function getClassToBeTransformed(array $tags, ReflectionMethod $transformerMethod): string |
118 | 118 | { |
119 | - $modelTag = Arr::first(array_filter($tags, function ($tag) { |
|
119 | + $modelTag = Arr::first(array_filter($tags, function($tag) { |
|
120 | 120 | return ($tag instanceof Tag) && strtolower($tag->getName()) == 'transformermodel'; |
121 | 121 | })); |
122 | 122 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | $type = $modelTag->getContent(); |
126 | 126 | } else { |
127 | 127 | $parameter = Arr::first($transformerMethod->getParameters()); |
128 | - if ($parameter->hasType() && ! $parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) { |
|
128 | + if ($parameter->hasType() && !$parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) { |
|
129 | 129 | // Ladies and gentlemen, we have a type! |
130 | 130 | $type = (string) $parameter->getType(); |
131 | 131 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | private function getTransformerTag(array $tags) |
187 | 187 | { |
188 | 188 | $transformerTags = array_values( |
189 | - array_filter($tags, function ($tag) { |
|
189 | + array_filter($tags, function($tag) { |
|
190 | 190 | return ($tag instanceof Tag) && in_array(strtolower($tag->getName()), ['transformer', 'transformercollection']); |
191 | 191 | }) |
192 | 192 | ); |