Passed
Push — master ( 5a6aec...5e9b73 )
by Gordon
05:22 queued 02:54
created

Facet::getFacetCounts()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace Suilven\FreeTextSearch\Container;
4
5
/**
6
 * Class Facet
7
 *
8
 * @package Suilven\FreeTextSearch\Container
9
 */
10
class Facet
11
{
12
    /** @var string */
13
    private $name;
14
15
    /** @var array<\Suilven\FreeTextSearch\Container\FacetCount> */
16
    private $facetCounts = [];
17
18
    /**
19
     * Facet constructor.
20
     */
21
    public function __construct(string $name)
22
    {
23
        $this->name = $name;
24
    }
25
26
27
    /** @param string|float|int|bool $key $key */
28
    public function addFacetCount($key, int $count): void
29
    {
30
        $fc = new FacetCount($key, $count);
31
        $this->facetCounts[] = $fc;
32
    }
33
34
35
    public function getName(): string
36
    {
37
        return $this->name;
38
    }
39
40
41
    /** @return array<\Suilven\FreeTextSearch\Container\FacetCount> */
42
    public function getFacetCounts(): array
43
    {
44
        return $this->facetCounts;
45
    }
46
47
48
    /** @return array<string|float|int|bool, int> */
49
    public function asKeyValueArray(): array
50
    {
51
        $result = [];
52
        /** @var \Suilven\FreeTextSearch\Container\FacetCount $fc */
53
        foreach ($this->facetCounts as $fc) {
54
            $result[$fc->getKey()] = $fc->getCount();
55
        }
56
57
        return $result;
58
    }
59
}
60