From 5520b59f167e7397c5c5c3fda065fed9c76ce193 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Wed, 15 May 2024 10:11:57 +0300 Subject: [PATCH] fix a horrible thing --- src/GeneratorConfig.php | 6 ++++-- src/Infer/Reflector/MethodReflector.php | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/GeneratorConfig.php b/src/GeneratorConfig.php index 59695882..6a852ac1 100644 --- a/src/GeneratorConfig.php +++ b/src/GeneratorConfig.php @@ -14,7 +14,7 @@ public function __construct( private ?Closure $routeResolver = null, private ?Closure $afterOpenApiGenerated = null, ) { - $this->routeResolver = $this->routeResolver ?? function (Route $route) { + $this->routeResolver = $this->routeResolver ?: function (Route $route) { $expectedDomain = $this->get('api_domain'); return Str::startsWith($route->uri, $this->get('api_path', 'api')) @@ -35,7 +35,9 @@ public function routes(?Closure $routeResolver = null) return $this->routeResolver; } - $this->routeResolver = $routeResolver; + if ($routeResolver) { + $this->routeResolver = $routeResolver; + } return $this; } diff --git a/src/Infer/Reflector/MethodReflector.php b/src/Infer/Reflector/MethodReflector.php index dcb0fff8..eff462ae 100644 --- a/src/Infer/Reflector/MethodReflector.php +++ b/src/Infer/Reflector/MethodReflector.php @@ -48,7 +48,10 @@ public function getReflection(): ReflectionMethod return new ReflectionMethod($this->className, $this->name); } - public function getAstNode(): ClassMethod + /** + * @todo: Think if this method can actually return `null` or it should fail. + */ + public function getAstNode(): ?ClassMethod { if (! $this->methodNode) { $className = class_basename($this->className);