Completed
Pull Request — master (#1240)
by Maksim
04:15
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
c 0
b 0
f 0
dl 8
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
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
    /** @var array */
22
    private $persisters = [];
23
24
    /**
25
     * @param string $index
26
     * @param string $type
27
     * @param string $persisterId
28
     */
29
    public function addPersister($index, $type, $persisterId)
30
    {
31
        if (!isset($this->persisters[$index])) {
32
            $this->persisters[$index] = [];
33
        }
34
35
        $this->persisters[$index][$type] = $persisterId;
36
    }
37
38
    /**
39
     * @return ObjectPersisterInterface
40
     */
41 View Code Duplication
    public function getPersister($index, $type)
42
    {
43
        if (!isset($this->persisters[$index][$type])) {
44
            throw new \InvalidArgumentException(sprintf('No persister was registered for index "%s" and type "%s".', $index, $type));
45
        }
46
47
        return $this->container->get($this->persisters[$index][$type]);
48
    }
49
}
50