Completed
Pull Request — master (#201)
by Simonas
114:27 queued 49:20
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
 * @deprecated Will be renamed to AbstractFilter.
26
 */
27
abstract class AbstractFilter implements FilterInterface
28
{
29
    use RelationAwareTrait;
30
    use RequestFieldAwareTrait;
31
    use DocumentFieldAwareTrait;
0 ignored issues
show
Deprecated Code introduced by
The trait ONGR\FilterManagerBundle...DocumentFieldAwareTrait has been deprecated with message: FieldAwareTrait will be changed to DocumentFieldAwareTrait in 2.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
32
    use OptionsAwareTrait;
33
34
    /**
35
     * @var array
36
     */
37
    private $tags = [];
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getState(Request $request)
43
    {
44
        $state = new FilterState();
45
        $value = $request->get($this->getRequestField());
46
47
        if (isset($value) && $value !== '') {
48
            $value = is_array($value) ? array_values($value) : $value;
49
            $state->setActive(true);
50
            $state->setValue($value);
51
            $state->setUrlParameters([$this->getRequestField() => $value]);
52
        }
53
54
        return $state;
55
    }
56
57
58
    /**
59
     * @return string
60
     */
61
    public function getTags()
62
    {
63
        return $this->tags;
64
    }
65
66
    /**
67
     * @param string $tags
68
     */
69
    public function setTags($tags)
70
    {
71
        $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...
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function isRelated()
78
    {
79
        return false;
80
    }
81
}
82