| Conditions | 25 |
| Paths | 232 |
| Total Lines | 55 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 121 | public function processSelectSearch(array $fields, array $indexes): array |
||
| 122 | { |
||
| 123 | $expressions = []; |
||
| 124 | foreach ($indexes as $i => $index) { |
||
| 125 | if ($index->type == 'FULLTEXT' && $this->input->values['fulltext'][$i] != '') { |
||
| 126 | $columns = \array_map(function ($column) { |
||
| 127 | return $this->driver->escapeId($column); |
||
| 128 | }, $index->columns); |
||
| 129 | $expressions[] = 'MATCH (' . \implode(', ', $columns) . ') AGAINST (' . |
||
| 130 | $this->driver->quote($this->input->values['fulltext'][$i]) . |
||
| 131 | (isset($this->input->values['boolean'][$i]) ? ' IN BOOLEAN MODE' : '') . ')'; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | foreach ((array) $this->input->values['where'] as $key => $val) { |
||
| 135 | if ("$val[col]$val[val]" != '' && in_array($val['op'], $this->driver->operators())) { |
||
| 136 | $prefix = ''; |
||
| 137 | $cond = " $val[op]"; |
||
| 138 | if (\preg_match('~IN$~', $val['op'])) { |
||
| 139 | $in = $this->processLength($val['val']); |
||
| 140 | $cond .= ' ' . ($in != '' ? $in : '(NULL)'); |
||
| 141 | } elseif ($val['op'] == 'SQL') { |
||
| 142 | $cond = " $val[val]"; // SQL injection |
||
| 143 | } elseif ($val['op'] == 'LIKE %%') { |
||
| 144 | $cond = ' LIKE ' . $this->_processInput($fields[$val['col']], "%$val[val]%"); |
||
|
|
|||
| 145 | } elseif ($val['op'] == 'ILIKE %%') { |
||
| 146 | $cond = ' ILIKE ' . $this->_processInput($fields[$val['col']], "%$val[val]%"); |
||
| 147 | } elseif ($val['op'] == 'FIND_IN_SET') { |
||
| 148 | $prefix = "$val[op](" . $this->driver->quote($val['val']) . ', '; |
||
| 149 | $cond = ')'; |
||
| 150 | } elseif (!\preg_match('~NULL$~', $val['op'])) { |
||
| 151 | $cond .= ' ' . $this->_processInput($fields[$val['col']], $val['val']); |
||
| 152 | } |
||
| 153 | if ($val['col'] != '') { |
||
| 154 | $expressions[] = $prefix . $this->driver->convertSearch( |
||
| 155 | $this->driver->escapeId($val['col']), |
||
| 156 | $val, |
||
| 157 | $fields[$val['col']] |
||
| 158 | ) . $cond; |
||
| 159 | } else { |
||
| 160 | // find anywhere |
||
| 161 | $cols = []; |
||
| 162 | foreach ($fields as $name => $field) { |
||
| 163 | if ((\preg_match('~^[-\d.' . (\preg_match('~IN$~', $val['op']) ? ',' : '') . ']+$~', $val['val']) || |
||
| 164 | !\preg_match('~' . $this->driver->numberRegex() . '|bit~', $field->type)) && |
||
| 165 | (!\preg_match("~[\x80-\xFF]~", $val['val']) || \preg_match('~char|text|enum|set~', $field->type)) && |
||
| 166 | (!\preg_match('~date|timestamp~', $field->type) || \preg_match('~^\d+-\d+-\d+~', $val['val'])) |
||
| 167 | ) { |
||
| 168 | $cols[] = $prefix . $this->driver->convertSearch($this->driver->escapeId($name), $val, $field) . $cond; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | $expressions[] = ($cols ? '(' . \implode(' OR ', $cols) . ')' : '1 = 0'); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | } |
||
| 175 | return $expressions; |
||
| 176 | } |
||
| 229 |