Completed
Push — master ( acc7aa...4059cd )
by Simonas
318:55 queued 254:01
created

AbstractSingleRequestValueFilter::isRelated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\Relation\RelationAwareTrait;
17
use Symfony\Component\HttpFoundation\Request;
18
19
/**
20
 * This class generalises filters using single field value from request.
21
 */
22
abstract class AbstractSingleRequestValueFilter implements FilterInterface
23
{
24
    use RelationAwareTrait;
25
26
    /**
27
     * @var string
28
     */
29
    private $requestField;
30
31
    /**
32
     * @var array
33
     */
34
    private $tags = [];
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getState(Request $request)
40
    {
41
        $state = new FilterState();
42
        $value = $request->get($this->getRequestField());
43
44
        if (isset($value) && $value !== '') {
45
            $value = is_array($value) ? array_values($value) : $value;
46
            $state->setActive(true);
47
            $state->setValue($value);
48
            $state->setUrlParameters([$this->getRequestField() => $value]);
49
        }
50
51
        return $state;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getRequestField()
58
    {
59
        return $this->requestField;
60
    }
61
62
    /**
63
     * @param string $requestField
64
     */
65
    public function setRequestField($requestField)
66
    {
67
        $this->requestField = $requestField;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getTags()
74
    {
75
        return $this->tags;
76
    }
77
78
    /**
79
     * @param string $tags
80
     */
81
    public function setTags($tags)
82
    {
83
        $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...
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function isRelated()
90
    {
91
        return false;
92
    }
93
}
94