@@ -15,14 +15,14 @@ |
||
| 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 | ], 'views'); |
| 23 | 23 | |
| 24 | 24 | $this->publishes([ |
| 25 | - __DIR__.'/../config/apidoc.php' => config_path('apidoc.php'), |
|
| 25 | + __DIR__ . '/../config/apidoc.php' => config_path('apidoc.php'), |
|
| 26 | 26 | ], 'config'); |
| 27 | 27 | |
| 28 | 28 | if ($this->app->runningInConsole()) { |
@@ -48,14 +48,14 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | private function getAllRoutes(bool $usingDingoRouter, array $versions = []) |
| 50 | 50 | { |
| 51 | - if (! $usingDingoRouter) { |
|
| 51 | + if (!$usingDingoRouter) { |
|
| 52 | 52 | return RouteFacade::getRoutes(); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $allRouteCollections = app(\Dingo\Api\Routing\Router::class)->getRoutes(); |
| 56 | 56 | |
| 57 | 57 | return collect($allRouteCollections) |
| 58 | - ->flatMap(function (RouteCollection $collection) { |
|
| 58 | + ->flatMap(function(RouteCollection $collection) { |
|
| 59 | 59 | return $collection->getRoutes(); |
| 60 | 60 | })->toArray(); |
| 61 | 61 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | private function shouldIncludeRoute(Route $route, array $routeRule, array $mustIncludes, bool $usingDingoRouter) |
| 64 | 64 | { |
| 65 | 65 | $matchesVersion = $usingDingoRouter |
| 66 | - ? ! empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? [])) |
|
| 66 | + ? !empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? [])) |
|
| 67 | 67 | : true; |
| 68 | 68 | |
| 69 | 69 | return in_array($route->getName(), $mustIncludes) |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $parsedRoutes = $this->processRoutes($generator, $routes); |
| 61 | 61 | $parsedRoutes = collect($parsedRoutes)->groupBy('resource') |
| 62 | - ->sort(function ($a, $b) { |
|
| 62 | + ->sort(function($a, $b) { |
|
| 63 | 63 | return strcmp($a->first()['resource'], $b->first()['resource']); |
| 64 | 64 | }); |
| 65 | 65 | |
@@ -74,17 +74,17 @@ discard block |
||
| 74 | 74 | private function writeMarkdown($parsedRoutes) |
| 75 | 75 | { |
| 76 | 76 | $outputPath = $this->option('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 | - ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection')); |
|
| 84 | + ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection')); |
|
| 85 | 85 | |
| 86 | - $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) { |
|
| 87 | - return $routeGroup->map(function ($route) { |
|
| 86 | + $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) { |
|
| 87 | + return $routeGroup->map(function($route) { |
|
| 88 | 88 | $route['output'] = (string) view('apidoc::partials.route')->with('parsedRoute', $route)->render(); |
| 89 | 89 | |
| 90 | 90 | return $route; |
@@ -104,16 +104,16 @@ discard block |
||
| 104 | 104 | $frontmatter = trim($generatedFrontmatter[1], "\n"); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
| 108 | - return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) { |
|
| 109 | - if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $routeMatch)) { |
|
| 110 | - $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1]); |
|
| 107 | + $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
| 108 | + return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) { |
|
| 109 | + if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $routeMatch)) { |
|
| 110 | + $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1]); |
|
| 111 | 111 | if ($routeDocumentationChanged === false || $this->option('force')) { |
| 112 | 112 | if ($routeDocumentationChanged) { |
| 113 | - $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
| 113 | + $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
| 114 | 114 | } |
| 115 | 115 | } else { |
| 116 | - $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
| 116 | + $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
| 117 | 117 | $route['modified_output'] = $routeMatch[0]; |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $prependFileContents = file_exists($prependFile) |
| 127 | - ? file_get_contents($prependFile)."\n" : ''; |
|
| 127 | + ? file_get_contents($prependFile) . "\n" : ''; |
|
| 128 | 128 | $appendFileContents = file_exists($appendFile) |
| 129 | - ? "\n".file_get_contents($appendFile) : ''; |
|
| 129 | + ? "\n" . file_get_contents($appendFile) : ''; |
|
| 130 | 130 | |
| 131 | 131 | $documentarian = new Documentarian(); |
| 132 | 132 | |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | ->with('prependMd', $prependFileContents) |
| 138 | 138 | ->with('appendMd', $appendFileContents) |
| 139 | 139 | ->with('outputPath', $this->option('output')) |
| 140 | - ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection')) |
|
| 140 | + ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection')) |
|
| 141 | 141 | ->with('parsedRoutes', $parsedRouteOutput); |
| 142 | 142 | |
| 143 | - if (! is_dir($outputPath)) { |
|
| 143 | + if (!is_dir($outputPath)) { |
|
| 144 | 144 | $documentarian->create($outputPath); |
| 145 | 145 | } |
| 146 | 146 | |
@@ -155,23 +155,23 @@ discard block |
||
| 155 | 155 | ->with('prependMd', $prependFileContents) |
| 156 | 156 | ->with('appendMd', $appendFileContents) |
| 157 | 157 | ->with('outputPath', $this->option('output')) |
| 158 | - ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection')) |
|
| 158 | + ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection')) |
|
| 159 | 159 | ->with('parsedRoutes', $parsedRouteOutput); |
| 160 | 160 | |
| 161 | 161 | file_put_contents($compareFile, $compareMarkdown); |
| 162 | 162 | |
| 163 | - $this->info('Wrote index.md to: '.$outputPath); |
|
| 163 | + $this->info('Wrote index.md to: ' . $outputPath); |
|
| 164 | 164 | |
| 165 | 165 | $this->info('Generating API HTML code'); |
| 166 | 166 | |
| 167 | 167 | $documentarian->generate($outputPath); |
| 168 | 168 | |
| 169 | - $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
| 169 | + $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
| 170 | 170 | |
| 171 | 171 | if ($this->option('noPostmanCollection') !== true) { |
| 172 | 172 | $this->info('Generating Postman collection'); |
| 173 | 173 | |
| 174 | - file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
| 174 | + file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
@@ -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, $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(); |