@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | $parsedRoutes = $this->processRoutes($generator, $routes); |
| 60 | 60 | $parsedRoutes = collect($parsedRoutes)->groupBy('resource') |
| 61 | - ->sort(function ($a, $b) { |
|
| 61 | + ->sort(function($a, $b) { |
|
| 62 | 62 | return strcmp($a->first()['resource'], $b->first()['resource']); |
| 63 | 63 | }); |
| 64 | 64 | |
@@ -73,17 +73,17 @@ discard block |
||
| 73 | 73 | private function writeMarkdown($parsedRoutes) |
| 74 | 74 | { |
| 75 | 75 | $outputPath = config('apidoc.output'); |
| 76 | - $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
|
| 77 | - $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md'; |
|
| 78 | - $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md'; |
|
| 79 | - $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md'; |
|
| 76 | + $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md'; |
|
| 77 | + $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md'; |
|
| 78 | + $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md'; |
|
| 79 | + $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md'; |
|
| 80 | 80 | |
| 81 | 81 | $infoText = view('apidoc::partials.info') |
| 82 | 82 | ->with('outputPath', ltrim($outputPath, 'public/')) |
| 83 | 83 | ->with('showPostmanCollectionButton', config('apidoc.postman')); |
| 84 | 84 | |
| 85 | - $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) { |
|
| 86 | - return $routeGroup->map(function ($route) { |
|
| 85 | + $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) { |
|
| 86 | + return $routeGroup->map(function($route) { |
|
| 87 | 87 | $route['output'] = (string) view('apidoc::partials.route')->with('route', $route)->render(); |
| 88 | 88 | |
| 89 | 89 | return $route; |
@@ -103,16 +103,16 @@ discard block |
||
| 103 | 103 | $frontmatter = trim($generatedFrontmatter[1], "\n"); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
| 107 | - return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) { |
|
| 108 | - if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
| 109 | - $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
| 106 | + $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
| 107 | + return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) { |
|
| 108 | + if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
| 109 | + $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
| 110 | 110 | if ($routeDocumentationChanged === false || $this->option('force')) { |
| 111 | 111 | if ($routeDocumentationChanged) { |
| 112 | - $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
| 112 | + $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
| 113 | 113 | } |
| 114 | 114 | } else { |
| 115 | - $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
| 115 | + $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
| 116 | 116 | $route['modified_output'] = $existingRouteDoc[0]; |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $prependFileContents = file_exists($prependFile) |
| 126 | - ? file_get_contents($prependFile)."\n" : ''; |
|
| 126 | + ? file_get_contents($prependFile) . "\n" : ''; |
|
| 127 | 127 | $appendFileContents = file_exists($appendFile) |
| 128 | - ? "\n".file_get_contents($appendFile) : ''; |
|
| 128 | + ? "\n" . file_get_contents($appendFile) : ''; |
|
| 129 | 129 | |
| 130 | 130 | $documentarian = new Documentarian(); |
| 131 | 131 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | ->with('showPostmanCollectionButton', config('apidoc.postman')) |
| 140 | 140 | ->with('parsedRoutes', $parsedRouteOutput); |
| 141 | 141 | |
| 142 | - if (! is_dir($outputPath)) { |
|
| 142 | + if (!is_dir($outputPath)) { |
|
| 143 | 143 | $documentarian->create($outputPath); |
| 144 | 144 | } |
| 145 | 145 | |
@@ -159,18 +159,18 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | file_put_contents($compareFile, $compareMarkdown); |
| 161 | 161 | |
| 162 | - $this->info('Wrote index.md to: '.$outputPath); |
|
| 162 | + $this->info('Wrote index.md to: ' . $outputPath); |
|
| 163 | 163 | |
| 164 | 164 | $this->info('Generating API HTML code'); |
| 165 | 165 | |
| 166 | 166 | $documentarian->generate($outputPath); |
| 167 | 167 | |
| 168 | - $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
| 168 | + $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
| 169 | 169 | |
| 170 | 170 | if (config('apidoc.postman')) { |
| 171 | 171 | $this->info('Generating Postman collection'); |
| 172 | 172 | |
| 173 | - file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
| 173 | + file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
@@ -188,9 +188,9 @@ discard block |
||
| 188 | 188 | /** @var Route $route */ |
| 189 | 189 | if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) { |
| 190 | 190 | $parsedRoutes[] = $generator->processRoute($route) + $routeItem['apply']; |
| 191 | - $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
| 191 | + $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
| 192 | 192 | } else { |
| 193 | - $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
| 193 | + $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | private function isValidRoute(Route $route) |
| 206 | 206 | { |
| 207 | - return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']); |
|
| 207 | + return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $phpdoc = new DocBlock($comment); |
| 222 | 222 | |
| 223 | 223 | return collect($phpdoc->getTags()) |
| 224 | - ->filter(function ($tag) use ($route) { |
|
| 224 | + ->filter(function($tag) use ($route) { |
|
| 225 | 225 | return $tag->getName() === 'hideFromAPIDocumentation'; |
| 226 | 226 | }) |
| 227 | 227 | ->isEmpty(); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $content = $this->getResponse($docBlock['tags']); |
| 59 | 59 | |
| 60 | 60 | return [ |
| 61 | - 'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))), |
|
| 61 | + 'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))), |
|
| 62 | 62 | 'resource' => $routeGroup, |
| 63 | 63 | 'title' => $docBlock['short'], |
| 64 | 64 | 'description' => $docBlock['long'], |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | 'parameters' => $this->getParametersFromDocBlock($docBlock['tags']), |
| 68 | 68 | 'authenticated' => $this->getAuthStatusFromDocBlock($docBlock['tags']), |
| 69 | 69 | 'response' => $content, |
| 70 | - 'showresponse' => ! empty($content), |
|
| 70 | + 'showresponse' => !empty($content), |
|
| 71 | 71 | ]; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | protected function getDocblockResponse($tags) |
| 91 | 91 | { |
| 92 | - $responseTags = array_filter($tags, function ($tag) { |
|
| 92 | + $responseTags = array_filter($tags, function($tag) { |
|
| 93 | 93 | return $tag instanceof Tag && \strtolower($tag->getName()) == 'response'; |
| 94 | 94 | }); |
| 95 | 95 | if (empty($responseTags)) { |
@@ -108,10 +108,10 @@ discard block |
||
| 108 | 108 | protected function getParametersFromDocBlock(array $tags) |
| 109 | 109 | { |
| 110 | 110 | $parameters = collect($tags) |
| 111 | - ->filter(function ($tag) { |
|
| 111 | + ->filter(function($tag) { |
|
| 112 | 112 | return $tag instanceof Tag && $tag->getName() === 'bodyParam'; |
| 113 | 113 | }) |
| 114 | - ->mapWithKeys(function ($tag) { |
|
| 114 | + ->mapWithKeys(function($tag) { |
|
| 115 | 115 | preg_match('/(.+?)\s+(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content); |
| 116 | 116 | if (empty($content)) { |
| 117 | 117 | // this means only name and type were supplied |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | protected function getAuthStatusFromDocBlock(array $tags) |
| 146 | 146 | { |
| 147 | 147 | $authTag = collect($tags) |
| 148 | - ->first(function ($tag) { |
|
| 148 | + ->first(function($tag) { |
|
| 149 | 149 | return $tag instanceof Tag && strtolower($tag->getName()) === 'authenticated'; |
| 150 | 150 | }); |
| 151 | 151 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $methods = $this->getMethods($route); |
| 167 | 167 | |
| 168 | 168 | // Split headers into key - value pairs |
| 169 | - $headers = collect($headers)->map(function ($value) { |
|
| 169 | + $headers = collect($headers)->map(function($value) { |
|
| 170 | 170 | $split = explode(':', $value); // explode to get key + values |
| 171 | 171 | $key = array_shift($split); // extract the key and keep the values in the array |
| 172 | 172 | $value = implode(':', $split); // implode values into string again |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | { |
| 191 | 191 | $uri = $this->getUri($route); |
| 192 | 192 | foreach ($bindings as $model => $id) { |
| 193 | - $uri = str_replace('{'.$model.'}', $id, $uri); |
|
| 194 | - $uri = str_replace('{'.$model.'?}', $id, $uri); |
|
| 193 | + $uri = str_replace('{' . $model . '}', $id, $uri); |
|
| 194 | + $uri = str_replace('{' . $model . '?}', $id, $uri); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return $uri; |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | foreach ($headers as $name => $value) { |
| 271 | 271 | $name = strtr(strtoupper($name), '-', '_'); |
| 272 | 272 | |
| 273 | - if (! Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') { |
|
| 274 | - $name = $prefix.$name; |
|
| 273 | + if (!Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') { |
|
| 274 | + $name = $prefix . $name; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | $server[$name] = $value; |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | protected function getTransformerResponse($tags) |
| 310 | 310 | { |
| 311 | 311 | try { |
| 312 | - $transFormerTags = array_filter($tags, function ($tag) { |
|
| 313 | - if (! ($tag instanceof Tag)) { |
|
| 312 | + $transFormerTags = array_filter($tags, function($tag) { |
|
| 313 | + if (!($tag instanceof Tag)) { |
|
| 314 | 314 | return false; |
| 315 | 315 | } |
| 316 | 316 | |
@@ -321,8 +321,8 @@ discard block |
||
| 321 | 321 | return false; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - $modelTag = array_first(array_filter($tags, function ($tag) { |
|
| 325 | - if (! ($tag instanceof Tag)) { |
|
| 324 | + $modelTag = array_first(array_filter($tags, function($tag) { |
|
| 325 | + if (!($tag instanceof Tag)) { |
|
| 326 | 326 | return false; |
| 327 | 327 | } |
| 328 | 328 | |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | })); |
| 331 | 331 | $tag = \array_first($transFormerTags); |
| 332 | 332 | $transformer = $tag->getContent(); |
| 333 | - if (! \class_exists($transformer)) { |
|
| 333 | + if (!\class_exists($transformer)) { |
|
| 334 | 334 | // if we can't find the transformer we can't generate a response |
| 335 | 335 | return; |
| 336 | 336 | } |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | } |
| 346 | 346 | if (\is_null($type)) { |
| 347 | 347 | if ($parameter->hasType() && |
| 348 | - ! $parameter->getType()->isBuiltin() && |
|
| 348 | + !$parameter->getType()->isBuiltin() && |
|
| 349 | 349 | \class_exists((string) $parameter->getType())) { |
| 350 | 350 | //we have a type |
| 351 | 351 | $type = (string) $parameter->getType(); |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | // we have a response from the docblock ( @response ) |
| 399 | 399 | $response = $docblockResponse; |
| 400 | 400 | } |
| 401 | - if (! $response && ($transformerResponse = $this->getTransformerResponse($annotationTags))) { |
|
| 401 | + if (!$response && ($transformerResponse = $this->getTransformerResponse($annotationTags))) { |
|
| 402 | 402 | // we have a transformer response from the docblock ( @transformer || @transformercollection ) |
| 403 | 403 | $response = $transformerResponse; |
| 404 | 404 | } |
@@ -423,25 +423,25 @@ discard block |
||
| 423 | 423 | { |
| 424 | 424 | $faker = Factory::create(); |
| 425 | 425 | $fakes = [ |
| 426 | - 'integer' => function () { |
|
| 426 | + 'integer' => function() { |
|
| 427 | 427 | return rand(1, 20); |
| 428 | 428 | }, |
| 429 | - 'number' => function () use ($faker) { |
|
| 429 | + 'number' => function() use ($faker) { |
|
| 430 | 430 | return $faker->randomFloat(); |
| 431 | 431 | }, |
| 432 | - 'float' => function () use ($faker) { |
|
| 432 | + 'float' => function() use ($faker) { |
|
| 433 | 433 | return $faker->randomFloat(); |
| 434 | 434 | }, |
| 435 | - 'boolean' => function () use ($faker) { |
|
| 435 | + 'boolean' => function() use ($faker) { |
|
| 436 | 436 | return $faker->boolean(); |
| 437 | 437 | }, |
| 438 | - 'string' => function () use ($faker) { |
|
| 438 | + 'string' => function() use ($faker) { |
|
| 439 | 439 | return str_random(); |
| 440 | 440 | }, |
| 441 | - 'array' => function () { |
|
| 441 | + 'array' => function() { |
|
| 442 | 442 | return '[]'; |
| 443 | 443 | }, |
| 444 | - 'object' => function () { |
|
| 444 | + 'object' => function() { |
|
| 445 | 445 | return '{}'; |
| 446 | 446 | }, |
| 447 | 447 | ]; |