Skip to content

Commit

Permalink
Fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianaromagnoli authored and mmenozzi committed Nov 22, 2024
1 parent fe7f537 commit 949024f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
17 changes: 8 additions & 9 deletions src/Flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,17 @@ public function __construct(

public function boot(): void
{
$this->logger->info(
'Booting flow',
['flow' => $this->flowConfig->getDescription(), 'tube' => $this->flowConfig->getTube()]
);
Loop::defer(function () {
$this->logger->info(
'Booting flow',
['flow' => $this->flowConfig->getDescription(), 'tube' => $this->flowConfig->getTube()]
);

yield $this->producerInstance->boot();
});
foreach ($this->workerInstances as $workerInstance) {
Loop::defer(function () use ($workerInstance) {
foreach ($this->workerInstances as $workerInstance) {
yield $workerInstance->boot();
});
}
}
});
}

public function getCode(): string
Expand Down
24 changes: 14 additions & 10 deletions src/Service/ElasticSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,8 @@ public function indexExists(string $indexName): Amp\Promise
{
return Amp\call(function () use ($indexName) {
try {
$response = yield $this->client->existsIndex($indexName);
if ($response->getStatusCode() === 200) {
return true;
}
return false;
yield $this->client->existsIndex($indexName);
return true;
} catch (Error $error) {
if ($error->getCode() === 404) {
return false;
Expand All @@ -112,26 +109,33 @@ public function indexExists(string $indexName): Amp\Promise
});
}

/**
* @param array<array-key, mixed>|null $indexName
*/
public function setElasticSearchIndex(string $indexName): Amp\Promise
{
return $this->client->createIndex($indexName);
}


/**
* @param string $indexName
* @param array<string, mixed> $updateSettingsBody
*/
public function setElasticSearchIndexSettings(string $indexName, array $updateSettingsBody = null): Amp\Promise
{
return $this->client->updateIndexSettings($indexName, $updateSettingsBody);
}


/**
* @param string $indexName
* @param array<string, mixed> $updateMappingBody
*/
public function setElasticSearchIndexMapping(string $indexName, array $updateMappingBody = null): Amp\Promise
{
return $this->client->updateMappings($indexName, $updateMappingBody);
}

/**
* @param string $indexName
* @param array<string, mixed> $aliasBody
*/
public function setElasticSearchIndexAlias(string $indexName, string $aliasName, array $aliasBody = null): Amp\Promise
{
return $this->client->createOrUpdateAlias($indexName, $aliasName, $aliasBody);
Expand Down
2 changes: 1 addition & 1 deletion src/Service/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function boot(): Promise
);
}

if ($this->flowConfig->getElasticSearchIndexUpdateAliasesBody()) {
if ($this->flowConfig->getElasticSearchIndexUpdateAliasesBody() !== null) {
$elasticSearchIndexUpdateAliases = $this->flowConfig->getElasticSearchIndexUpdateAliasesBody();
foreach ($elasticSearchIndexUpdateAliases as $aliasName => $aliasBody) {
yield $this->elasticSearch->setElasticSearchIndexAlias(
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/ElasticSearchIndexingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function itUpdatesIndexSettingsAccordingToFlowConfigTest()
'flows' => [
self::FLOW_CODE => [
'description' => 'ElasticSearch Indexing Test Repeat Flow',
'es_index_settings' => ['index' => ['mapping' => ['total_fields' => ['limit' => 2000]]]],
'es_index_settings' => ['index' => ['mapping' => ['total_fields' => ['limit' => 3000]]]],
'producer' => ['service' => DummyFilesystemRepeatProducer::class],
'worker' => ['service' => DummyFilesystemWorker::class],
]
Expand Down Expand Up @@ -269,7 +269,7 @@ function ($log) {

Promise\wait($this->esClient->refresh());
$search = Promise\wait($this->esClient->uriSearchOneIndex(self::FLOW_CODE, ''));
$this->assertCount(1, $search['hits']['hits']);
$this->assertCount(2, $search['hits']['hits']);
$this->assertFalse($this->logHandler()->hasErrorThatContains('Job could not be indexed in ElasticSearch'));
$logRecords = $this->logHandler()->getRecords();
$successfullyIndexedLog = array_filter(
Expand Down

0 comments on commit 949024f

Please sign in to comment.