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

SearchFacets::__set()   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\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