Skip to content

Commit c11ff2d

Browse files
committed
psalm fixes
1 parent 7b14654 commit c11ff2d

File tree

8 files changed

+36
-9
lines changed

8 files changed

+36
-9
lines changed

psalm-baseline.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="4.7.2@83a0325c0a95c0ab531d6b90c877068b464377b5">
3+
<file src="src/Commands/IndexCommand.php">
4+
<PossiblyInvalidArgument occurrences="1">
5+
<code>$this-&gt;argument('index')</code>
6+
</PossiblyInvalidArgument>
7+
</file>
8+
<file src="src/Jobs/PopulateBatchIndex.php">
9+
<PossiblyNullReference occurrences="1">
10+
<code>cancelled</code>
11+
</PossiblyNullReference>
12+
</file>
13+
<file src="src/Jobs/PopulateIndex.php">
14+
<PossiblyNullReference occurrences="2">
15+
<code>add</code>
16+
<code>cancelled</code>
17+
</PossiblyNullReference>
18+
</file>
19+
</files>

psalm.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="4"
3+
errorLevel="3"
44
findUnusedVariablesAndParams="true"
55
resolveFromConfigFile="true"
66
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
77
xmlns="https://getpsalm.org/schema/config"
88
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
9+
errorBaseline="psalm-baseline.xml"
910
>
1011
<projectFiles>
1112
<directory name="src"/>

src/Commands/IndexCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function handle()
6161
Bus::batch([
6262
[new PopulateIndex($indexConfig)],
6363
])
64-
->then(function (Batch $batch) use ($indexConfig): void {
64+
->then(function () use ($indexConfig): void {
6565
dispatch(new ActivateIndex($indexConfig));
6666
})
6767
->name('ES index: '.$indexConfig->getName())

src/Commands/StatusCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ protected function formatBytes(int $bytes): string
120120
$base = log($bytes, 1024);
121121
$suffixes = ['', 'K', 'M', 'G', 'T'];
122122

123-
return round(1024 ** ($base - floor($base)), 2).' '.$suffixes[floor($base)].'B';
123+
return round(1024 ** ($base - floor($base)), 2).' '.$suffixes[(int)floor($base)].'B';
124124
}
125125
}

src/Index/IndexInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getCreateArguments(): array;
7171
/**
7272
* Defines the types of documents found in this index. Array of classes implementing ElasticsearchableInterface.
7373
*
74-
* @return array<class-string<Model>> Class names of Model classes
74+
* @return array<string> Class names of Model classes
7575
*/
7676
public function getAllowedDocuments(): array;
7777

src/Jobs/PopulateBatchIndex.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Bus\Batchable;
99
use Illuminate\Bus\Queueable;
1010
use Illuminate\Contracts\Queue\ShouldQueue;
11+
use Illuminate\Database\Eloquent\Model;
1112
use Illuminate\Foundation\Bus\Dispatchable;
1213
use Illuminate\Queue\InteractsWithQueue;
1314
use Illuminate\Queue\SerializesModels;
@@ -52,9 +53,10 @@ public function handle(): void
5253
$esDocuments[] = $record->toElasticaDocument();
5354
}
5455

55-
if (count($esDocuments) > 0) {
56-
$this->index->addDocuments($esDocuments);
57-
$esDocuments = [];
56+
if (count($esDocuments) === 0) {
57+
return;
5858
}
59+
60+
$this->index->addDocuments($esDocuments);
5961
}
6062
}

src/Jobs/PopulateIndex.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,19 @@ public function handle(): void
3535
$index->delete();
3636
$index->create($this->indexConfig->getCreateArguments());
3737

38+
$jobs = [];
39+
3840
foreach ($this->indexConfig->getAllowedDocuments() as $indexDocument) {
3941
$modelCount = $indexDocument::count();
4042

4143
for ($batchNumber = 0; $batchNumber < ceil($modelCount / $this->indexConfig->getBatchSize()); $batchNumber++) {
42-
$this->batch()->add(new PopulateBatchIndex($index, $indexDocument, $this->indexConfig->getBatchSize(), $batchNumber * $this->indexConfig->getBatchSize()));
44+
$jobs[]=new PopulateBatchIndex($index, $indexDocument, $this->indexConfig->getBatchSize(), $batchNumber * $this->indexConfig->getBatchSize());
4345
}
4446
}
4547

48+
49+
$this->batch()->add($jobs);
50+
4651
$index->refresh();
4752
}
4853
}

src/LaravelElasticaBridgeServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function configurePackage(Package $package): void
2424
->hasCommands([IndexCommand::class,StatusCommand::class]);
2525
}
2626

27-
public function packageRegistered()
27+
public function packageRegistered():void
2828
{
2929
$this->app->singleton(ElasticaClient::class);
3030
$this->app->tag(config('elastica-bridge.indices'), 'elasticaBridgeIndices');

0 commit comments

Comments
 (0)