Skip to content

Commit

Permalink
Merge pull request #370 from alies-dev/optimize-1.x
Browse files Browse the repository at this point in the history
[1.x] Register handler for Models only (bypass an issue in ide-helper)
  • Loading branch information
alies-dev authored Mar 13, 2024
2 parents 44675f7 + 29ff76b commit 937f6cb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Fakes/FakeModelsCommandLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,33 @@
use function config;
use function get_class;
use function in_array;
use function is_string;
use function implode;
use function is_a;
use function array_merge;

trait FakeModelsCommandLogic
{
/** @var array<class-string> */
/** @var list<class-string<\Illuminate\Database\Eloquent\Model>> */
private $model_classes = [];

/** @return array<class-string> */
public function getModels(): array
{
return $this->model_classes + $this->loadModels();
if ($this->dirs === []) {
throw new \LogicException('Directories to scan models are not set.');
}

$models = [];

// Bypass an issue https://github.com/barryvdh/laravel-ide-helper/issues/1414
foreach ($this->loadModels() as $probably_model_fqcn) {
if (is_string($probably_model_fqcn) && is_a($probably_model_fqcn, Model::class, true)) {
$models[] = $probably_model_fqcn;
}
}

return array_merge($this->model_classes, $models);
}

/**
Expand Down

0 comments on commit 937f6cb

Please sign in to comment.