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

Registry::addFacet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
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