Skip to content

Commit f2c7626

Browse files
authored
Merge pull request #1798 from deguif/null-coalescing-operator
Use null coalescing operator
2 parents a6ffdc1 + f85e8cd commit f2c7626

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

src/DependencyInjection/FOSElasticaExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ private function loadIndexConfig(array $index, array &$indexConfig): void
316316
'dynamic_date_formats',
317317
'numeric_detection',
318318
] as $field) {
319-
$indexConfig['config'][$field] = \array_key_exists($field, $index) ? $index[$field] : null;
319+
$indexConfig['config'][$field] = $index[$field] ?? null;
320320
}
321321
}
322322

src/Elastica/Client.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,14 @@ public function request(string $path, string $method = Request::GET, $data = [],
8585

8686
public function getIndex(string $name): BaseIndex
8787
{
88-
if (isset($this->indexCache[$name])) {
89-
return $this->indexCache[$name];
90-
}
91-
92-
return $this->indexCache[$name] = new Index($this, $name);
88+
// TODO PHP >= 7.4 ??=
89+
return $this->indexCache[$name] ?? ($this->indexCache[$name] = new Index($this, $name));
9390
}
9491

9592
public function getIndexTemplate($name): IndexTemplate
9693
{
97-
if (isset($this->indexTemplateCache[$name])) {
98-
return $this->indexTemplateCache[$name];
99-
}
100-
101-
return $this->indexTemplateCache[$name] = new IndexTemplate($this, $name);
94+
// TODO PHP >= 7.4 ??=
95+
return $this->indexTemplateCache[$name] ?? ($this->indexTemplateCache[$name] = new IndexTemplate($this, $name));
10296
}
10397

10498
/**

src/Manager/RepositoryManager.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ public function hasRepository(string $indexName): bool
6969

7070
protected function getRepositoryName(string $indexName): string
7171
{
72-
if (isset($this->indexes[$indexName]['repositoryName'])) {
73-
return $this->indexes[$indexName]['repositoryName'];
74-
}
75-
76-
return Repository::class;
72+
return $this->indexes[$indexName]['repositoryName'] ?? Repository::class;
7773
}
7874

7975
/**

0 commit comments

Comments
 (0)