Skip to content

Commit 0f45eff

Browse files
committed
rector
1 parent 61ca2e1 commit 0f45eff

File tree

11 files changed

+36
-24
lines changed

11 files changed

+36
-24
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
"require-dev": {
2525
"driftingly/rector-laravel": "^2.0.2",
2626
"larastan/larastan": "^3.1",
27-
"laravel/pint": "^1.21.0",
27+
"laravel/pint": "^1.21.1",
2828
"nunomaduro/collision": "^8.6.1",
29-
"orchestra/testbench": "^9.11 || ^10.0",
29+
"orchestra/testbench": "^9.11 || ^10.1",
3030
"phpstan/extension-installer": "^1.4.3",
3131
"phpstan/phpstan-deprecation-rules": "^2.0.1",
3232
"phpstan/phpstan-phpunit": "^2.0.4",
3333
"phpstan/phpstan-strict-rules": "^2.0.3",
34-
"phpunit/phpunit": "^11.5.10",
34+
"phpunit/phpunit": "^11.5.12",
3535
"psr/log": "^3.0.2",
36-
"rector/rector": "^2.0.9",
36+
"rector/rector": "^2.0.10",
3737
"sentry/sentry": "^4.10.0",
3838
"symfony/http-client": "^7.2.4"
3939
},

rector.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,23 @@
55
use Rector\Config\RectorConfig;
66
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
77
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
8+
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector;
89
use RectorLaravel\Set\LaravelSetList;
910

1011
return RectorConfig::configure()
11-
->withPreparedSets()
12+
->withPreparedSets(
13+
deadCode: true,
14+
codeQuality: true,
15+
codingStyle: true,
16+
typeDeclarations: true,
17+
privatization: true,
18+
naming: false,
19+
instanceOf: true,
20+
earlyReturn: true,
21+
strictBooleans: true,
22+
carbon: true,
23+
phpunitCodeQuality: true,
24+
)
1225
->withSets([
1326
LaravelSetList::LARAVEL_110,
1427
])
@@ -26,4 +39,5 @@
2639
StringClassNameToClassConstantRector::class => [
2740
'src/Client/ElasticaClient.php',
2841
],
42+
AssertCountWithZeroToAssertEmptyRector::class,
2943
]);

src/Commands/DeleteCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function handle(): int
3232
if (! $client->exists()) {
3333
continue;
3434
}
35+
3536
$this->info($index);
3637

3738
foreach ($client->getAliases() as $alias) {

src/Events/EventHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function subscribe(Dispatcher $events): void
2020
collect(ModelEventListener::EVENTS)
2121
->map(fn (string $name): string => sprintf('eloquent.%s:*', $name))
2222
->toArray(),
23-
function ($event, $models) {
23+
function ($event, $models): void {
2424
if (! $this->elasticaClient->listensToEvents()) {
2525
return;
2626
}

src/Index/AbstractIndex.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323

2424
abstract class AbstractIndex implements IndexInterface
2525
{
26-
public function __construct(
27-
protected ElasticaClient $client
28-
) {
29-
$this->client = $client;
30-
}
26+
public function __construct(protected ElasticaClient $client) {}
3127

3228
public function getMapping(): array
3329
{

src/Jobs/PopulateBatchIndex.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public function handle(): void
4949
$esDocuments[] = $record->toElasticaDocument($this->indexConfig);
5050
}
5151

52-
if (count($esDocuments) === 0) {
52+
if ($esDocuments === []) {
5353
return;
5454
}
5555

5656
try {
5757
$this->index->addDocuments($esDocuments);
58-
} catch (Throwable $th) {
58+
} catch (Throwable $throwable) {
5959
if (! $this->indexConfig->ingoreIndexingErrors()) {
60-
throw $th;
60+
throw $throwable;
6161
}
6262
}
6363
}

src/Jobs/SetupIndex.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function handle(ElasticaClient $elastica): void
2626
if ($this->batch()?->cancelled() === true) {
2727
return;
2828
}
29+
2930
$this->migrate($elastica);
3031
$this->cleanup($elastica);
3132
$this->setup($elastica);
@@ -42,7 +43,7 @@ private function migrate(ElasticaClient $elastica): void
4243
try {
4344
$response = ElasticsearchResponse::getResponse($elastica->getClient()->indices()->existsAlias(['name' => $this->indexConfig->getName()]))->asBool();
4445
} catch (ElasticaException) {
45-
if ($index->exists() && count($index->getAliases()) === 0) {
46+
if ($index->exists() && $index->getAliases() === []) {
4647
$index->delete();
4748
}
4849

tests/Feature/EventTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function test_event_create_disabled_listener(): void
2525
$this->index($this->productIndex);
2626
LaravelElasticaBridgeFacade::disableEventListener();
2727
$product = Product::factory()->create();
28-
$this->assertNull($this->productIndex->getDocumentInstance($product));
28+
$this->assertNotInstanceOf(\Elastica\Document::class, $this->productIndex->getDocumentInstance($product));
2929
}
3030

3131
public function test_event_create_enabled_listener(): void
@@ -44,7 +44,7 @@ public function test_event_update_disabled_listener(): void
4444
LaravelElasticaBridgeFacade::disableEventListener();
4545
$product = Product::all()->random();
4646
$oldName = $product->name;
47-
$newName = time();
47+
$newName = \Carbon\Carbon::now()->getTimestamp();
4848
$product->name = $newName;
4949
$this->assertSame($oldName, $this->productIndex->getDocumentInstance($product)->get('name'));
5050
$this->assertNotSame($oldName, $newName);
@@ -59,7 +59,7 @@ public function test_event_update_enabled_listener(): void
5959
LaravelElasticaBridgeFacade::enableEventListener();
6060
$product = Product::all()->random();
6161
$oldName = $product->name;
62-
$newName = time();
62+
$newName = \Carbon\Carbon::now()->getTimestamp();
6363
$product->name = $newName;
6464
$this->assertSame($oldName, $this->productIndex->getDocumentInstance($product)->get('name'));
6565
$this->assertNotSame($oldName, $newName);
@@ -82,15 +82,15 @@ public function test_event_delete_enabled_listener(): void
8282
LaravelElasticaBridgeFacade::enableEventListener();
8383
$product = Product::all()->random();
8484
$product->delete();
85-
$this->assertNull($this->productIndex->getDocumentInstance($product));
85+
$this->assertNotInstanceOf(\Elastica\Document::class, $this->productIndex->getDocumentInstance($product));
8686
}
8787

8888
public function test_event_delete_model_not_in_index(): void
8989
{
9090
$this->index($this->customerIndex);
9191
LaravelElasticaBridgeFacade::enableEventListener();
9292
$customer = Customer::findOrFail(1);
93-
$this->assertNull($this->customerIndex->getDocumentInstance($customer));
93+
$this->assertNotInstanceOf(\Elastica\Document::class, $this->customerIndex->getDocumentInstance($customer));
9494
$customer->delete();
9595
$this->assertNull($this->customerIndex->getDocumentInstance($customer));
9696
}

tests/Feature/TestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ protected function cleanupIndices(): void
5757
if ($index->getElasticaIndex()->hasAlias($index->getName())) {
5858
$index->getElasticaIndex()->removeAlias($index->getName());
5959
}
60+
6061
$active = $index->getBlueGreenActiveElasticaIndex();
6162
$inactive = $index->getBlueGreenInactiveElasticaIndex();
6263
if ($active->exists()) {
6364
$active->delete();
6465
}
66+
6567
if ($inactive->exists()) {
6668
$inactive->delete();
6769
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected function setUp(): void
2323
$this->setUpDatabase();
2424

2525
Factory::guessFactoryNamesUsing(
26-
fn (string $modelName) => 'Limenet\\LaravelElasticaBridge\\Tests\\Database\\Factories\\'.class_basename($modelName).'Factory'
26+
fn (string $modelName): string => 'Limenet\\LaravelElasticaBridge\\Tests\\Database\\Factories\\'.class_basename($modelName).'Factory'
2727
);
2828

2929
$this->seed(DatabaseSeeder::class);

0 commit comments

Comments
 (0)