@@ -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 | } |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | |
| 69 | 69 | public static function deleteDirectoryAndContents($dir) |
| 70 | 70 | { |
| 71 | - $adapter = new Local(realpath(__DIR__.'/../../')); |
|
| 71 | + $adapter = new Local(realpath(__DIR__ . '/../../')); |
|
| 72 | 72 | $fs = new Filesystem($adapter); |
| 73 | 73 | $fs->deleteDir($dir); |
| 74 | 74 | } |
@@ -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 | { |
@@ -41,32 +41,32 @@ discard block |
||
| 41 | 41 | $collection = [ |
| 42 | 42 | 'variables' => [], |
| 43 | 43 | 'info' => [ |
| 44 | - 'name' => config('apidoc.postman.name') ?: config('app.name').' API', |
|
| 44 | + 'name' => config('apidoc.postman.name') ?: config('app.name') . ' API', |
|
| 45 | 45 | '_postman_id' => Uuid::uuid4()->toString(), |
| 46 | 46 | 'description' => config('apidoc.postman.description') ?: '', |
| 47 | 47 | 'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json', |
| 48 | 48 | ], |
| 49 | - 'item' => $this->routeGroups->map(function ($routes, $groupName) { |
|
| 49 | + 'item' => $this->routeGroups->map(function($routes, $groupName) { |
|
| 50 | 50 | return [ |
| 51 | 51 | 'name' => $groupName, |
| 52 | 52 | 'description' => '', |
| 53 | - 'item' => $routes->map(function ($route) { |
|
| 53 | + 'item' => $routes->map(function($route) { |
|
| 54 | 54 | $mode = $route['methods'][0] === 'PUT' ? 'urlencoded' : 'formdata'; |
| 55 | 55 | |
| 56 | 56 | return [ |
| 57 | 57 | 'name' => $route['title'] != '' ? $route['title'] : url($route['uri']), |
| 58 | 58 | 'request' => [ |
| 59 | - 'url' => url($route['uri']).(collect($route['queryParameters'])->isEmpty() |
|
| 59 | + 'url' => url($route['uri']) . (collect($route['queryParameters'])->isEmpty() |
|
| 60 | 60 | ? '' |
| 61 | - : ('?'.implode('&', collect($route['queryParameters'])->map(function ($parameter, $key) { |
|
| 62 | - return urlencode($key).'='.urlencode($parameter['value'] ?? ''); |
|
| 61 | + : ('?' . implode('&', collect($route['queryParameters'])->map(function($parameter, $key) { |
|
| 62 | + return urlencode($key) . '=' . urlencode($parameter['value'] ?? ''); |
|
| 63 | 63 | })->all()))), |
| 64 | 64 | 'method' => $route['methods'][0], |
| 65 | 65 | 'header' => collect($route['headers']) |
| 66 | 66 | ->union([ |
| 67 | 67 | 'Accept' => 'application/json', |
| 68 | 68 | ]) |
| 69 | - ->map(function ($value, $header) { |
|
| 69 | + ->map(function($value, $header) { |
|
| 70 | 70 | return [ |
| 71 | 71 | 'key' => $header, |
| 72 | 72 | 'value' => $value, |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | ->values()->all(), |
| 76 | 76 | 'body' => [ |
| 77 | 77 | 'mode' => $mode, |
| 78 | - $mode => collect($route['bodyParameters'])->map(function ($parameter, $key) { |
|
| 78 | + $mode => collect($route['bodyParameters'])->map(function($parameter, $key) { |
|
| 79 | 79 | return [ |
| 80 | 80 | 'key' => $key, |
| 81 | 81 | 'value' => $parameter['value'] ?? '', |
@@ -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())); |
@@ -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; |
@@ -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]; |
@@ -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(); |
@@ -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 | |