Skip to content

Commit f717470

Browse files
authored
Merge pull request #1658 from deguif/type-hint-repository-manager-signatures
Add type-hints on signatures of repository-manager methods
2 parents aa82c50 + ac3156b commit f717470

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

CHANGELOG-6.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ in 6.0 versions.
2121
* [BC break] Signature of methods `findPaginated`, `createPaginatorAdapter` and `createRawPaginatorAdapter` from interface `FOS\ElasticaBundle\Finder\PaginatedFinderInterface` were changed.
2222
* [BC break] Signature of methods `request`, `getIndex`, `getIndexTemplate` and `setStopwatch` from class `FOS\ElasticaBundle\Elastica\Client` were changed.
2323
* [BC break] Signature of methods `logQuery`, `getNbQueries` and `getQueries` from class `FOS\ElasticaBundle\Logger\ElasticaLogger` were changed.
24+
* [BC break] Signature of methods `addIndex`, `getRepository` and `getRepositoryName` from class `FOS\ElasticaBundle\Manager\RepositoryManager` were changed.
2425
* [BC break] Signature of methods `find`, `findHybrid`, `findPaginated` and `createPaginatorAdapter` from class `FOS\ElasticaBundle\Repository` were changed.
2526
* [BC break] Removed `Elastica\Type`.
2627
* [BC break] Removed `_parent`.

src/Manager/RepositoryManager.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use FOS\ElasticaBundle\Finder\FinderInterface;
1515
use FOS\ElasticaBundle\Repository;
16-
use RuntimeException;
1716

1817
/**
1918
* @author Richard Miller <[email protected]>
@@ -26,20 +25,14 @@ class RepositoryManager implements RepositoryManagerInterface
2625
/**
2726
* @var array
2827
*/
29-
private $indexes;
28+
private $indexes = [];
3029

3130
/**
3231
* @var array
3332
*/
34-
private $repositories;
33+
private $repositories = [];
3534

36-
public function __construct()
37-
{
38-
$this->indexes = [];
39-
$this->repositories = [];
40-
}
41-
42-
public function addIndex(string $indexName, FinderInterface $finder, string $repositoryName = null): void
35+
public function addIndex(string $indexName, FinderInterface $finder, ?string $repositoryName = null): void
4336
{
4437
$this->indexes[$indexName] = [
4538
'finder' => $finder,
@@ -60,7 +53,7 @@ public function getRepository(string $indexName): Repository
6053
}
6154

6255
if (!$this->hasRepository($indexName)) {
63-
throw new RuntimeException(sprintf('No search finder configured for %s', $indexName));
56+
throw new \RuntimeException(sprintf('No repository configured for %s', $indexName));
6457
}
6558

6659
$repository = $this->createRepository($indexName);
@@ -74,12 +67,7 @@ public function hasRepository(string $indexName): bool
7467
return isset($this->indexes[$indexName]);
7568
}
7669

77-
/**
78-
* @param $indexName
79-
*
80-
* @return string
81-
*/
82-
protected function getRepositoryName($indexName)
70+
protected function getRepositoryName(string $indexName): string
8371
{
8472
if (isset($this->indexes[$indexName]['repositoryName'])) {
8573
return $this->indexes[$indexName]['repositoryName'];
@@ -89,14 +77,12 @@ protected function getRepositoryName($indexName)
8977
}
9078

9179
/**
92-
* @param $indexName
93-
*
9480
* @return mixed
9581
*/
96-
private function createRepository($indexName)
82+
private function createRepository(string $indexName)
9783
{
9884
if (!class_exists($repositoryName = $this->getRepositoryName($indexName))) {
99-
throw new RuntimeException(sprintf('%s repository for %s does not exist', $repositoryName, $indexName));
85+
throw new \RuntimeException(sprintf('%s repository for %s does not exist', $repositoryName, $indexName));
10086
}
10187

10288
return new $repositoryName($this->indexes[$indexName]['finder']);

0 commit comments

Comments
 (0)