These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminListBundle\AdminList; |
||
4 | |||
5 | use Kunstmaan\AdminListBundle\AdminList\FilterType\FilterTypeInterface; |
||
6 | use Symfony\Component\HttpFoundation\Request; |
||
7 | |||
8 | /** |
||
9 | * AdminListFilter |
||
10 | */ |
||
11 | class FilterBuilder |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | private $filterDefinitions = array(); |
||
17 | |||
18 | /** |
||
19 | * @var Filter[] |
||
20 | */ |
||
21 | private $currentFilters = array(); |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | private $currentParameters = array(); |
||
27 | |||
28 | /** |
||
29 | * @param string $columnName The column name |
||
30 | * @param FilterTypeInterface $type The filter type |
||
0 ignored issues
–
show
|
|||
31 | * @param string $filterName The name of the filter |
||
0 ignored issues
–
show
Should the type for parameter
$filterName not be string|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types.
Loading history...
|
|||
32 | * @param array $options Options |
||
33 | * |
||
34 | * @return FilterBuilder |
||
35 | */ |
||
36 | 10 | public function add($columnName, FilterTypeInterface $type = null, $filterName = null, array $options = array()) |
|
37 | { |
||
38 | 10 | $this->filterDefinitions[$columnName] = array( |
|
39 | 10 | 'type' => $type, |
|
40 | 10 | 'options' => $options, |
|
41 | 10 | 'filtername' => $filterName, |
|
42 | ); |
||
43 | |||
44 | 10 | return $this; |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * @param string $columnName |
||
49 | * |
||
50 | * @return mixed|null |
||
51 | */ |
||
52 | 3 | public function get($columnName) |
|
53 | { |
||
54 | 3 | if (isset($this->filterDefinitions[$columnName])) { |
|
55 | 3 | return $this->filterDefinitions[$columnName]; |
|
56 | } |
||
57 | |||
58 | 1 | return null; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param string $columnName |
||
63 | * |
||
64 | * @return FilterBuilder |
||
65 | */ |
||
66 | 1 | public function remove($columnName) |
|
67 | { |
||
68 | 1 | if (isset($this->filterDefinitions[$columnName])) { |
|
69 | 1 | unset($this->filterDefinitions[$columnName]); |
|
70 | } |
||
71 | |||
72 | 1 | return $this; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param string $columnName |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | 1 | public function has($columnName) |
|
81 | { |
||
82 | 1 | return isset($this->filterDefinitions[$columnName]); |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return array |
||
87 | */ |
||
88 | 4 | public function getFilterDefinitions() |
|
89 | { |
||
90 | 4 | return $this->filterDefinitions; |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param Request $request |
||
95 | */ |
||
96 | 1 | public function bindRequest(Request $request) |
|
97 | { |
||
98 | 1 | $filterBuilderName = 'filter_' . $request->get('_route'); |
|
99 | |||
100 | 1 | $this->currentParameters = $request->query->all(); |
|
101 | 1 | if (count($this->currentParameters) === 0) { |
|
102 | 1 | if (!$request->query->has('filter')) { |
|
103 | 1 | if ($request->getSession()->has($filterBuilderName)) { |
|
104 | 1 | $savedQuery = $request->getSession()->get($filterBuilderName); |
|
105 | 1 | $request->query->replace($savedQuery); |
|
106 | 1 | $this->currentParameters = $savedQuery; |
|
107 | } |
||
108 | } |
||
109 | } else { |
||
110 | $request->getSession()->set($filterBuilderName, $this->currentParameters); |
||
111 | } |
||
112 | |||
113 | 1 | $filterColumnNames = $request->query->get('filter_columnname'); |
|
114 | 1 | if (isset($filterColumnNames)) { |
|
115 | 1 | $uniqueIds = $request->query->get('filter_uniquefilterid'); |
|
116 | 1 | $index = 0; |
|
117 | 1 | foreach ($filterColumnNames as $filterColumnName) { |
|
118 | 1 | $uniqueId = $uniqueIds[$index]; |
|
119 | 1 | $filter = new Filter($filterColumnName, $this->get($filterColumnName), $uniqueId); |
|
120 | 1 | $this->currentFilters[] = $filter; |
|
121 | 1 | $filter->bindRequest($request); |
|
122 | 1 | ++$index; |
|
123 | } |
||
124 | } |
||
125 | 1 | } |
|
126 | |||
127 | /** |
||
128 | * @return array |
||
129 | */ |
||
130 | 1 | public function getCurrentParameters() |
|
131 | { |
||
132 | 1 | return $this->currentParameters; |
|
133 | } |
||
134 | |||
135 | /** |
||
136 | * @return Filter[] |
||
137 | */ |
||
138 | 5 | public function getCurrentFilters() |
|
139 | { |
||
140 | 5 | return $this->currentFilters; |
|
141 | } |
||
142 | } |
||
143 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.