Skip to content

Commit

Permalink
Merge pull request #1798 from deguif/null-coalescing-operator
Browse files Browse the repository at this point in the history
Use null coalescing operator
  • Loading branch information
XWB authored May 24, 2021
2 parents a6ffdc1 + f85e8cd commit f2c7626
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/DependencyInjection/FOSElasticaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private function loadIndexConfig(array $index, array &$indexConfig): void
'dynamic_date_formats',
'numeric_detection',
] as $field) {
$indexConfig['config'][$field] = \array_key_exists($field, $index) ? $index[$field] : null;
$indexConfig['config'][$field] = $index[$field] ?? null;
}
}

Expand Down
14 changes: 4 additions & 10 deletions src/Elastica/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,14 @@ public function request(string $path, string $method = Request::GET, $data = [],

public function getIndex(string $name): BaseIndex
{
if (isset($this->indexCache[$name])) {
return $this->indexCache[$name];
}

return $this->indexCache[$name] = new Index($this, $name);
// TODO PHP >= 7.4 ??=
return $this->indexCache[$name] ?? ($this->indexCache[$name] = new Index($this, $name));
}

public function getIndexTemplate($name): IndexTemplate
{
if (isset($this->indexTemplateCache[$name])) {
return $this->indexTemplateCache[$name];
}

return $this->indexTemplateCache[$name] = new IndexTemplate($this, $name);
// TODO PHP >= 7.4 ??=
return $this->indexTemplateCache[$name] ?? ($this->indexTemplateCache[$name] = new IndexTemplate($this, $name));
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Manager/RepositoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ public function hasRepository(string $indexName): bool

protected function getRepositoryName(string $indexName): string
{
if (isset($this->indexes[$indexName]['repositoryName'])) {
return $this->indexes[$indexName]['repositoryName'];
}

return Repository::class;
return $this->indexes[$indexName]['repositoryName'] ?? Repository::class;
}

/**
Expand Down

0 comments on commit f2c7626

Please sign in to comment.