Skip to content

Commit

Permalink
Merge pull request #456 from michaeljennings/master
Browse files Browse the repository at this point in the history
Update grouped endpoint classes to be easier to extend
  • Loading branch information
shalvah authored Mar 31, 2022
2 parents 4e3d72f + 4240569 commit 961a873
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/GroupedEndpoints/GroupedEndpointsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
21 changes: 19 additions & 2 deletions src/GroupedEndpoints/GroupedEndpointsFromApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ protected function extractEndpointsInfoAndWriteToDisk(RouteMatcherInterface $rou
*/
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) {
Expand Down Expand Up @@ -274,7 +275,23 @@ private function isRouteHiddenFromDocumentation(array $routeControllerAndMethod)

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);
}
}

0 comments on commit 961a873

Please sign in to comment.