This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * ZfTable ( Module for Zend Framework 2) |
||
4 | * |
||
5 | * @copyright Copyright (c) 2013 Piotr Duda [email protected] |
||
6 | * @license MIT License |
||
7 | */ |
||
8 | |||
9 | namespace ZfTable\Params; |
||
10 | |||
11 | use ZfTable\Params\AbstractAdapter; |
||
12 | use ZfTable\Params\AdapterInterface; |
||
13 | use ZfTable\Table\Exception; |
||
14 | |||
15 | class AdapterArrayObject extends AbstractAdapter implements AdapterInterface, \Zend\Stdlib\InitializableInterface |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * |
||
20 | * @var \ArrayObject | \Zend\Stdlib\ArrayObject |
||
21 | */ |
||
22 | protected $object; |
||
23 | |||
24 | /** |
||
25 | * |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $page; |
||
29 | |||
30 | /** |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $order; |
||
35 | |||
36 | /** |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $column; |
||
41 | |||
42 | /** |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $itemCountPerPage; |
||
47 | |||
48 | /** |
||
49 | * Quick search |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $quickSearch; |
||
53 | |||
54 | |||
55 | /** |
||
56 | * Array of filters |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $filters; |
||
60 | |||
61 | const DEFAULT_PAGE = 1; |
||
62 | const DEFAULT_ORDER = 'asc'; |
||
63 | const DEFAULT_ITEM_COUNT_PER_PAGE = 2; |
||
64 | |||
65 | |||
66 | View Code Duplication | public function __construct($object) |
|
0 ignored issues
–
show
|
|||
67 | { |
||
68 | if ($object instanceof \ArrayObject) { |
||
69 | $this->object = $object; |
||
70 | } elseif ($object instanceof \Zend\Stdlib\ArrayObject) { |
||
0 ignored issues
–
show
The class
Zend\Stdlib\ArrayObject does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
71 | $this->object = $object; |
||
0 ignored issues
–
show
It seems like
$object of type object<Zend\Stdlib\ArrayObject> is incompatible with the declared type object<ArrayObject> of property $object .
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.. ![]() |
|||
72 | } else { |
||
73 | throw new Exception\InvalidArgumentException('parameter must be instance of ArrayObject'); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Init method |
||
79 | */ |
||
80 | public function init() |
||
81 | { |
||
82 | $array = (method_exists($this->object, 'toArray')) ? $this->object->toArray() : $this->object->getArrayCopy(); |
||
83 | |||
84 | $this->page = (isset($array['zfTablePage'])) ? $array['zfTablePage'] : self::DEFAULT_PAGE; |
||
85 | $this->column = (isset($array['zfTableColumn'])) ? $array['zfTableColumn'] : null; |
||
86 | $this->order = (isset($array['zfTableOrder'])) ? $array['zfTableOrder'] : self::DEFAULT_ORDER; |
||
87 | $this->itemCountPerPage = (isset($array['zfTableItemPerPage'])) |
||
88 | ? $array['zfTableItemPerPage'] : $this->getOptions()->getItemCountPerPage(); |
||
89 | $this->quickSearch = (isset($array['zfTableQuickSearch'])) ? $array['zfTableQuickSearch'] : ''; |
||
90 | |||
91 | //Init filters value |
||
92 | if ($this->getTable()->getOptions('showColumnFilters')) { |
||
0 ignored issues
–
show
The call to
AbstractTable::getOptions() has too many arguments starting with 'showColumnFilters' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
93 | foreach ($array as $key => $value) { |
||
94 | if (substr($key, 0, 4) == 'zff_') { |
||
95 | $this->filters[$key] = $value; |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | } |
||
100 | |||
101 | public function getPureValueOfFilter($key) |
||
102 | { |
||
103 | return $this->object[$key]; |
||
104 | } |
||
105 | |||
106 | public function getValueOfFilter($key, $prefix = 'zff_') |
||
107 | { |
||
108 | return $this->filters[$prefix . $key]; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Get page |
||
113 | * |
||
114 | * @return int |
||
115 | */ |
||
116 | public function getPage() |
||
117 | { |
||
118 | return $this->page; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Set page |
||
123 | * |
||
124 | * @param string $page |
||
125 | * @return $this |
||
126 | */ |
||
127 | public function setPage($page) |
||
128 | { |
||
129 | $this->page = $page; |
||
0 ignored issues
–
show
The property
$page was declared of type integer , but $page is of type string . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
![]() |
|||
130 | return $this; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * Get order |
||
135 | * |
||
136 | * @return string |
||
137 | */ |
||
138 | public function getOrder() |
||
139 | { |
||
140 | return $this->order; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Set asc or desc ordering |
||
145 | * |
||
146 | * @param $order |
||
147 | */ |
||
148 | public function setOrder($order) |
||
149 | { |
||
150 | $this->order = $order; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Get column |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | public function getColumn() |
||
159 | { |
||
160 | return ($this->column == '') ? null : $this->column; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * |
||
165 | * @param string $column |
||
166 | * @return $this |
||
167 | */ |
||
168 | public function setColumn($column) |
||
169 | { |
||
170 | $this->column = $column; |
||
171 | return $this; |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Get item count per page |
||
176 | * |
||
177 | * @return int |
||
178 | */ |
||
179 | public function getItemCountPerPage() |
||
180 | { |
||
181 | return $this->itemCountPerPage; |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * |
||
186 | * @param int $itemCountPerPage |
||
187 | */ |
||
188 | public function setItemCountPerPage($itemCountPerPage) |
||
189 | { |
||
190 | $this->itemCountPerPage = $itemCountPerPage; |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * Return offset |
||
195 | * |
||
196 | * @return int |
||
197 | */ |
||
198 | public function getOffset() |
||
199 | { |
||
200 | return ($this->getPage() * $this->getItemCountPerPage()) - $this->getItemCountPerPage(); |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Get quick search string |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | public function getQuickSearch() |
||
209 | { |
||
210 | return $this->quickSearch; |
||
211 | } |
||
212 | } |
||
213 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.