Completed
Pull Request — 2.0 (#1098)
by
unknown
09:24 queued 13s
created

FilterSetCollection::getFilterSets()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 0
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Config;
13
14
final class FilterSetCollection
15
{
16
    /**
17
     * @var array
18
     */
19
    private $filterSets = [];
20
21
    /**
22
     * @var FilterSetBuilderInterface
23
     */
24
    private $filterSetBuilder;
25
26
    /**
27
     * @var array
28
     */
29
    private $filtersConfiguration;
30
31
    /**
32
     * @param FilterSetBuilderInterface $filterSetBuilder
33
     * @param array                     $filtersConfiguration
34
     */
35
    public function __construct(FilterSetBuilderInterface $filterSetBuilder, array $filtersConfiguration = [])
36
    {
37
        $this->filterSetBuilder = $filterSetBuilder;
38
        $this->filtersConfiguration = $filtersConfiguration;
39
    }
40
41
    /**
42
     * @return FilterSetInterface[]
43
     */
44
    public function getFilterSets()
45
    {
46
        if (!empty($this->filterSets)) {
47
            return $this->filterSets;
48
        }
49
50
        foreach ($this->filtersConfiguration as $filterSetName => $filterSetData) {
51
            $this->filterSets[] = $this->filterSetBuilder->build($filterSetName, $filterSetData);
52
        }
53
54
        return $this->filterSets;
55
    }
56
}
57