Skip to content

Commit

Permalink
Merge pull request #14 from matchish/analysis-8nEOx5
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
matchish authored May 6, 2019
2 parents a4f73e6 + 0985bea commit 575cdf4
Show file tree
Hide file tree
Showing 21 changed files with 36 additions and 51 deletions.
1 change: 1 addition & 0 deletions resources/lang/en/flush.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

return [
'done' => 'All [:searchable] records have been flushed.',
];
1 change: 1 addition & 0 deletions resources/lang/en/import.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

return [
'start' => 'Importing [:searchable]',
'done' => 'All [:searchable] records have been imported.',
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/FlushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function handle(): void
$searchableList->each(function ($searchable) {
$searchable::removeAllFromSearch();
$doneMessage = trans('scout::flush.done', [
'searchable' => $searchable
'searchable' => $searchable,
]);
$this->output->success($doneMessage);
});
Expand Down
5 changes: 2 additions & 3 deletions src/Console/Commands/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ private function searchableList($argument)
{
return collect($argument)->whenEmpty(function () {
$factory = new SearchableListFactory(app()->getNamespace(), app()->path());

return $factory->make();
});

}

private function import($searchable)
Expand All @@ -58,9 +58,8 @@ private function import($searchable)
->allOnConnection(config((new $searchable)->syncWithSearchUsing()));

$doneMessage = trans(config('scout.queue') ? 'scout::import.done.queue' : 'scout::import.done', [
'searchable' => $searchable
'searchable' => $searchable,
]);
$this->output->success($doneMessage);

}
}
7 changes: 3 additions & 4 deletions src/Console/Commands/ProgressBarFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Matchish\ScoutElasticSearch\Console\Commands;

use Symfony\Component\Console\Style\OutputStyle;
Expand All @@ -24,12 +23,12 @@ public function create(int $max = 0)
{
$bar = $this->output->createProgressBar($max);
$bar->setBarCharacter('<fg=green>⚬</>');
$bar->setEmptyBarCharacter("<fg=red>⚬</>");
$bar->setProgressCharacter("<fg=green>➤</>");
$bar->setEmptyBarCharacter('<fg=red>⚬</>');
$bar->setProgressCharacter('<fg=green>➤</>');
$bar->setFormat(
"%message%\n%current%/%max% [%bar%] %percent:3s%%\n"
);

return $bar;
}

}
1 change: 0 additions & 1 deletion src/Engines/ElasticSearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Laravel\Scout\Builder as BaseBuilder;
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
use Matchish\ScoutElasticSearch\ElasticSearch\Index;
use Matchish\ScoutElasticSearch\Pipelines\ImportPipeline;
use Matchish\ScoutElasticSearch\ElasticSearch\Params\Bulk;
use Matchish\ScoutElasticSearch\ElasticSearch\SearchFactory;
use Matchish\ScoutElasticSearch\ElasticSearch\SearchResults;
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function handle(Client $elasticsearch): void
$stages = $this->stages();
$estimate = $stages->sum->estimate();
$this->progressBar()->setMaxSteps($estimate);
$stages->each(function ($stage) use ($elasticsearch){
$stages->each(function ($stage) use ($elasticsearch) {
$this->progressBar()->setMessage($stage->title());
$stage->handle($elasticsearch);
$this->progressBar()->advance($stage->estimate());
Expand Down
9 changes: 3 additions & 6 deletions src/Jobs/ImportStages.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<?php


namespace Matchish\ScoutElasticSearch\Jobs;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Matchish\ScoutElasticSearch\ElasticSearch\Index;
use Matchish\ScoutElasticSearch\Jobs\Stages\CleanUp;
use Matchish\ScoutElasticSearch\Jobs\Stages\CreateWriteIndex;
use Matchish\ScoutElasticSearch\Jobs\Stages\PullFromSource;
use Matchish\ScoutElasticSearch\Jobs\Stages\RefreshIndex;
use Matchish\ScoutElasticSearch\Jobs\Stages\PullFromSource;
use Matchish\ScoutElasticSearch\Jobs\Stages\CreateWriteIndex;
use Matchish\ScoutElasticSearch\Jobs\Stages\SwitchToNewAndRemoveOldIndex;

class ImportStages extends Collection
{

/**
* @param Model $searchable
* @return Collection
Expand Down
6 changes: 1 addition & 5 deletions src/Jobs/QueueableJob.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<?php


namespace Matchish\ScoutElasticSearch\Jobs;


use Elasticsearch\Client;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Matchish\ScoutElasticSearch\ProgressReportable;

class QueueableJob implements ShouldQueue
class QueueableJob implements ShouldQueue
{
use Queueable;
use ProgressReportable;

public function handle()
{

}
}
5 changes: 2 additions & 3 deletions src/Jobs/Stages/CleanUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
namespace Matchish\ScoutElasticSearch\Jobs\Stages;

use Elasticsearch\Client;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;
use Elasticsearch\Common\Exceptions\Missing404Exception;
use Matchish\ScoutElasticSearch\ElasticSearch\Params\Indices\Delete as DeleteIndexParams;
use Matchish\ScoutElasticSearch\ElasticSearch\Params\Indices\Alias\Get as GetAliasParams;
use Matchish\ScoutElasticSearch\ElasticSearch\Params\Indices\Delete as DeleteIndexParams;

/**
* @internal
*/
final class CleanUp
{

/**
* @var Model
*/
Expand Down
4 changes: 1 addition & 3 deletions src/Jobs/Stages/CreateWriteIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Matchish\ScoutElasticSearch\Jobs\Stages;

use Elasticsearch\Client;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;
use Matchish\ScoutElasticSearch\ElasticSearch\Index;
use Matchish\ScoutElasticSearch\ElasticSearch\WriteAlias;
use Matchish\ScoutElasticSearch\ElasticSearch\DefaultAlias;
Expand Down Expand Up @@ -35,7 +35,6 @@ public function __construct(Model $searchable, Index $index)
}

public function handle(Client $elasticsearch): void

{
/** @var Searchable $searchable */
$searchable = $this->searchable;
Expand All @@ -58,5 +57,4 @@ public function estimate(): int
{
return 1;
}

}
2 changes: 2 additions & 0 deletions src/Jobs/Stages/PullFromSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public static function chunked(Model $searchable): Collection
if ($totalSearchables) {
$chunkSize = (int) config('scout.chunk.searchable', self::DEFAULT_CHUNK_SIZE);
$totalChunks = (int) ceil($totalSearchables / $chunkSize);

return collect(range(1, $totalChunks))->map(function ($page) use ($query, $chunkSize) {
$clone = (clone $query)->forPage($page, $chunkSize);

return new static($clone);
});
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/Jobs/Stages/SwitchToNewAndRemoveOldIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Matchish\ScoutElasticSearch\Jobs\Stages;

use Elasticsearch\Client;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;
use Matchish\ScoutElasticSearch\ElasticSearch\Index;
use Matchish\ScoutElasticSearch\ElasticSearch\Params\Indices\Alias\Get;
use Matchish\ScoutElasticSearch\ElasticSearch\Params\Indices\Alias\Update;
Expand Down Expand Up @@ -33,10 +33,10 @@ public function __construct(Model $searchable, Index $index)
}

public function handle(Client $elasticsearch): void
{
/** @var Searchable $searchable */
$searchable = $this->searchable;
$params = Get::anyIndex($searchable->searchableAs());
{
/** @var Searchable $searchable */
$searchable = $this->searchable;
$params = Get::anyIndex($searchable->searchableAs());
$response = $elasticsearch->indices()->getAliases($params->toArray());

$params = new Update();
Expand All @@ -47,7 +47,7 @@ public function handle(Client $elasticsearch): void
$params->add((string) $indexName, $searchable->searchableAs());
}
}
$elasticsearch->indices()->updateAliases($params->toArray());
$elasticsearch->indices()->updateAliases($params->toArray());
}

public function estimate(): int
Expand Down
2 changes: 0 additions & 2 deletions src/ProgressReportable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Matchish\ScoutElasticSearch;

use Symfony\Component\Console\Output\NullOutput;
Expand All @@ -19,5 +18,4 @@ private function progressBar(): ProgressBar
{
return $this->progressBar ?: new ProgressBar(new NullOutput());
}

}
8 changes: 4 additions & 4 deletions tests/Feature/ImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Tests\Feature;

use App\Book;
use App\Product;
use stdClass;
use App\Product;
use Tests\IntegrationTestCase;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Console\Output\BufferedOutput;
Expand Down Expand Up @@ -126,13 +126,13 @@ public function test_progress_report()
trans('scout::import.start', ['searchable' => Product::class]),
trim($output[0]));
$this->assertEquals(
'[OK] ' . trans('scout::import.done', ['searchable' => Product::class]),
'[OK] '.trans('scout::import.done', ['searchable' => Product::class]),
trim($output[2]));
$this->assertEquals(
trans('scout::import.start', ['searchable' => Book::class]),
trim($output[4]));
$this->assertEquals(
'[OK] ' . trans('scout::import.done', ['searchable' => Book::class]),
'[OK] '.trans('scout::import.done', ['searchable' => Book::class]),
trim($output[6]));
}

Expand All @@ -148,7 +148,7 @@ public function test_progress_report_in_queue()
trans('scout::import.start', ['searchable' => Product::class]),
trim($output[0]));
$this->assertEquals(
'[OK] ' . trans('scout::import.done.queue', ['searchable' => Product::class]),
'[OK] '.trans('scout::import.done.queue', ['searchable' => Product::class]),
trim($output[2]));
}
}
2 changes: 1 addition & 1 deletion tests/Feature/ScoutElasticSearchServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Matchish\ScoutElasticSearch;

use Elasticsearch\Client;
use Tests\TestCase;
use Elasticsearch\Client;

class ScoutElasticSearchServiceProviderTest extends TestCase
{
Expand Down
3 changes: 1 addition & 2 deletions tests/Integration/Jobs/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace Tests\Integration\Jobs;

use App\Product;
use Tests\IntegrationTestCase;
use Illuminate\Console\OutputStyle;
use Matchish\ScoutElasticSearch\Jobs\Import;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
use Tests\IntegrationTestCase;

class ImportTest extends IntegrationTestCase
{

public function test_progress_report()
{
$dispatcher = Product::getEventDispatcher();
Expand Down
3 changes: 1 addition & 2 deletions tests/Integration/Jobs/Stages/CleanUpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Tests\Integration\Jobs\Stages;

use App\Product;
use stdClass;
use App\Product;
use Tests\IntegrationTestCase;
use Matchish\ScoutElasticSearch\Jobs\Stages\CleanUp;

Expand Down Expand Up @@ -32,5 +32,4 @@ public function test_remove_write_index()
$this->assertFalse($writeIndexExist);
$this->assertTrue($readIndexExist);
}

}
4 changes: 1 addition & 3 deletions tests/Integration/Jobs/Stages/PullFromSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Tests\Integration\Jobs\Stages;

use App\Product;
use stdClass;
use App\Product;
use Tests\IntegrationTestCase;
use Matchish\ScoutElasticSearch\Jobs\Stages\PullFromSource;

Expand Down Expand Up @@ -167,7 +167,6 @@ public function test_pull_soft_deleted()

public function test_no_searchables_no_chunks()
{

$stages = PullFromSource::chunked(new Product());

$this->assertEquals(0, $stages->count());
Expand Down Expand Up @@ -201,5 +200,4 @@ public function test_chunked_pull_only_one_page()

$this->assertEquals(3, $response['hits']['total']);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Tests\Integration\Jobs\Stages;

use App\Product;
use stdClass;
use App\Product;
use Tests\IntegrationTestCase;
use Matchish\ScoutElasticSearch\ElasticSearch\Index;
use Matchish\ScoutElasticSearch\Jobs\Stages\SwitchToNewAndRemoveOldIndex;
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Jobs/ImportStagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace Tests\Unit\Jobs;

use App\Product;
use Tests\TestCase;
use Matchish\ScoutElasticSearch\Jobs\ImportStages;
use Matchish\ScoutElasticSearch\Jobs\Stages\CleanUp;
use Matchish\ScoutElasticSearch\Jobs\Stages\CreateWriteIndex;
use Matchish\ScoutElasticSearch\Jobs\Stages\PullFromSource;
use Matchish\ScoutElasticSearch\Jobs\Stages\RefreshIndex;
use Matchish\ScoutElasticSearch\Jobs\Stages\PullFromSource;
use Matchish\ScoutElasticSearch\Jobs\Stages\CreateWriteIndex;
use Matchish\ScoutElasticSearch\Jobs\Stages\SwitchToNewAndRemoveOldIndex;
use Tests\TestCase;

class ImportStagesTest extends TestCase
{
Expand Down

0 comments on commit 575cdf4

Please sign in to comment.