DataTablesExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 69.23%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 3
b 0
f 0
dl 0
loc 28
ccs 9
cts 13
cp 0.6923
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 4 1
A process() 0 14 4
1
<?php
2
3
//----------------------------------------------------------------------
4
//
5
//  Copyright (C) 2015-2022 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;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...ection\ContainerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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 https://symfony.com/doc/5.4/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
        foreach ($services as $id => $tags) {
52 1
            foreach ($tags as $tag) {
53
                $definition->addMethodCall('addService', [
54
                    new Reference($id),
55
                    $tag['id'] ?? null,
56
                ]);
57
            }
58
        }
59
    }
60
}
61