PagerProviderRegistry   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 38
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getProvider() 0 8 2
A getProviders() 0 6 1
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\Provider;
13
14
use Symfony\Component\DependencyInjection\ServiceLocator;
15
16
/**
17
 * References persistence providers for each index.
18
 */
19
class PagerProviderRegistry
20
{
21
    /** @var ServiceLocator */
22
    private $providers;
23
24 7
    public function __construct(ServiceLocator $providers)
25
    {
26 7
        $this->providers = $providers;
27 7
    }
28
29
    /**
30
     * Gets all registered providers.
31
     *
32
     * Providers will be indexed by "index" strings in the returned array.
33
     *
34
     * @return PagerProviderInterface[]
35
     */
36 1
    public function getProviders()
37
    {
38 1
        return \array_reduce(\array_keys($this->providers->getProvidedServices()), function ($carry, $index) {
39 1
            return $carry + [$index => $this->providers->get($index)];
40 1
        }, []);
41
    }
42
43
    /**
44
     * Gets the provider for an index.
45
     *
46
     * @throws \InvalidArgumentException if no provider was registered for the index and type
47
     */
48 2
    public function getProvider(string $index): PagerProviderInterface
49
    {
50 2
        if (!$this->providers->has($index)) {
51 1
            throw new \InvalidArgumentException(\sprintf('No provider was registered for index "%s".', $index));
52
        }
53
54 1
        return $this->providers->get($index);
55
    }
56
}
57