Completed
Push — master ( e6c0c9...d841f8 )
by Jeroen
35:52 queued 19:21
created

AdminList/RedirectAdminListConfigurator.php (4 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\RedirectBundle\AdminList;
4
5
use Doctrine\ORM\EntityManager;
6
use Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface;
7
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
8
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator;
9
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM;
10
use Kunstmaan\RedirectBundle\Form\RedirectAdminType;
11
12
class RedirectAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator
13
{
14
    /**
15
     * @var DomainConfigurationInterface
16
     */
17
    private $domainConfiguration;
18
19
    /**
20
     * @param EntityManager                $em                  The entity manager
21
     * @param AclHelper                    $aclHelper           The acl helper
22
     * @param DomainConfigurationInterface $domainConfiguration
23
     */
24 4
    public function __construct(EntityManager $em, AclHelper $aclHelper = null, DomainConfigurationInterface $domainConfiguration)
25
    {
26 4
        parent::__construct($em, $aclHelper);
27
28 4
        $this->domainConfiguration = $domainConfiguration;
29
30 4
        $this->setAdminType(RedirectAdminType::class);
31 4
        $this->setAdminTypeOptions(['domainConfiguration' => $domainConfiguration]);
32 4
    }
33
34
    /**
35
     * Configure the visible columns
36
     */
37 1
    public function buildFields()
38
    {
39 1
        if ($this->domainConfiguration->isMultiDomainHost()) {
40
            $this->addField('domain', 'redirect.adminlist.header.domain', 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...
41
        }
42 1
        $this->addField('origin', 'redirect.adminlist.header.origin', 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...
43 1
        $this->addField('target', 'redirect.adminlist.header.target', 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...
44 1
        $this->addField('permanent', 'redirect.adminlist.header.permanent', 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...
45 1
        $this->addField('note', 'redirect.adminlist.header.note', true);
46 1
    }
47
48
    /**
49
     * Build filters for admin list
50
     */
51 1
    public function buildFilters()
52
    {
53 1
        if ($this->domainConfiguration->isMultiDomainHost()) {
54
            $hosts = $this->domainConfiguration->getHosts();
55
            $domains = array_combine($hosts, $hosts);
56
            $domains = array_merge(array('' => 'redirect.all'), $domains);
57
            $this->addFilter('domain', new ORM\EnumerationFilterType('domain'), 'redirect.adminlist.filter.domain', $domains);
58
        }
59 1
        $this->addFilter('origin', new ORM\StringFilterType('origin'), 'redirect.adminlist.filter.origin');
60 1
        $this->addFilter('target', new ORM\StringFilterType('target'), 'redirect.adminlist.filter.target');
61 1
        $this->addFilter('permanent', new ORM\BooleanFilterType('permanent'), 'redirect.adminlist.filter.permanent');
62 1
        $this->addFilter('note', new ORM\StringFilterType('note'), 'redirect.adminlist.filter.note');
63 1
    }
64
65
    /**
66
     * @param array|object $item       The item
67
     * @param string       $columnName The column name
68
     *
69
     * @return string
70
     */
71
    public function getValue($item, $columnName)
72
    {
73
        if ($columnName == 'domain' && !$item->getDomain()) {
74
            return 'All domains';
75
        }
76
77
        return parent::getValue($item, $columnName);
78
    }
79
80
    /**
81
     * Get bundle name
82
     *
83
     * @return string
84
     */
85 1
    public function getBundleName()
86
    {
87 1
        return 'KunstmaanRedirectBundle';
88
    }
89
90
    /**
91
     * Get entity name
92
     *
93
     * @return string
94
     */
95 1
    public function getEntityName()
96
    {
97 1
        return 'Redirect';
98
    }
99
}
100