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

Registry::getFacets()   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 0
dl 0
loc 3
rs 10
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