| Conditions | 27 |
| Paths | 3648 |
| Total Lines | 152 |
| Code Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 169 | private function prepareSelect(string $table, array &$queryOptions = []) |
||
| 170 | { |
||
| 171 | $defaultOptions = [ |
||
| 172 | 'columns' => [], |
||
| 173 | 'where' => [], |
||
| 174 | 'order' => [], |
||
| 175 | 'desc' => [], |
||
| 176 | 'fulltext' => [], |
||
| 177 | 'limit' => '50', |
||
| 178 | 'text_length' => '100', |
||
| 179 | 'page' => '1', |
||
| 180 | ]; |
||
| 181 | foreach ($defaultOptions as $name => $value) { |
||
| 182 | if (!isset($queryOptions[$name])) { |
||
| 183 | $queryOptions[$name] = $value; |
||
| 184 | } |
||
| 185 | } |
||
| 186 | $page = \intval($queryOptions['page']); |
||
| 187 | if ($page > 0) { |
||
| 188 | $page -= 1; // Page numbers start at 0 here, instead of 1. |
||
| 189 | } |
||
| 190 | $queryOptions['page'] = $page; |
||
| 191 | |||
| 192 | $this->util->input()->values = $queryOptions; |
||
| 193 | |||
| 194 | // From select.inc.php |
||
| 195 | $indexes = $this->driver->indexes($table); |
||
| 196 | $fields = $this->driver->fields($table); |
||
| 197 | $foreignKeys = $this->admin->columnForeignKeys($table); |
||
| 198 | |||
| 199 | $rights = []; // privilege => 0 |
||
| 200 | $columns = []; // selectable columns |
||
| 201 | $textLength = null; |
||
| 202 | foreach ($fields as $key => $field) { |
||
| 203 | $name = $this->util->fieldName($field); |
||
| 204 | if (isset($field->privileges["select"]) && $name != "") { |
||
| 205 | $columns[$key] = \html_entity_decode(\strip_tags($name), ENT_QUOTES); |
||
| 206 | if ($this->util->isShortable($field)) { |
||
| 207 | $textLength = $this->util->processSelectLength(); |
||
| 208 | } |
||
| 209 | } |
||
| 210 | $rights[] = $field->privileges; |
||
| 211 | } |
||
| 212 | |||
| 213 | list($select, $group) = $this->util->processSelectColumns($columns, $indexes); |
||
| 214 | $isGroup = \count($group) < \count($select); |
||
| 215 | $where = $this->util->processSelectSearch($fields, $indexes); |
||
| 216 | $order = $this->util->processSelectOrder($fields, $indexes); |
||
| 217 | $limit = intval($this->util->processSelectLimit()); |
||
| 218 | |||
| 219 | // if(isset($queryOptions["val"]) && is_ajax()) { |
||
| 220 | // header("Content-Type: text/plain; charset=utf-8"); |
||
| 221 | // foreach($queryOptions["val"] as $unique_idf => $row) { |
||
| 222 | // $as = convertField($fields[key($row)]); |
||
| 223 | // $select = array($as ? $as : escapeId(key($row))); |
||
| 224 | // $where[] = where_check($unique_idf, $fields); |
||
| 225 | // $statement = $this->driver->select($table, $select, $where, $select); |
||
| 226 | // if($statement) { |
||
| 227 | // echo reset($statement->fetchRow()); |
||
| 228 | // } |
||
| 229 | // } |
||
| 230 | // exit; |
||
| 231 | // } |
||
| 232 | |||
| 233 | $primary = $unselected = null; |
||
| 234 | foreach ($indexes as $index) { |
||
| 235 | if ($index->type == "PRIMARY") { |
||
| 236 | $primary = \array_flip($index->columns); |
||
| 237 | $unselected = ($select ? $primary : []); |
||
| 238 | foreach ($unselected as $key => $val) { |
||
| 239 | if (\in_array($this->driver->escapeId($key), $select)) { |
||
| 240 | unset($unselected[$key]); |
||
| 241 | } |
||
| 242 | } |
||
| 243 | break; |
||
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 247 | $tableStatus = $this->driver->tableStatusOrName($table); |
||
| 248 | $oid = $tableStatus->oid; |
||
| 249 | if ($oid && !$primary) { |
||
| 250 | /*$primary = */$unselected = [$oid => 0]; |
||
| 251 | $indexes[] = ["type" => "PRIMARY", "columns" => [$oid]]; |
||
| 252 | } |
||
| 253 | |||
| 254 | $tableName = $this->util->tableName($tableStatus); |
||
| 255 | |||
| 256 | // $set = null; |
||
| 257 | // if(isset($rights["insert"]) || !support("table")) { |
||
| 258 | // $set = ""; |
||
| 259 | // foreach((array) $queryOptions["where"] as $val) { |
||
| 260 | // if($foreignKeys[$val["col"]] && count($foreignKeys[$val["col"]]) == 1 && ($val["op"] == "=" |
||
| 261 | // || (!$val["op"] && !preg_match('~[_%]~', $val["val"])) // LIKE in Editor |
||
| 262 | // )) { |
||
| 263 | // $set .= "&set" . urlencode("[" . $this->util->bracketEscape($val["col"]) . "]") . "=" . urlencode($val["val"]); |
||
| 264 | // } |
||
| 265 | // } |
||
| 266 | // } |
||
| 267 | // $this->util->selectLinks($tableStatus, $set); |
||
| 268 | |||
| 269 | if (!$columns && $this->driver->support("table")) { |
||
| 270 | throw new Exception($this->trans->lang('Unable to select the table') . |
||
| 271 | ($fields ? "." : ": " . $this->driver->error())); |
||
| 272 | } |
||
| 273 | |||
| 274 | // if($page == "last") |
||
| 275 | // { |
||
| 276 | // $found_rows = $this->driver->result($this->driver->countRowsSql($table, $where, $isGroup, $group)); |
||
| 277 | // $page = \floor(\max(0, $found_rows - 1) / $limit); |
||
| 278 | // } |
||
| 279 | |||
| 280 | $options = [ |
||
| 281 | 'columns' => $this->getColumnsOptions($select, $columns, $queryOptions), |
||
| 282 | 'filters' => $this->getFiltersOptions($columns, $indexes, $queryOptions), |
||
| 283 | 'sorting' => $this->getSortingOptions($columns, $queryOptions), |
||
| 284 | 'limit' => $this->getLimitOptions($limit), |
||
| 285 | 'length' => $this->getLengthOptions($textLength), |
||
| 286 | // 'action' => $this->getActionOptions($indexes), |
||
| 287 | ]; |
||
| 288 | |||
| 289 | $select2 = $select; |
||
| 290 | $group2 = $group; |
||
| 291 | if (!$select2) { |
||
| 292 | $select2[] = "*"; |
||
| 293 | $convert_fields = $this->driver->convertFields($columns, $fields, $select); |
||
| 294 | if ($convert_fields) { |
||
| 295 | $select2[] = \substr($convert_fields, 2); |
||
| 296 | } |
||
| 297 | } |
||
| 298 | foreach ($select as $key => $val) { |
||
| 299 | $field = $fields[$this->driver->unescapeId($val)] ?? null; |
||
| 300 | if ($field && ($as = $this->driver->convertField($field))) { |
||
| 301 | $select2[$key] = "$as AS $val"; |
||
| 302 | } |
||
| 303 | } |
||
| 304 | if (!$isGroup && $unselected) { |
||
| 305 | foreach ($unselected as $key => $val) { |
||
| 306 | $select2[] = $this->driver->escapeId($key); |
||
| 307 | if ($group2) { |
||
| 308 | $group2[] = $this->driver->escapeId($key); |
||
| 309 | } |
||
| 310 | } |
||
| 311 | } |
||
| 312 | |||
| 313 | // From driver.inc.php |
||
| 314 | $entity = new TableSelectEntity($table, $select2, $where, $group2, $order, $limit, $page); |
||
| 315 | $query = $this->driver->buildSelectQuery($entity); |
||
| 316 | // From adminer.inc.php |
||
| 317 | $query = \str_replace("\n", " ", $query); |
||
| 318 | |||
| 319 | return [$options, $query, $select, $fields, $foreignKeys, $columns, $indexes, |
||
| 320 | $where, $group, $order, $limit, $page, $textLength, $isGroup, $tableName, $unselected]; |
||
| 321 | } |
||
| 495 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths