Completed
Push — master ( 4e4cd8...063296 )
by Maksim
16s
created

PersisterRegistry::getPersister()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 6
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\Persister;
13
14
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
16
17
class PersisterRegistry implements ContainerAwareInterface
18
{
19
    use ContainerAwareTrait;
20
21
    /** 
22
     * @var array 
23
     */
24
    private $persisters = [];
25
26
    /**
27
     * @param array $persisters
28
     */
29
    public function __construct(array $persisters)
30
    {
31
        $this->persisters = $persisters;
32
    }
33
34
    /**
35
     * Gets the persister for an index and type.
36
     *
37
     * @param string $index
38
     * @param string $type
39
     *
40
     * @return ObjectPersisterInterface
41
     *
42
     * @throws \InvalidArgumentException if no persister was registered for the index and type
43
     */
44 View Code Duplication
    public function getPersister($index, $type)
45
    {
46
        if (!isset($this->persisters[$index][$type])) {
47
            throw new \InvalidArgumentException(sprintf('No persister was registered for index "%s" and type "%s".', $index, $type));
48
        }
49
50
        return $this->container->get($this->persisters[$index][$type]);
51
    }
52
}
53