IndexManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 52
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultIndex() 0 4 1
A __construct() 0 5 1
A getAllIndexes() 0 4 1
A getIndex() 0 12 3
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <https://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\ElasticaBundle\Index;
13
14
use FOS\ElasticaBundle\Elastica\Index;
15
16
class IndexManager
17
{
18
    /**
19
     * @var Index
20
     */
21
    private $defaultIndex;
22
23
    /**
24
     * @var array
25
     */
26
    private $indexes;
27
28 11
    public function __construct(array $indexes, Index $defaultIndex)
29
    {
30 11
        $this->defaultIndex = $defaultIndex;
31 11
        $this->indexes = $indexes;
32 11
    }
33
34
    /**
35
     * Gets all registered indexes.
36
     */
37 1
    public function getAllIndexes(): array
38
    {
39 1
        return $this->indexes;
40
    }
41
42
    /**
43
     * Gets an index by its name or the default index.
44
     *
45
     * @throws \InvalidArgumentException if no index exists for the given name
46
     */
47 6
    public function getIndex(?string $name = null): Index
48
    {
49 6
        if (null === $name) {
50 1
            return $this->defaultIndex;
51
        }
52
53 5
        if (!isset($this->indexes[$name])) {
54 1
            throw new \InvalidArgumentException(\sprintf('The index "%s" does not exist', $name));
55
        }
56
57 4
        return $this->indexes[$name];
58
    }
59
60
    /**
61
     * Gets the default index.
62
     */
63 1
    public function getDefaultIndex(): Index
64
    {
65 1
        return $this->defaultIndex;
66
    }
67
}
68