FilterFactoryCollection::getAll()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
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
use Liip\ImagineBundle\Exception\Config\Filter\NotFoundException;
15
use Liip\ImagineBundle\Factory\Config\FilterFactoryInterface;
16
17
class FilterFactoryCollection
18
{
19
    /**
20
     * @var FilterFactoryInterface[]
21
     */
22
    private $filterFactories = [];
23
24
    /**
25
     * @param FilterFactoryInterface ...$filterFactories
26
     */
27
    public function __construct(FilterFactoryInterface ...$filterFactories)
28
    {
29
        foreach ($filterFactories as $filterFactory) {
30
            $this->filterFactories[$filterFactory->getName()] = $filterFactory;
31
        }
32
    }
33
34
    /**
35
     * @throws NotFoundException
36
     */
37
    public function getFilterFactoryByName(string $name): FilterFactoryInterface
38
    {
39
        if (!isset($this->filterFactories[$name])) {
40
            throw new NotFoundException(sprintf("Filter factory with name '%s' was not found.", $name));
41
        }
42
43
        return $this->filterFactories[$name];
44
    }
45
46
    /**
47
     * @return FilterFactoryInterface[]
48
     */
49
    public function getAll()
50
    {
51
        return $this->filterFactories;
52
    }
53
}
54