Completed
Push — upgrade-boilerplate ( 903b21 )
by Kamil
17:46
created

EntityFilter::apply()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
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
17
/**
18
 * @author Grzegorz Sadowski <[email protected]>
19
 */
20
final class EntityFilter implements FilterInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function apply(DataSourceInterface $dataSource, $name, $data, array $options)
26
    {
27
        if (empty($data) || empty($data['id'])) {
28
            return;
29
        }
30
31
        $field = isset($options['field']) ? $options['field'] : $name;
32
33
        $dataSource->restrict($dataSource->getExpressionBuilder()->equals($field, $data['id']));
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getType()
40
    {
41
        return 'entity';
42
    }
43
}
44