Completed
Push — master ( e2173c...0d60f0 )
by Simonas
61:10
created

AbstractFilter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 6
dl 0
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getState() 0 14 4
A getTags() 0 4 1
A setTags() 0 4 1
A isRelated() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[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 ONGR\FilterManagerBundle\Filter\Widget;
13
14
use ONGR\FilterManagerBundle\Filter\FilterInterface;
15
use ONGR\FilterManagerBundle\Filter\FilterState;
16
use ONGR\FilterManagerBundle\Filter\Helper\DocumentFieldAwareTrait;
17
use ONGR\FilterManagerBundle\Filter\Helper\OptionsAwareTrait;
18
use ONGR\FilterManagerBundle\Filter\Helper\RequestFieldAwareTrait;
19
use ONGR\FilterManagerBundle\Filter\Relation\RelationAwareTrait;
20
use Symfony\Component\HttpFoundation\Request;
21
22
/**
23
 * This class generalises filters using single field value from request.
24
 */
25
abstract class AbstractFilter implements FilterInterface
26
{
27
    use RelationAwareTrait;
28
    use RequestFieldAwareTrait;
29
    use DocumentFieldAwareTrait;
30
    use OptionsAwareTrait;
31
32
    /**
33
     * @var array
34
     */
35
    private $tags = [];
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getState(Request $request)
41
    {
42
        $state = new FilterState();
43
        $value = $request->get($this->getRequestField());
44
45
        if (isset($value) && $value !== '') {
46
            $value = is_array($value) ? array_values($value) : $value;
47
            $state->setActive(true);
48
            $state->setValue($value);
49
            $state->setUrlParameters([$this->getRequestField() => $value]);
50
        }
51
52
        return $state;
53
    }
54
55
56
    /**
57
     * @return string
58
     */
59
    public function getTags()
60
    {
61
        return $this->tags;
62
    }
63
64
    /**
65
     * @param string $tags
66
     */
67
    public function setTags($tags)
68
    {
69
        $this->tags = $tags;
0 ignored issues
show
Documentation Bug introduced by
It seems like $tags of type string is incompatible with the declared type array of property $tags.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function isRelated()
76
    {
77
        return false;
78
    }
79
}
80