Completed
Push — master ( fbc1fa...9bba21 )
by
unknown
14s
created

IndexManager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAllIndexes() 0 4 1
A getIndex() 0 12 3
A getDefaultIndex() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://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
    /**
29
     * @param array $indexes
30
     * @param Index $defaultIndex
31
     */
32
    public function __construct(array $indexes, Index $defaultIndex)
33
    {
34
        $this->defaultIndex = $defaultIndex;
35
        $this->indexes = $indexes;
36
    }
37
38
    /**
39
     * Gets all registered indexes.
40
     *
41
     * @return array
42
     */
43
    public function getAllIndexes()
44
    {
45
        return $this->indexes;
46
    }
47
48
    /**
49
     * Gets an index by its name.
50
     *
51
     * @param string $name Index to return, or the default index if null
52
     *
53
     * @return Index
54
     *
55
     * @throws \InvalidArgumentException if no index exists for the given name
56
     */
57
    public function getIndex($name = null)
58
    {
59
        if (null === $name) {
60
            return $this->defaultIndex;
61
        }
62
63
        if (!isset($this->indexes[$name])) {
64
            throw new \InvalidArgumentException(sprintf('The index "%s" does not exist', $name));
65
        }
66
67
        return $this->indexes[$name];
68
    }
69
70
    /**
71
     * Gets the default index.
72
     *
73
     * @return Index
74
     */
75
    public function getDefaultIndex()
76
    {
77
        return $this->defaultIndex;
78
    }
79
}
80