Completed
Push — 2.x ( 359f6e )
by Sullivan
16:25 queued 14:10
created

Filter::isActive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sonata package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrineORMAdminBundle\Filter;
13
14
use Sonata\AdminBundle\Filter\Filter as BaseFilter;
15
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
16
17
abstract class Filter extends BaseFilter
18
{
19
    protected $active = false;
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function apply($queryBuilder, $value)
25
    {
26
        $this->value = $value;
27
        if(is_array($value) && array_key_exists('value', $value)) {
28
            list($alias, $field) = $this->association($queryBuilder, $value);
29
30
            $this->filter($queryBuilder, $alias, $field, $value);
0 ignored issues
show
Documentation introduced by
$value is of type array, 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...
31
        }
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function association(ProxyQueryInterface $queryBuilder, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        $alias = $queryBuilder->entityJoin($this->getParentAssociationMappings());
40
41
        return array($alias, $this->getFieldName());
42
    }
43
44
    /**
45
     * @param \Sonata\AdminBundle\Datagrid\ProxyQueryInterface $queryBuilder
46
     * @param mixed                                            $parameter
47
     */
48
    protected function applyWhere(ProxyQueryInterface $queryBuilder, $parameter)
49
    {
50
        if ($this->getCondition() == self::CONDITION_OR) {
51
            $queryBuilder->orWhere($parameter);
52
        } else {
53
            $queryBuilder->andWhere($parameter);
54
        }
55
56
        // filter is active since it's added to the queryBuilder
57
        $this->active = true;
58
    }
59
60
    /**
61
     * @param \Sonata\AdminBundle\Datagrid\ProxyQueryInterface $queryBuilder
62
     *
63
     * @return string
64
     */
65
    protected function getNewParameterName(ProxyQueryInterface $queryBuilder)
66
    {
67
        // dots are not accepted in a DQL identifier so replace them
68
        // by underscores.
69
        return str_replace('.', '_', $this->getName()) . '_' . $queryBuilder->getUniqueParameterId();
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function isActive()
76
    {
77
        return $this->active;
78
    }
79
}
80