BooleanFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 46
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isApplicable() 0 4 1
A getExpression() 0 8 1
A buildForm() 0 12 1
A configureOptions() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid\Filter;
6
7
use Psi\Component\Grid\FilterInterface;
8
use Psi\Component\ObjectAgent\Query\Comparison;
9
use Psi\Component\ObjectAgent\Query\Expression;
10
use Psi\Component\ObjectAgent\Query\Query;
11
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
12
use Symfony\Component\Form\FormBuilderInterface;
13
use Symfony\Component\OptionsResolver\OptionsResolver;
14
15
class BooleanFilter implements FilterInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function buildForm(FormBuilderInterface $builder, array $options)
21
    {
22
        $builder->add('value', ChoiceType::class, [
23
            'choices' => [
24
                '' => 'any',
25
                1 => 'yes',
26
                0 => 'no',
27
            ],
28
            'expanded' => true,
29
            'placeholder' => $options['placeholder'],
30
        ]);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function isApplicable(array $data): bool
37
    {
38
        return isset($data['value']);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getExpression(string $fieldName, array $data): Expression
45
    {
46
        return Query::comparison(
47
            Comparison::EQUALS,
48
            $fieldName,
49
            $data['value']
50
        );
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function configureOptions(OptionsResolver $options)
57
    {
58
        $options->setDefault('placeholder', null);
59
    }
60
}
61