diff --git a/config/api-postman.php b/config/api-postman.php index c83850b..80372c8 100644 --- a/config/api-postman.php +++ b/config/api-postman.php @@ -86,5 +86,4 @@ * Specify the configured disk for storing the postman collection file. */ 'disk' => 'local', - ]; diff --git a/src/Commands/ExportPostmanCommand.php b/src/Commands/ExportPostmanCommand.php index 932fd0a..165ac38 100644 --- a/src/Commands/ExportPostmanCommand.php +++ b/src/Commands/ExportPostmanCommand.php @@ -71,17 +71,15 @@ public function handle(): void $requestRules = []; - if ($this->config['enable_formdata']) { - $routeAction = $route->getAction(); - - if ($routeAction['uses'] instanceof Closure) { - $reflectionMethod = new ReflectionFunction($routeAction['uses']); - } else { - $routeData = explode('@', $routeAction['uses']); - $reflection = new ReflectionClass($routeData[0]); - $reflectionMethod = $reflection->getMethod($routeData[1]); - } + $routeAction = $route->getAction(); + + $reflectionMethod = $this->getReflectionMethod($routeAction); + + if (! $reflectionMethod) { + continue; + } + if ($this->config['enable_formdata']) { $rulesParameter = null; foreach ($reflectionMethod->getParameters() as $parameter) { @@ -143,6 +141,22 @@ public function handle(): void $this->info("Postman Collection Exported: $exportName"); } + protected function getReflectionMethod(array $routeAction): ?object + { + if ($routeAction['uses'] instanceof Closure) { + return new ReflectionFunction($routeAction['uses']); + } + + $routeData = explode('@', $routeAction['uses']); + $reflection = new ReflectionClass($routeData[0]); + + if (! $reflection->hasMethod($routeData[1])) { + return null; + } + + return $reflection->getMethod($routeData[1]); + } + protected function buildTree(array &$routes, array $segments, array $request): void { $parent = &$routes;