Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion config/ide-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
|
*/

'filename' => '_ide_helper.php',
'filename' => '_ide_helper.php',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice


/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -155,6 +155,19 @@

],

/*
|--------------------------------------------------------------------------
| Models to silence warnings
|--------------------------------------------------------------------------
|
| Define which models should have warnings silenced
|
*/

'silenced_models' => [

],

/*
|--------------------------------------------------------------------------
| Models hooks
Expand Down
33 changes: 32 additions & 1 deletion src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ protected function generateDocs($loadModels, $ignore = '')
$this->laravel['config']->get('ide-helper.ignored_models', [])
);

$skippedGeneratingTablePropertiesForModels = [];

foreach ($models as $name) {
if (in_array($name, $ignore)) {
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
Expand Down Expand Up @@ -280,7 +282,20 @@ protected function generateDocs($loadModels, $ignore = '')

$model = $this->laravel->make($name);

$this->getPropertiesFromTable($model);
try {
$this->getPropertiesFromTable($model);
} catch (Throwable $e) {
$modelName = $model::class;

if ($this->warningsAreAllowedForForModel($model)) {
$connectionName = $model->getConnectionName() ?? $this->laravel['config']->get('database.default');
$driver = $model->getConnection()::class;

$this->warn("Could not get table properties for model [{$modelName}] using connection [{$connectionName}]. The underlying database driver [{$driver}] may not be supported.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this is already a long text, we should not swallow that actual content of $e, I suggest something like appending: … be supported: " . get_class($e) . ' ' . $e->getMessage()


$skippedGeneratingTablePropertiesForModels[] = $model;
}
}

if (method_exists($model, 'getCasts')) {
$this->castPropertiesType($model);
Expand All @@ -304,6 +319,16 @@ protected function generateDocs($loadModels, $ignore = '')
}
}

if (! empty($skippedGeneratingTablePropertiesForModels)) {
$classes = collect($skippedGeneratingTablePropertiesForModels)
->map(fn ($model) => ' • ' . $model::class);
$this->warn('Could not inspect table properties for some models. See output above for any warnings');
$this->warn('Models without table inspection:');
$this->newLine();
$this->warn($classes->implode(PHP_EOL));
$this->newLine();
}

return $output;
}

Expand Down Expand Up @@ -1626,4 +1651,10 @@ protected function setForeignKeys($schema, $table)
}
}
}

protected function warningsAreAllowedForForModel(Model $model): bool
{
return collect($this->laravel['config']->get('ide-helper.silenced_models'))
->doesntContain($model::class);
}
}