From 1d392f6088063ba526280a1d8666c41c3178e0e1 Mon Sep 17 00:00:00 2001 From: zigzagdev Date: Wed, 13 May 2026 23:18:18 +0900 Subject: [PATCH 1/3] chore: remove duplicate semicolon --- src/RelationFinder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RelationFinder.php b/src/RelationFinder.php index 7c8f46d..890104a 100644 --- a/src/RelationFinder.php +++ b/src/RelationFinder.php @@ -31,7 +31,7 @@ public function getModelRelations(string $model) $methods = Collection::make($class->getMethods(ReflectionMethod::IS_PUBLIC)) ->merge($traitMethods) ->reject(function (ReflectionMethod $method) use ($model) { - return $method->class !== $model || $method->getNumberOfParameters() > 0 || $method->isStatic();; + return $method->class !== $model || $method->getNumberOfParameters() > 0 || $method->isStatic(); }); $relations = Collection::make(); From 2d513a84923ae25e7a20b09a3952d694b503a72b Mon Sep 17 00:00:00 2001 From: zigzagdev Date: Wed, 13 May 2026 23:20:30 +0900 Subject: [PATCH 2/3] feat: add opt-in debug logging via debug_relations config --- config/config.php | 7 +++++++ src/RelationFinder.php | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/config/config.php b/config/config.php index 65128f6..8d7c1b1 100644 --- a/config/config.php +++ b/config/config.php @@ -10,6 +10,13 @@ base_path('app' . DIRECTORY_SEPARATOR . 'Models'), ], + /* + * If you want to enable debug logging when a model method cannot be + * analyzed during relation discovery, set this to true. + * Useful for troubleshooting unexpected ERD generation issues. + */ + // 'debug_relations' => true, + /* * If you want to ignore complete models or certain relations of a specific model, * you can specify them here. diff --git a/src/RelationFinder.php b/src/RelationFinder.php index 890104a..2657bc5 100644 --- a/src/RelationFinder.php +++ b/src/RelationFinder.php @@ -9,6 +9,7 @@ use ReflectionClass; use ReflectionMethod; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Log; class RelationFinder @@ -95,7 +96,13 @@ protected function getRelationshipFromMethodAndModel(ReflectionMethod $method, s ) ]; } - } catch (\Throwable $e) {} + } catch (\Throwable $e) { + // Non-relation methods may throw when invoked; this is expected. + // To enable debug logging, set 'debug_relations' => true in config/erd-generator.php + if (config('erd-generator.debug_relations', false)) { + Log::debug("Could not analyze method {$method->getName()} on {$model}: {$e->getMessage()}"); + } + } return null; } From 2949a6ac4e433d0f849ea1ff05ef2b10b3146e3e Mon Sep 17 00:00:00 2001 From: zigzagdev Date: Thu, 14 May 2026 10:05:07 +0900 Subject: [PATCH 3/3] chore: add test --- tests/GetModelRelationsTest.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/GetModelRelationsTest.php b/tests/GetModelRelationsTest.php index 81fdaaa..a92acdc 100644 --- a/tests/GetModelRelationsTest.php +++ b/tests/GetModelRelationsTest.php @@ -7,14 +7,14 @@ use BeyondCode\ErdGenerator\Tests\Models\Avatar; use BeyondCode\ErdGenerator\Tests\Models\Comment; use BeyondCode\ErdGenerator\Tests\Models\Post; +use BeyondCode\ErdGenerator\Tests\Fixtures\ModelWithThrowingMethod; use BeyondCode\ErdGenerator\Tests\Models\User; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Log; use PHPUnit\Framework\Attributes\Test; - class GetModelRelationsTest extends TestCase { - #[Test] public function it_can_find_model_relations() { @@ -69,4 +69,24 @@ public function it_will_ignore_a_relation_if_it_is_excluded_on_config() $this->assertNull(Arr::get($relations, 'posts')); } + #[Test] + public function it_logs_debug_when_method_throws_exception() + { + Log::spy(); + + $finder = new RelationFinder(); + + $relations = $finder->getModelRelations(ModelWithThrowingMethod::class); + + $this->assertCount(0, $relations); + + Log::shouldHaveReceived('debug') + ->withArgs(function (string $message) { + return str_contains($message, 'Could not analyze method') + && str_contains($message, 'throwingMethod') + && str_contains($message, 'Something went wrong'); + }) + ->once(); + } + }