Skip to content

Commit

Permalink
refactor: fix PHPStan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed Feb 21, 2025
1 parent ca2cf5b commit 309c8d8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Commands/ElasticsearchCreateIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class ElasticsearchCreateIndex extends Command

protected $description = 'Creates index in elasticsearch';

/**
* @return array<string, mixed>
*/
public function getIndexMapping(): array
{
return app()->bound(IndexMappingBuilderInterface::class) ?
Expand Down
15 changes: 11 additions & 4 deletions src/Commands/ElasticsearchRefreshIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
namespace Swis\Laravel\Elasticsearch\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Swis\Laravel\Elasticsearch\Contracts\IndexableInterface;

/**
* @phpstan-type IndexableModel \Illuminate\Database\Eloquent\Model&\Swis\Laravel\Elasticsearch\Contracts\IndexableInterface
*/
class ElasticsearchRefreshIndex extends Command
{
protected $signature = 'elasticsearch:refresh-index';
Expand All @@ -19,12 +22,16 @@ public function handle(): int
$this->call(ElasticsearchDeleteIndex::class);
$this->call(ElasticsearchCreateIndex::class);

/** @var class-string<\Illuminate\Database\Eloquent\Model>[] $models */
/** @var class-string<IndexableModel>[] $models */
$models = config('elasticsearch.models');

$models = collect($models)
->filter(fn (string $model) => is_a($model, IndexableInterface::class, true))
->flatMap(fn (string $model): Collection => $model::all())
->filter(fn (string $model): bool => is_a($model, Model::class, true) && is_a($model, IndexableInterface::class, true))
/**
* @param class-string<IndexableModel> $model
* @return array<int, IndexableModel>
*/
->flatMap(fn (string $model): array => $model::all()->all())
->each(fn (IndexableInterface $model) => $model->index());

$this->info(sprintf('Dispatched %d index jobs', $models->count()));
Expand Down
3 changes: 3 additions & 0 deletions src/Contracts/IndexMappingBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

interface IndexMappingBuilderInterface
{
/**
* @return array<string, mixed>
*/
public function indexMapping(): array;
}
3 changes: 3 additions & 0 deletions src/Contracts/SearchResultInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

interface SearchResultInterface
{
/**
* @param array<string, mixed> $values
*/
public static function fromElasticsearchResult(array $values): self;
}

0 comments on commit 309c8d8

Please sign in to comment.