Completed
Push — master ( d1e33a...1dc55d )
by Nikola
05:12
created

DoctrineOrmExtension   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 46.91 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 84%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 38
loc 81
ccs 21
cts 25
cp 0.84
rs 10
c 2
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 4 1
A getFilters() 11 11 1
A getTableName() 8 8 2
A getColumnName() 8 8 2
A getFunctions() 11 11 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
 * This file is part of the QueryResourcesLoaderBundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\QueryResourcesLoader\Twig;
11
12
use Symfony\Bridge\Doctrine\RegistryInterface;
13
14
class DoctrineOrmExtension extends \Twig_Extension
15
{
16
    /**
17
     * @var RegistryInterface
18
     */
19
    private $doctrine;
20
21 5
    public function __construct(RegistryInterface $doctrine)
22
    {
23 5
        $this->doctrine = $doctrine;
24 5
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public function getName()
30
    {
31 1
        return 'runopencode_query_resources_loader';
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 View Code Duplication
    public function getFunctions()
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...
38
    {
39
        return array(
40 3
            new \Twig_SimpleFunction('table_name', \Closure::bind(function($entity) {
41 1
                return $this->getTableName($entity);
42 3
            }, $this)),
43 3
            new \Twig_SimpleFunction('column_name', \Closure::bind(function($field, $entity) {
44 1
                return $this->getColumnName($field, $entity);
45 3
            }, $this))
46
        );
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 View Code Duplication
    public function getFilters()
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...
53
    {
54
        return array(
55 1
            new \Twig_SimpleFilter('table_name', \Closure::bind(function($entity) {
56
                return $this->getTableName($entity);
57 1
            }, $this)),
58 1
            new \Twig_SimpleFilter('column_name', \Closure::bind(function($field, $entity) {
59
                return $this->getColumnName($field, $entity);
60 1
            }, $this))
61
        );
62
    }
63
64
    /**
65
     * Get table name for entity
66
     *
67
     * @param string|object $entity Entity
68
     * @return string
69
     */
70 1 View Code Duplication
    protected function getTableName($entity)
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...
71
    {
72 1
        if (is_object($entity)) {
73
            $entity = get_class($entity);
74
        }
75
76 1
        return $this->doctrine->getManagerForClass($entity)->getClassMetadata($entity)->getTableName();
77
    }
78
79
    /**
80
     * Get column name for property of the entity
81
     *
82
     * @param string $field Entity property
83
     * @param string|object $entity
84
     * @return string
85
     */
86 1 View Code Duplication
    protected function getColumnName($field, $entity)
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...
87
    {
88 1
        if (is_object($entity)) {
89
            $entity = get_class($entity);
90
        }
91
92 1
        return $this->doctrine->getManagerForClass($entity)->getClassMetadata($entity)->getColumnName($field);
93
    }
94
}
95