ChainLoaderFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A addConfiguration() 0 12 1
A createLoaderReferences() 0 6 1
A create() 0 7 1
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\DependencyInjection\Factory\Loader;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class ChainLoaderFactory extends AbstractLoaderFactory
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function create(ContainerBuilder $container, $loaderName, array $config): string
24
    {
25
        $definition = $this->getChildLoaderDefinition();
26
        $definition->replaceArgument(0, $this->createLoaderReferences($config['loaders']));
27
28
        return $this->setTaggedLoaderDefinition($loaderName, $definition, $container);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getName(): string
35
    {
36
        return 'chain';
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function addConfiguration(ArrayNodeDefinition $builder): void
43
    {
44
        $builder
45
            ->children()
46
                ->arrayNode('loaders')
47
                    ->isRequired()
48
                    ->prototype('scalar')
49
                        ->cannotBeEmpty()
50
                    ->end()
51
                ->end()
52
            ->end();
53
    }
54
55
    /**
56
     * @param string[] $loaders
57
     *
58
     * @return string[]
59
     */
60
    private function createLoaderReferences(array $loaders): array
61
    {
62
        return array_combine($loaders, array_map(function ($name) {
63
            return new Reference(sprintf('liip_imagine.binary.loader.%s', $name));
64
        }, $loaders));
65
    }
66
}
67