Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

AbstractArticleCategoryAdminListConfigurator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 4
dl 75
loc 75
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getBundleName() 4 4 1
A getEntityName() 4 4 1
A buildFilters() 4 4 1
A buildFields() 4 4 1
A adaptQueryBuilder() 4 4 1
A getQuery() 14 14 2

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 Kunstmaan\ArticleBundle\AdminList;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\QueryBuilder;
7
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
8
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator;
9
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\StringFilterType;
10
11
/**
12
 * The AdminList configurator for the AbstractArticleAuthor
13
 */
14 View Code Duplication
class AbstractArticleCategoryAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator
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...
15
{
16
    /**
17
     * @param EntityManagerInterface $em        The entity manager
18
     * @param AclHelper              $aclHelper The ACL helper
19
     */
20
    public function __construct(EntityManagerInterface $em, AclHelper $aclHelper)
21
    {
22
        parent::__construct($em, $aclHelper);
23
    }
24
25
    /**
26
     * Return current bundle name.
27
     *
28
     * @return string
29
     */
30
    public function getBundleName()
31
    {
32
        return 'KunstmaanArticleBundle';
33
    }
34
35
    /**
36
     * Return current entity name.
37
     *
38
     * @return string
39
     */
40
    public function getEntityName()
41
    {
42
        return 'AbstractArticleCategory';
43
    }
44
45
    /**
46
     * Configure filters
47
     */
48
    public function buildFilters()
49
    {
50
        $this->addFilter('name', new StringFilterType('name'), 'article.category.list.filter.name');
51
    }
52
53
    /**
54
     * Configure the visible columns
55
     */
56
    public function buildFields()
57
    {
58
        $this->addField('name', 'article.category.list.header.name', true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
    }
60
61
    /**
62
     * @param QueryBuilder $queryBuilder
63
     */
64
    public function adaptQueryBuilder(QueryBuilder $queryBuilder)
65
    {
66
        $queryBuilder->orderBy('b.name', 'ASC');
67
    }
68
69
    /**
70
     * Overwrite the parent function. By adding the TranslationWalker, we can order by the translated fields.
71
     *
72
     * @return \Doctrine\ORM\Query|null
73
     */
74
    public function getQuery()
75
    {
76
        $query = parent::getQuery();
77
78
        if (!is_null($query)) {
79
            $query->setHint(
80
                \Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER,
81
                'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
82
            );
83
            $query->useQueryCache(false);
84
        }
85
86
        return $query;
87
    }
88
}
89