Passed
Push — master ( a7f0ec...c2460d )
by Artem
02:49
created

DataTablesExtension::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 15
ccs 5
cts 10
cp 0.5
rs 9.9666
cc 4
nc 4
nop 1
crap 6
1
<?php
2
3
//----------------------------------------------------------------------
4
//
5
//  Copyright (C) 2015-2019 Artem Rodygin
6
//
7
//  This file is part of DataTables Symfony bundle.
8
//
9
//  You should have received a copy of the MIT License along with
10
//  the bundle. If not, see <http://opensource.org/licenses/MIT>.
11
//
12
//----------------------------------------------------------------------
13
14
namespace DataTables\DependencyInjection;
15
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
20
use Symfony\Component\DependencyInjection\Reference;
21
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
22
23
/**
24
 * This is the class that loads and manages the bundle configuration.
25
 *
26
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
27
 */
28
class DataTablesExtension extends Extension implements CompilerPassInterface
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function load(array $configs, ContainerBuilder $container)
34
    {
35 1
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
36 1
        $loader->load('datatables.yml');
37 1
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 1
    public function process(ContainerBuilder $container)
43
    {
44 1
        if (!$container->has('datatables')) {
45
            return;
46
        }
47
48 1
        $definition = $container->findDefinition('datatables');
49 1
        $services   = $container->findTaggedServiceIds('datatable');
50
51
        /** @var array $tags */
52 1
        foreach ($services as $id => $tags) {
53
            foreach ($tags as $tag) {
54
                $definition->addMethodCall('addService', [
55
                    new Reference($id),
56
                    $tag['id'] ?? null,
57
                ]);
58
            }
59
        }
60 1
    }
61
}
62