Completed
Push — 1.0 ( 30aea4...7767b3 )
by Rob
9s
created

FileSystemLoaderFactory::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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\DependencyInjection\Factory\Loader;
13
14
use Liip\ImagineBundle\Utility\Framework\SymfonyFramework;
15
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\ContainerInterface;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
class FileSystemLoaderFactory extends AbstractLoaderFactory
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 View Code Duplication
    public function create(ContainerBuilder $container, $loaderName, array $config)
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...
26
    {
27
        $definition = $this->getChildLoaderDefinition();
28
        $definition->replaceArgument(2, $config['data_root']);
29
        $definition->replaceArgument(3, $this->createLocatorReference($config['locator']));
30
31
        return $this->setTaggedLoaderDefinition($loaderName, $definition, $container);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getName()
38
    {
39
        return 'filesystem';
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function addConfiguration(ArrayNodeDefinition $builder)
46
    {
47
        $builder
48
            ->children()
49
                ->enumNode('locator')
50
                    ->values(array('filesystem', 'filesystem_insecure'))
51
                    ->info('Using the "filesystem_insecure" locator is not recommended due to a less secure resolver mechanism, but is provided for those using heavily symlinked projects.')
52
                    ->defaultValue('filesystem')
53
                ->end()
54
                ->arrayNode('data_root')
55
                    ->beforeNormalization()
56
                    ->ifString()
57
                        ->then(function ($value) { return array($value); })
58
                    ->end()
59
                    ->defaultValue(array('%kernel.root_dir%/../web'))
60
                    ->prototype('scalar')
61
                        ->cannotBeEmpty()
62
                    ->end()
63
                ->end()
64
            ->end();
65
    }
66
67
    /**
68
     * @param string $reference
69
     *
70
     * @return Reference
71
     */
72
    private function createLocatorReference($reference)
73
    {
74
        $name = sprintf('liip_imagine.binary.locator.%s', $reference);
75
76
        if (SymfonyFramework::hasDefinitionSharing()) {
77
            return new Reference($name);
78
        }
79
80
        return new Reference($name, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
0 ignored issues
show
Unused Code introduced by
The call to Reference::__construct() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
81
    }
82
}
83