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

PersisterRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 8
loc 36
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPersister() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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