Completed
Pull Request — 2.0 (#1098)
by
unknown
10:38 queued 07:38
created

StackBuilder::build()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 2
nop 2
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
use Liip\ImagineBundle\Factory\Config\StackFactory;
15
16
final class StackBuilder implements StackBuilderInterface
17
{
18
    /**
19
     * @var StackFactory
20
     */
21
    private $filterSetFactory;
22
23
    /**
24
     * @var FilterFactoryCollection
25
     */
26
    private $filterFactoryCollection;
27
28
    /**
29
     * @param StackFactory            $filterSetFactory
30
     * @param FilterFactoryCollection $filterFactoryCollection
31
     */
32
    public function __construct(StackFactory $filterSetFactory, FilterFactoryCollection $filterFactoryCollection)
33
    {
34
        $this->filterSetFactory = $filterSetFactory;
35
        $this->filterFactoryCollection = $filterFactoryCollection;
36
    }
37
38
    /**
39
     * @param string $filterSetName
40
     * @param array  $filterSetData
41
     *
42
     * @return StackInterface
43
     */
44
    public function build(string $filterSetName, array $filterSetData): StackInterface
45
    {
46
        $filters = [];
47
        if (!empty($filterSetData['filters'])) {
48
            foreach ($filterSetData['filters'] as $filterName => $filterData) {
49
                $filterFactory = $this->filterFactoryCollection->getFilterFactoryByName($filterName);
50
                $filters[] = $filterFactory->create($filterData);
51
            }
52
        }
53
54
        return $this->filterSetFactory->create(
55
            $filterSetName,
56
            $filterSetData['data_loader'],
57
            $filterSetData['quality'],
58
            $filters
59
        );
60
    }
61
}
62