Completed
Pull Request — 2.0 (#1098)
by
unknown
15:14 queued 12:33
created

StackBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
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\StackFactoryInterface;
15
16
final class StackBuilder implements StackBuilderInterface
17
{
18
    /**
19
     * @var StackFactoryInterface
20
     */
21
    private $stackFactory;
22
23
    /**
24
     * @var FilterFactoryCollection
25
     */
26
    private $filterFactoryCollection;
27
28
    public function __construct(StackFactoryInterface $stackFactory, FilterFactoryCollection $filterFactoryCollection)
29
    {
30
        $this->stackFactory = $stackFactory;
31
        $this->filterFactoryCollection = $filterFactoryCollection;
32
    }
33
34
    public function build(string $stackName, array $stackData): StackInterface
35
    {
36
        $filters = [];
37
        if (!empty($stackData['filters'])) {
38
            foreach ($stackData['filters'] as $filterName => $filterData) {
39
                $filterFactory = $this->filterFactoryCollection->getFilterFactoryByName($filterName);
40
                $filters[] = $filterFactory->create($filterData);
41
            }
42
        }
43
44
        return $this->stackFactory->create(
45
            $stackName,
46
            $stackData['data_loader'],
47
            $stackData['quality'],
48
            $filters
49
        );
50
    }
51
}
52