Skip to content

Commit

Permalink
Merge pull request #299 from lptn/fix-244-performance
Browse files Browse the repository at this point in the history
Register handler for Models only (bypass an issue in ide-helper)
  • Loading branch information
lptn authored Jan 26, 2023
2 parents 19dddc3 + 579d83a commit a3a3e86
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
<exclude-pattern>tests/_run</exclude-pattern>
<exclude-pattern>tests/_support</exclude-pattern>
<exclude-pattern>tests/Support/</exclude-pattern><!-- This code mostly copy-paste from https://github.com/psalm/codeception-psalm-module and thus may have different coding-style rules -->
<exclude-pattern>tests/Unit/Handlers/Eloquent/Schema/migrations</exclude-pattern>
</ruleset>
17 changes: 16 additions & 1 deletion src/Fakes/FakeModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -32,7 +34,20 @@ public function __construct(Filesystem $files, SchemaAggregator $schema)
/** @return list<class-string<\Illuminate\Database\Eloquent\Model>> */
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];
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Handlers/Eloquent/Schema/DefaultUserTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit a3a3e86

Please sign in to comment.