Completed
Push — master ( 209945...41a4bc )
by Matthew
07:41 queued 03:34
created

DtcGridExtension   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 61
Duplicated Lines 39.34 %

Importance

Changes 0
Metric Value
dl 24
loc 61
rs 10
c 0
b 0
f 0
wmc 16

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setJquery() 0 4 2
A load() 0 15 2
A setDataTables() 7 7 3
A getAlias() 0 3 1
A setPurl() 0 4 2
A setJqGrid() 7 7 3
A setTheme() 7 7 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Dtc\GridBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Processor;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
8
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9
use Symfony\Component\Config\FileLocator;
10
11
class DtcGridExtension extends Extension
12
{
13
    public function load(array $configs, ContainerBuilder $container)
14
    {
15
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
16
        $loader->load('grid.yml');
17
18
        $configuration = new Configuration();
19
        $processor = new Processor();
20
21
        $config = $processor->processConfiguration($configuration, $configs);
22
        $this->setJqGrid($config, $container);
23
        $this->setTheme($config, $container);
24
        $this->setDatatables($config, $container);
25
        $this->setJquery($config, $container);
26
        $this->setPurl($config, $container);
27
        $container->setParameter('dtc_grid.page_div_style', isset($config['page_div_style']) ? $config['page_div_style'] : null);
28
    }
29
30
    public function setPurl(array $config, ContainerBuilder $container)
31
    {
32
        $purl = isset($config['purl']) ? $config['purl'] : [];
33
        $container->setParameter('dtc_grid.purl', $purl);
34
    }
35
36
    public function setJquery(array $config, ContainerBuilder $container)
37
    {
38
        $jquery = isset($config['jquery']) ? $config['jquery'] : [];
39
        $container->setParameter('dtc_grid.jquery', $jquery);
40
    }
41
42 View Code Duplication
    public function setJqGrid(array $config, ContainerBuilder $container)
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...
43
    {
44
        $css = isset($config['jq_grid']['css']) ? $config['jq_grid']['css'] : [];
45
        $js = isset($config['jq_grid']['js']) ? $config['jq_grid']['js'] : [];
46
47
        $container->setParameter('dtc_grid.jq_grid.css', $css);
48
        $container->setParameter('dtc_grid.jq_grid.js', $js);
49
    }
50
51 View Code Duplication
    public function setDataTables(array $config, ContainerBuilder $container)
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...
52
    {
53
        $css = isset($config['datatables']['css']) ? $config['datatables']['css'] : [];
54
        $js = isset($config['datatables']['js']) ? $config['datatables']['js'] : [];
55
56
        $container->setParameter('dtc_grid.datatables.css', $css);
57
        $container->setParameter('dtc_grid.datatables.js', $js);
58
    }
59
60 View Code Duplication
    public function setTheme(array $config, ContainerBuilder $container)
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...
61
    {
62
        $css = isset($config['theme']['css']) ? $config['theme']['css'] : [];
63
        $js = isset($config['theme']['js']) ? $config['theme']['js'] : [];
64
65
        $container->setParameter('dtc_grid.theme.css', $css);
66
        $container->setParameter('dtc_grid.theme.js', $js);
67
    }
68
69
    public function getAlias()
70
    {
71
        return 'dtc_grid';
72
    }
73
}
74