Browse Source

Merge pull request #456 from michaeljennings/master

Update grouped endpoint classes to be easier to extend
Shalvah 3 năm trước cách đây
mục cha
commit
961a873b2e

+ 16 - 3
src/GroupedEndpoints/GroupedEndpointsFactory.php

@@ -11,13 +11,26 @@ class GroupedEndpointsFactory
     public function make(GenerateDocumentation $command, RouteMatcherInterface $routeMatcher): GroupedEndpointsContract
     {
         if ($command->isForcing()) {
-            return new GroupedEndpointsFromApp($command, $routeMatcher, false);
+            return $this->makeGroupedEndpointsFromApp($command, $routeMatcher, false);
         }
 
         if ($command->shouldExtract()) {
-            return new GroupedEndpointsFromApp($command, $routeMatcher, true);
+            return $this->makeGroupedEndpointsFromApp($command, $routeMatcher, true);
         }
 
-        return new GroupedEndpointsFromCamelDir;
+        return $this->makeGroupedEndpointsFromCamelDir();
+    }
+
+    protected function makeGroupedEndpointsFromApp(
+        GenerateDocumentation $command,
+        RouteMatcherInterface $routeMatcher,
+        bool $preserveUserChanges
+    ): GroupedEndpointsFromApp {
+        return new GroupedEndpointsFromApp($command, $routeMatcher, $preserveUserChanges);
+    }
+
+    protected function makeGroupedEndpointsFromCamelDir(): GroupedEndpointsFromCamelDir
+    {
+        return new GroupedEndpointsFromCamelDir();
     }
 }

+ 19 - 2
src/GroupedEndpoints/GroupedEndpointsFromApp.php

@@ -90,7 +90,8 @@ class GroupedEndpointsFromApp implements GroupedEndpointsContract
      */
     private function extractEndpointsInfoFromLaravelApp(array $matches, array $cachedEndpoints, array $latestEndpointsData, array $groups): array
     {
-        $generator = new Extractor($this->docConfig);
+        $generator = $this->makeExtractor();
+
         $parsedEndpoints = [];
 
         foreach ($matches as $routeItem) {
@@ -274,7 +275,23 @@ class GroupedEndpointsFromApp implements GroupedEndpointsContract
 
     protected function extractAndWriteApiDetailsToDisk(): void
     {
-        $apiDetails = new ApiDetails($this->docConfig, !$this->command->option('force'));
+        $apiDetails = $this->makeApiDetails();
+
         $apiDetails->writeMarkdownFiles();
     }
+
+    protected function makeApiDetails(): ApiDetails
+    {
+        return new ApiDetails($this->docConfig, !$this->command->option('force'));
+    }
+
+    /**
+     * Make a new extractor.
+     *
+     * @return Extractor
+     */
+    protected function makeExtractor(): Extractor
+    {
+        return new Extractor($this->docConfig);
+    }
 }