Completed
Pull Request — 5.0 (#2162)
by Kevin
14:33
created

AbstractArticleTagAdminListConfigurator.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\ArticleBundle\AdminList;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Doctrine\ORM\QueryBuilder;
8
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
9
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator;
10
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\StringFilterType;
11
12
/**
13
 * The AdminList configurator for the AbstractArticleAuthor
14
 */
15 View Code Duplication
class AbstractArticleTagAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator
0 ignored issues
show
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...
16
{
17
    /**
18
     * @param EntityManagerInterface $em         The entity manager
19
     * @param AclHelper     $aclHelper  The ACL helper
20
     */
21
    public function __construct(EntityManagerInterface $em, AclHelper $aclHelper)
22
    {
23
        parent::__construct($em, $aclHelper);
24
    }
25
26
    /**
27
     * Return current bundle name.
28
     *
29
     * @return string
30
     */
31
    public function getBundleName()
32
    {
33
        return "KunstmaanArticleBundle";
34
    }
35
36
    /**
37
     * Return current entity name.
38
     *
39
     * @return string
40
     */
41
    public function getEntityName()
42
    {
43
        return "AbstractArticleTag";
44
    }
45
46
    /**
47
     * Configure filters
48
     */
49
    public function buildFilters()
50
    {
51
        $this->addFilter('name', new StringFilterType('name'), 'article.tag.list.filter.name');
52
    }
53
54
    /**
55
     * Configure the visible columns
56
     */
57
    public function buildFields()
58
    {
59
        $this->addField('name', 'article.tag.list.header.name', true);
0 ignored issues
show
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...
60
    }
61
62
63
    /**
64
     * @param QueryBuilder $queryBuilder
65
     */
66
    public function adaptQueryBuilder(QueryBuilder $queryBuilder)
67
    {
68
        $queryBuilder->orderBy('b.name', 'ASC');
69
    }
70
71
    /**
72
     * Overwrite the parent function. By adding the TranslationWalker, we can order by the translated fields.
73
     *
74
     * @return \Doctrine\ORM\Query|null
75
     */
76
    public function getQuery()
77
    {
78
        $query = parent::getQuery();
79
80
        if (!is_null($query)) {
81
            $query->setHint(
82
                \Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER,
83
                'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
84
            );
85
            $query->useQueryCache(false);
86
        }
87
88
        return $query;
89
    }
90
}
91