Passed
Pull Request — master (#69)
by Manuele
03:19
created

Registry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addFacet() 0 3 1
A getFacets() 0 3 1
A getFacetById() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
namespace BitBag\SyliusElasticsearchPlugin\Facet;
5
6
final class Registry implements RegistryInterface
7
{
8
    /**
9
     * @var FacetInterface[]
10
     */
11
    private $facets = [];
12
13
    public function addFacet(string $facetId, FacetInterface $facet): void
14
    {
15
        $this->facets[$facetId] = $facet;
16
    }
17
18
    /**
19
     * @return FacetInterface[]
20
     */
21
    public function getFacets(): array
22
    {
23
        return $this->facets;
24
    }
25
26
    /**
27
     * @param string $facetId
28
     * @return FacetInterface
29
     */
30
    public function getFacetById(string $facetId): FacetInterface
31
    {
32
        if (!array_key_exists($facetId, $this->facets)) {
33
            throw new FacetNotFoundException(sprintf('Cannot find facet with ID "%s" in registry.', $facetId));
34
        }
35
        return $this->facets[$facetId];
36
    }
37
}
38