RegisterCollectionConvertersPass::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 2
rs 10
1
<?php
2
/**
3
 * This file is part of the sauls/components-bundle package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2018
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Sauls\Bundle\Components\DependencyInjection\Compiler;
14
15
use Exception;
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
19
use function array_keys;
20
use function array_map;
21
use function Sauls\Component\Helper\register_converters;
22
23
class RegisterCollectionConvertersPass implements CompilerPassInterface
24
{
25
    /**
26
     * @param ContainerBuilder $container
27
     *
28
     * @throws Exception
29
     */
30 7
    public function process(ContainerBuilder $container)
31
    {
32 7
        $taggedServices = $container->findTaggedServiceIds('sauls_collection.converter');
33
34 7
        if (empty($taggedServices)) {
35 6
            return;
36
        }
37
38 1
        register_converters(
39 1
            array_map(
40 1
                function ($converterId) use ($container) {
41 1
                    return $container->get($converterId);
42 1
                },
43 1
                array_keys($taggedServices)
44
            )
45
        );
46 1
    }
47
}
48