Passed
Push — master ( cc4e78...1262d4 )
by Damian
04:08
created

Registry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 24
rs 10
c 1
b 0
f 0
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
3
declare(strict_types=1);
4
5
namespace BitBag\SyliusElasticsearchPlugin\Facet;
6
7
final class Registry implements RegistryInterface
8
{
9
    /** @var FacetInterface[] */
10
    private $facets = [];
11
12
    public function addFacet(string $facetId, FacetInterface $facet): void
13
    {
14
        $this->facets[$facetId] = $facet;
15
    }
16
17
    /**
18
     * @return FacetInterface[]
19
     */
20
    public function getFacets(): array
21
    {
22
        return $this->facets;
23
    }
24
25
    public function getFacetById(string $facetId): FacetInterface
26
    {
27
        if (!array_key_exists($facetId, $this->facets)) {
28
            throw new FacetNotFoundException(sprintf('Cannot find facet with ID "%s" in registry.', $facetId));
29
        }
30
        return $this->facets[$facetId];
31
    }
32
}
33