Completed
Push — master ( 85472e...46e0b8 )
by Yann
9s
created

TwigExtensionBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 4
dl 73
loc 73
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
B buildDefinitions() 24 24 3
A getName() 4 4 1
A isActive() 4 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
namespace Knp\Rad\AutoRegistration\DefinitionBuilder;
4
5
use Knp\Rad\AutoRegistration\DefinitionBuilder;
6
use Knp\Rad\AutoRegistration\Finder\BundleFinder;
7
use Knp\Rad\AutoRegistration\Kernel\KernelWrapper;
8
use Knp\Rad\AutoRegistration\Reflection\ClassAnalyzer;
9
use Symfony\Component\DependencyInjection\Definition;
10
11 View Code Duplication
class TwigExtensionBuilder implements DefinitionBuilder
0 ignored issues
show
Duplication introduced by
This class 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...
12
{
13
    /**
14
     * @var KernelWrapper
15
     */
16
    private $kernel;
17
18
    /**
19
     * @var BundleFinder
20
     */
21
    private $finder;
22
23
    /**
24
     * @var ClassAnalyzer
25
     */
26
    private $analyzer;
27
28
    /**
29
     * @param KernelWrapper $kernel
30
     * @param BundleFinder  $finder
31
     * @param ClassAnalyzer $analyzer
32
     */
33
    public function __construct(KernelWrapper $kernel, BundleFinder $finder, ClassAnalyzer $analyzer)
34
    {
35
        $this->kernel   = $kernel;
36
        $this->finder   = $finder;
37
        $this->analyzer = $analyzer;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function buildDefinitions()
44
    {
45
        $definitions = [];
46
47
        $twigExtensions = $this->finder->findClasses(
48
            $this->kernel->getBundles(),
49
            ['Twig', 'Templating'],
50
            'Twig_Extension'
51
        );
52
53
        foreach ($twigExtensions as $twigExtension) {
54
            if (true === $this->analyzer->needConstruction($twigExtension)) {
55
                continue;
56
            }
57
58
            $definitions[$twigExtension] = (new Definition())
59
                ->setClass($twigExtension)
60
                ->setPublic(false)
61
                ->addTag('twig.extension')
62
            ;
63
        }
64
65
        return $definitions;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getName()
72
    {
73
        return 'twig_extension';
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function isActive()
80
    {
81
        return true;
82
    }
83
}
84