mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Give feedback when a relation can't be resolved (#1052)
Improves https://github.com/barryvdh/laravel-ide-helper/pull/1017 slightly
This commit is contained in:
@@ -38,6 +38,7 @@ use ReflectionObject;
|
|||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A command to generate autocomplete information for your IDE
|
* A command to generate autocomplete information for your IDE
|
||||||
@@ -277,7 +278,7 @@ class ModelsCommand extends Command
|
|||||||
$output .= $this->createPhpDocs($name);
|
$output .= $this->createPhpDocs($name);
|
||||||
$ignore[] = $name;
|
$ignore[] = $name;
|
||||||
$this->nullableColumns = [];
|
$this->nullableColumns = [];
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$this->error('Exception: ' . $e->getMessage() .
|
$this->error('Exception: ' . $e->getMessage() .
|
||||||
"\nCould not analyze class $name.\n\nTrace:\n" .
|
"\nCould not analyze class $name.\n\nTrace:\n" .
|
||||||
$e->getTraceAsString());
|
$e->getTraceAsString());
|
||||||
@@ -601,7 +602,9 @@ class ModelsCommand extends Command
|
|||||||
$relationObj = Relation::noConstraints(function () use ($model, $method) {
|
$relationObj = Relation::noConstraints(function () use ($model, $method) {
|
||||||
try {
|
try {
|
||||||
return $model->$method();
|
return $model->$method();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
|
$this->warn(sprintf('Error resolving relation model of %s:%s() : %s', get_class($model), $method, $e->getMessage()));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,8 +17,15 @@ class Test extends AbstractModelsCommand
|
|||||||
'--write' => true,
|
'--write' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$errors = <<<TXT
|
||||||
|
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Trying to get property 'created_at' of non-object
|
||||||
|
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Trying to get property 'created_at' of non-object
|
||||||
|
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Trying to get property 'created_at' of non-object
|
||||||
|
TXT;
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
|
$this->assertStringContainsString($errors, $tester->getDisplay());
|
||||||
$this->assertMatchesMockedSnapshot();
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user