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

SearchFacets   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 62
rs 10
c 1
b 0
f 0
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __isset() 0 3 1
A current() 0 3 1
A valid() 0 4 2
A next() 0 3 1
A __get() 0 6 2
A __set() 0 3 1
A rewind() 0 3 1
A key() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitBag\SyliusElasticsearchPlugin\Model;
6
7
class SearchFacets implements \Iterator
8
{
9
    /** @var array[] */
10
    private $selectedBuckets = [];
11
12
    public function __get(string $facetId)
13
    {
14
        if (!array_key_exists($facetId, $this->selectedBuckets)) {
15
            return [];
16
        }
17
        return $this->selectedBuckets[$facetId];
18
    }
19
20
    public function __set(string $facetId, $selectedBuckets)
21
    {
22
        $this->selectedBuckets[$facetId] = $selectedBuckets;
23
    }
24
25
    public function __isset(string $facetId)
26
    {
27
        return isset($this->selectedBuckets[$facetId]);
28
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    public function current()
34
    {
35
        return current($this->selectedBuckets);
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function next()
42
    {
43
        return next($this->selectedBuckets);
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function key()
50
    {
51
        return key($this->selectedBuckets);
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57
    public function valid()
58
    {
59
        $key = key($this->selectedBuckets);
60
        return ($key !== null && $key !== false);
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66
    public function rewind()
67
    {
68
        reset($this->selectedBuckets);
69
    }
70
}
71