Completed
Push — feature-20rc1 ( 008ae2 )
by Rob
16:55
created

LoadersCompilerPass::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

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 5
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\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Reference;
16
17 View Code Duplication
class LoadersCompilerPass extends AbstractCompilerPass
0 ignored issues
show
Duplication introduced by
This class 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...
18
{
19
    /**
20
     * @var string
21
     */
22
    private $tagName;
23
24
    /**
25
     * @var string
26
     */
27
    private $service;
28
29
    /**
30
     * @param string $loadersTagName
31
     * @param string $managerService
32
     */
33
    public function __construct(
34
        string $loadersTagName = 'liip_imagine.binary.loader',
35
        string $managerService = 'liip_imagine.data.manager'
36
    ) {
37
        $this->tagName = $loadersTagName;
38
        $this->service = $managerService;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function process(ContainerBuilder $container): void
45
    {
46
        $loaders = $container->findTaggedServiceIds($this->tagName);
47
48
        if (0 < count($loaders) && $container->hasDefinition($this->service)) {
49
            $manager = $container->getDefinition($this->service);
50
51
            foreach ($loaders as $id => $tag) {
52
                $manager->addMethodCall('addLoader', [$tag[0]['loader'], new Reference($id)]);
53
                $this->log($container, 'Registered binary loader: %s', $id);
54
            }
55
        }
56
    }
57
}
58