@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | ]); |
| 70 | 70 | |
| 71 | 71 | $parsedRoute = [ |
| 72 | - 'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))), |
|
| 72 | + 'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))), |
|
| 73 | 73 | 'group' => $routeGroup, |
| 74 | 74 | 'title' => $docBlock['short'], |
| 75 | 75 | 'description' => $docBlock['long'], |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | 'queryParameters' => $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 |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | protected function getQueryParametersFromDocBlock(array $tags) |
| 166 | 166 | { |
| 167 | 167 | $parameters = collect($tags) |
| 168 | - ->filter(function ($tag) { |
|
| 168 | + ->filter(function($tag) { |
|
| 169 | 169 | return $tag instanceof Tag && $tag->getName() === 'queryParam'; |
| 170 | 170 | }) |
| 171 | - ->mapWithKeys(function ($tag) { |
|
| 171 | + ->mapWithKeys(function($tag) { |
|
| 172 | 172 | preg_match('/(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content); |
| 173 | 173 | if (empty($content)) { |
| 174 | 174 | // this means only name was supplied |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | protected function getAuthStatusFromDocBlock(array $tags) |
| 207 | 207 | { |
| 208 | 208 | $authTag = collect($tags) |
| 209 | - ->first(function ($tag) { |
|
| 209 | + ->first(function($tag) { |
|
| 210 | 210 | return $tag instanceof Tag && strtolower($tag->getName()) === 'authenticated'; |
| 211 | 211 | }); |
| 212 | 212 | |
@@ -280,25 +280,25 @@ discard block |
||
| 280 | 280 | $faker->seed($this->fakerSeed); |
| 281 | 281 | } |
| 282 | 282 | $fakes = [ |
| 283 | - 'integer' => function () use ($faker) { |
|
| 283 | + 'integer' => function() use ($faker) { |
|
| 284 | 284 | return $faker->numberBetween(1, 20); |
| 285 | 285 | }, |
| 286 | - 'number' => function () use ($faker) { |
|
| 286 | + 'number' => function() use ($faker) { |
|
| 287 | 287 | return $faker->randomFloat(); |
| 288 | 288 | }, |
| 289 | - 'float' => function () use ($faker) { |
|
| 289 | + 'float' => function() use ($faker) { |
|
| 290 | 290 | return $faker->randomFloat(); |
| 291 | 291 | }, |
| 292 | - 'boolean' => function () use ($faker) { |
|
| 292 | + 'boolean' => function() use ($faker) { |
|
| 293 | 293 | return $faker->boolean(); |
| 294 | 294 | }, |
| 295 | - 'string' => function () use ($faker) { |
|
| 295 | + 'string' => function() use ($faker) { |
|
| 296 | 296 | return $faker->word; |
| 297 | 297 | }, |
| 298 | - 'array' => function () { |
|
| 298 | + 'array' => function() { |
|
| 299 | 299 | return []; |
| 300 | 300 | }, |
| 301 | - 'object' => function () { |
|
| 301 | + 'object' => function() { |
|
| 302 | 302 | return new \stdClass; |
| 303 | 303 | }, |
| 304 | 304 | ]; |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $generator = new Generator(config('apidoc.faker_seed')); |
| 59 | 59 | $parsedRoutes = $this->processRoutes($generator, $routes); |
| 60 | 60 | $parsedRoutes = collect($parsedRoutes)->groupBy('group') |
| 61 | - ->sortBy(static function ($group) { |
|
| 61 | + ->sortBy(static function($group) { |
|
| 62 | 62 | /* @var $group Collection */ |
| 63 | 63 | return $group->first()['group']; |
| 64 | 64 | }, SORT_NATURAL); |
@@ -74,18 +74,18 @@ discard block |
||
| 74 | 74 | private function writeMarkdown($parsedRoutes) |
| 75 | 75 | { |
| 76 | 76 | $outputPath = config('apidoc.output'); |
| 77 | - $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
|
| 78 | - $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md'; |
|
| 79 | - $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md'; |
|
| 80 | - $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md'; |
|
| 77 | + $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md'; |
|
| 78 | + $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md'; |
|
| 79 | + $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md'; |
|
| 80 | + $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md'; |
|
| 81 | 81 | |
| 82 | 82 | $infoText = view('apidoc::partials.info') |
| 83 | 83 | ->with('outputPath', ltrim($outputPath, 'public/')) |
| 84 | 84 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection()); |
| 85 | 85 | |
| 86 | - $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) { |
|
| 87 | - return $routeGroup->map(function ($route) { |
|
| 88 | - if (count($route['cleanBodyParameters']) && ! isset($route['headers']['Content-Type'])) { |
|
| 86 | + $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) { |
|
| 87 | + return $routeGroup->map(function($route) { |
|
| 88 | + if (count($route['cleanBodyParameters']) && !isset($route['headers']['Content-Type'])) { |
|
| 89 | 89 | $route['headers']['Content-Type'] = 'application/json'; |
| 90 | 90 | } |
| 91 | 91 | $route['output'] = (string) view('apidoc::partials.route')->with('route', $route)->render(); |
@@ -107,16 +107,16 @@ discard block |
||
| 107 | 107 | $frontmatter = trim($generatedFrontmatter[1], "\n"); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
| 111 | - return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) { |
|
| 112 | - if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
| 113 | - $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
| 110 | + $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
| 111 | + return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) { |
|
| 112 | + if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
| 113 | + $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
| 114 | 114 | if ($routeDocumentationChanged === false || $this->option('force')) { |
| 115 | 115 | if ($routeDocumentationChanged) { |
| 116 | - $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
| 116 | + $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
| 117 | 117 | } |
| 118 | 118 | } else { |
| 119 | - $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
| 119 | + $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
| 120 | 120 | $route['modified_output'] = $existingRouteDoc[0]; |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $prependFileContents = file_exists($prependFile) |
| 130 | - ? file_get_contents($prependFile)."\n" : ''; |
|
| 130 | + ? file_get_contents($prependFile) . "\n" : ''; |
|
| 131 | 131 | $appendFileContents = file_exists($appendFile) |
| 132 | - ? "\n".file_get_contents($appendFile) : ''; |
|
| 132 | + ? "\n" . file_get_contents($appendFile) : ''; |
|
| 133 | 133 | |
| 134 | 134 | $documentarian = new Documentarian(); |
| 135 | 135 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection()) |
| 144 | 144 | ->with('parsedRoutes', $parsedRouteOutput); |
| 145 | 145 | |
| 146 | - if (! is_dir($outputPath)) { |
|
| 146 | + if (!is_dir($outputPath)) { |
|
| 147 | 147 | $documentarian->create($outputPath); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -163,24 +163,24 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | file_put_contents($compareFile, $compareMarkdown); |
| 165 | 165 | |
| 166 | - $this->info('Wrote index.md to: '.$outputPath); |
|
| 166 | + $this->info('Wrote index.md to: ' . $outputPath); |
|
| 167 | 167 | |
| 168 | 168 | $this->info('Generating API HTML code'); |
| 169 | 169 | |
| 170 | 170 | $documentarian->generate($outputPath); |
| 171 | 171 | |
| 172 | - $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
| 172 | + $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
| 173 | 173 | |
| 174 | 174 | if ($this->shouldGeneratePostmanCollection()) { |
| 175 | 175 | $this->info('Generating Postman collection'); |
| 176 | 176 | |
| 177 | - file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
| 177 | + file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | if ($logo = config('apidoc.logo')) { |
| 181 | 181 | copy( |
| 182 | 182 | $logo, |
| 183 | - $outputPath.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'logo.png' |
|
| 183 | + $outputPath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.png' |
|
| 184 | 184 | ); |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | /** @var Route $route */ |
| 200 | 200 | if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) { |
| 201 | 201 | $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply']); |
| 202 | - $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
| 202 | + $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
| 203 | 203 | } else { |
| 204 | - $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
| 204 | + $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | private function isValidRoute(Route $route) |
| 217 | 217 | { |
| 218 | - return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']); |
|
| 218 | + return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | list($class, $method) = explode('@', $route); |
| 231 | 231 | $reflection = new ReflectionClass($class); |
| 232 | 232 | |
| 233 | - if (! $reflection->hasMethod($method)) { |
|
| 233 | + if (!$reflection->hasMethod($method)) { |
|
| 234 | 234 | return false; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | $phpdoc = new DocBlock($comment); |
| 241 | 241 | |
| 242 | 242 | return collect($phpdoc->getTags()) |
| 243 | - ->filter(function ($tag) use ($route) { |
|
| 243 | + ->filter(function($tag) use ($route) { |
|
| 244 | 244 | return $tag->getName() === 'hideFromAPIDocumentation'; |
| 245 | 245 | }) |
| 246 | 246 | ->isEmpty(); |