Bladeren bron

Refactor postman enabled config into method for GenerateDocumentation.php

Enrico Werkema 6 jaren geleden
bovenliggende
commit
69144c7c85
1 gewijzigde bestanden met toevoegingen van 14 en 4 verwijderingen
  1. 14 4
      src/Commands/GenerateDocumentation.php

+ 14 - 4
src/Commands/GenerateDocumentation.php

@@ -79,7 +79,7 @@ class GenerateDocumentation extends Command
 
         $infoText = view('apidoc::partials.info')
             ->with('outputPath', ltrim($outputPath, 'public/'))
-            ->with('showPostmanCollectionButton', config('apidoc.postman.enabled') ?? config('apidoc.postman'));
+            ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection());
 
         $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) {
             return $routeGroup->map(function ($route) {
@@ -135,7 +135,7 @@ class GenerateDocumentation extends Command
             ->with('prependMd', $prependFileContents)
             ->with('appendMd', $appendFileContents)
             ->with('outputPath', config('apidoc.output'))
-            ->with('showPostmanCollectionButton', config('apidoc.postman.enabled') ?? config('apidoc.postman'))
+            ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection())
             ->with('parsedRoutes', $parsedRouteOutput);
 
         if (! is_dir($outputPath)) {
@@ -153,7 +153,7 @@ class GenerateDocumentation extends Command
             ->with('prependMd', $prependFileContents)
             ->with('appendMd', $appendFileContents)
             ->with('outputPath', config('apidoc.output'))
-            ->with('showPostmanCollectionButton', config('apidoc.postman.enabled') ?? config('apidoc.postman'))
+            ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection())
             ->with('parsedRoutes', $parsedRouteOutput);
 
         file_put_contents($compareFile, $compareMarkdown);
@@ -166,7 +166,7 @@ class GenerateDocumentation extends Command
 
         $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
 
-        if (config('apidoc.postman.enabled') ?? config('apidoc.postman')) {
+        if ($this->shouldGeneratePostmanCollection()) {
             $this->info('Generating Postman collection');
 
             file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes));
@@ -257,4 +257,14 @@ class GenerateDocumentation extends Command
 
         return $writer->getCollection();
     }
+
+    /**
+     * Checks config if it should generate Postman collection.
+     *
+     * @return boolean
+     */
+    private function shouldGeneratePostmanCollection()
+    {
+        return config('apidoc.postman.enabled', is_bool(config('apidoc.postman')) ? config('apidoc.postman') : false);
+    }
 }