PersisterRegistry::getPersister()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 8
loc 8
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 0
b 0
f 0
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\Persister;
13
14
use Symfony\Component\DependencyInjection\ServiceLocator;
15
16 View Code Duplication
class PersisterRegistry
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /** @var ServiceLocator */
19
    private $persisters;
20
21 1
    public function __construct(ServiceLocator $persisters)
22
    {
23 1
        $this->persisters = $persisters;
24 1
    }
25
26
    /**
27
     * Gets the persister for an index.
28
     *
29
     * @throws \InvalidArgumentException if no persister was registered for the index
30
     */
31 1
    public function getPersister(string $index): ObjectPersisterInterface
32
    {
33 1
        if (!$this->persisters->has($index)) {
34
            throw new \InvalidArgumentException(\sprintf('No persister was registered for index "%s".', $index));
35
        }
36
37 1
        return $this->persisters->get($index);
38
    }
39
}
40