Completed
Push — master ( cc21e8...5c80a5 )
by Simonas
65:42
created

Filter/Widget/AbstractSingleRequestValueFilter.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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