Completed
Push — master ( 74371a...6da8c0 )
by Vladimir
02:21
created

TwigExtension   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 48
Duplicated Lines 54.17 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 61.11%

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 2
cbo 2
dl 26
loc 48
ccs 11
cts 18
cp 0.6111
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addFilters() 13 13 4
A addFunctions() 13 13 4
A getFilters() 0 4 1
A getFunctions() 0 4 1
A getName() 0 4 1

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
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Templating\Twig;
9
10
use allejo\stakx\Command\BuildableCommand;
11
use allejo\stakx\Service;
12
use allejo\stakx\Templating\Twig\Extension\AbstractTwigExtension;
13
use allejo\stakx\Templating\Twig\Extension\TwigFilterInterface;
14
use allejo\stakx\Templating\Twig\Extension\TwigFunctionInterface;
15
16
class TwigExtension extends \Twig_Extension
17
{
18
    private $filters = [];
19
    private $functions = [];
20
21 18 View Code Duplication
    public function addFilters(/*iterable*/ $filters)
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...
22
    {
23
        /** @var AbstractTwigExtension|TwigFilterInterface $filter */
24 18
        foreach ($filters as $filter)
25
        {
26 18
            if (Service::getParameter(BuildableCommand::SAFE_MODE) && $filter::disableInSafeMode())
27
            {
28
                continue;
29
            }
30
31 18
            $this->filters[] = $filter::get();
32
        }
33 18
    }
34
35 View Code Duplication
    public function addFunctions(/*iterable*/ $functions)
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...
36
    {
37
        /** @var AbstractTwigExtension|TwigFunctionInterface $fxn */
38
        foreach ($functions as $fxn)
39
        {
40
            if (Service::getParameter(BuildableCommand::SAFE_MODE) && $fxn::disableInSafeMode())
41
            {
42
                continue;
43
            }
44
45
            $this->functions[] = $fxn::get();
46
        }
47
    }
48
49 6
    public function getFilters()
50
    {
51 6
        return $this->filters;
52
    }
53
54 6
    public function getFunctions()
55
    {
56 6
        return $this->functions;
57
    }
58
59 30
    public function getName()
60
    {
61 30
        return 'stakx_twig_base_extension';
62
    }
63
}
64