Completed
Push — master ( 269470...f117d4 )
by Paweł
08:47
created

ExistsFilter::apply()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 5
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
17
/**
18
 * @author Jan Góralski <[email protected]>
19
 */
20
final class ExistsFilter implements FilterInterface
21
{
22
    const TRUE = true;
23
    const FALSE = false;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function apply(DataSourceInterface $dataSource, $name, $data, array $options)
29
    {
30
        if (null === $data) {
31
            return;
32
        }
33
34
        $field = isset($options['field']) ? $options['field'] : $name;
35
36
        if (self::TRUE === (bool) $data) {
37
            $dataSource->restrict($dataSource->getExpressionBuilder()->isNotNull($field));
38
39
            return;
40
        }
41
42
        $dataSource->restrict($dataSource->getExpressionBuilder()->isNull($field));
43
    }
44
}
45