diff --git a/phpcs.xml b/phpcs.xml index ef0e9943..c506fbe4 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -30,4 +30,5 @@ tests/_run tests/_support tests/Support/ + tests/Unit/Handlers/Eloquent/Schema/migrations diff --git a/src/Fakes/FakeModelsCommand.php b/src/Fakes/FakeModelsCommand.php index 4a33ed95..14a1c7bc 100644 --- a/src/Fakes/FakeModelsCommand.php +++ b/src/Fakes/FakeModelsCommand.php @@ -11,7 +11,9 @@ use function config; use function get_class; +use function is_a; use function in_array; +use function is_string; use function implode; /** @psalm-suppress PropertyNotSetInConstructor */ @@ -32,7 +34,20 @@ public function __construct(Filesystem $files, SchemaAggregator $schema) /** @return list> */ 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 [...$this->model_classes, ...$models]; } /** diff --git a/tests/Unit/Handlers/Eloquent/Schema/DefaultUserTableTest.php b/tests/Unit/Handlers/Eloquent/Schema/DefaultUserTableTest.php index db8ad57c..9d23671e 100644 --- a/tests/Unit/Handlers/Eloquent/Schema/DefaultUserTableTest.php +++ b/tests/Unit/Handlers/Eloquent/Schema/DefaultUserTableTest.php @@ -4,6 +4,8 @@ namespace Tests\Psalm\LaravelPlugin\Unit\Handlers\Eloquent\Schema; +use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator; + /** @covers \Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator */ final class DefaultUserTableTest extends AbstractSchemaAggregatorTest {