Completed
Push — master ( cac9ba...8627fd )
by Michał
17s
created

BooleanFilter::apply()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 6
nc 3
nop 4
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Component\Grid\Filter;
13
14
use Sylius\Component\Grid\Data\DataSourceInterface;
15
use Sylius\Component\Grid\Filtering\FilterInterface;
16
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
17
18
/**
19
 * @author Paweł Jędrzejewski <[email protected]>
20
 */
21
class BooleanFilter implements FilterInterface
22
{
23
    const TRUE  = 'true';
24
    const FALSE = 'false';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function apply(DataSourceInterface $dataSource, $name, $data, array $options)
30
    {
31
        if (empty($data)) {
32
            return;
33
        }
34
35
        $field = isset($options['field']) ? $options['field'] : $name;
36
37
        $data = self::TRUE === $data;
38
39
        $dataSource->restrict($dataSource->getExpressionBuilder()->equals($field, $data));
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getType()
46
    {
47
        return 'boolean';
48
    }
49
}
50