Passed
Pull Request — master (#69)
by Manuele
04:16
created

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