Completed
Push — master ( eb83f4...bb238e )
by Maximilian
14s
created

BooleanFilter::filter()   B

Complexity

Conditions 8
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 7.7777
cc 8
eloc 8
nc 3
nop 4
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project 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\DoctrinePHPCRAdminBundle\Filter;
13
14
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
15
use Sonata\CoreBundle\Form\Type\BooleanType;
16
use Sonata\DoctrinePHPCRAdminBundle\Filter\Filter as BaseFilter;
17
18
class BooleanFilter extends BaseFilter
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data)
24
    {
25
        if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) {
26
            return;
27
        }
28
29
        if (is_array($data['value']) || !in_array($data['value'], array(BooleanType::TYPE_NO, BooleanType::TYPE_YES))) {
30
            return;
31
        }
32
33
        $where = $this->getWhere($proxyQuery);
0 ignored issues
show
Compatibility introduced by
$proxyQuery of type object<Sonata\AdminBundl...id\ProxyQueryInterface> is not a sub-type of object<Sonata\DoctrinePH...le\Datagrid\ProxyQuery>. It seems like you assume a concrete implementation of the interface Sonata\AdminBundle\Datagrid\ProxyQueryInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
34
        $where->eq()->field('a.'.$field)->literal($data['value'] == BooleanType::TYPE_YES ? true : false);
35
36
        // filter is active as we have now modified the query
37
        $this->active = true;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getDefaultOptions()
44
    {
45
        return array();
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getRenderSettings()
52
    {
53
        return array('sonata_type_filter_default', array(
54
            'field_type' => $this->getFieldType(),
55
            'field_options' => $this->getFieldOptions(),
56
            'operator_type' => 'hidden',
57
            'operator_options' => array(),
58
            'label' => $this->getLabel(),
59
        ));
60
    }
61
}
62