Completed
Push — 2.0 ( 6b5f04...0265fa )
by
unknown
14s
created

ChainLoaderFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
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 View Code Duplication
    public function create(ContainerBuilder $container, $loaderName, array $config): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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