| Conditions | 16 |
| Paths | 25 |
| Total Lines | 62 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 25 | protected function getQueryBuilder() |
||
| 26 | { |
||
| 27 | if (!$this->objectManager instanceof DocumentManager) { |
||
| 28 | throw new \Exception("Should be DocumentManager, instead it's ".get_class($this->objectManager)); |
||
| 29 | } |
||
| 30 | $qb = $this->objectManager->createQueryBuilder($this->objectName); |
||
| 31 | |||
| 32 | /** @var ClassMetadata $classMetaData */ |
||
| 33 | $classMetaData = $this->getClassMetadata(); |
||
| 34 | $classFields = $classMetaData->fieldMappings; |
||
| 35 | |||
| 36 | $columns = $this->getColumns(); |
||
| 37 | $fieldList = []; |
||
| 38 | foreach ($columns as $column) { |
||
| 39 | if ($column instanceof GridColumn && $column->isSearchable()) { |
||
| 40 | $fieldList[$column->getField()] = true; |
||
| 41 | } |
||
| 42 | } |
||
| 43 | if ($this->filter) { |
||
| 44 | $validFilters = array_intersect_key($this->filter, $classFields); |
||
| 45 | |||
| 46 | $query = []; |
||
| 47 | foreach ($validFilters as $key => $value) { |
||
| 48 | if (isset($fieldList[$key])) { |
||
| 49 | if (is_array($value)) { |
||
| 50 | $qb->field($key)->in($value); |
||
| 51 | } else { |
||
| 52 | $qb->field($key)->equals($value); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | if (!$query) { |
||
| 57 | $starFilter = array_intersect_key($this->filter, ['*' => null]); |
||
| 58 | if ($starFilter) { |
||
| 59 | $value = current($starFilter); |
||
| 60 | foreach ($classFields as $key => $info) { |
||
| 61 | if (isset($fieldList[$key])) { |
||
| 62 | $expr = $qb->expr()->field($key); |
||
| 63 | switch ($info['type']) { |
||
| 64 | case 'integer': |
||
| 65 | $expr = $expr->equals(intval($value)); |
||
| 66 | break; |
||
| 67 | default: |
||
| 68 | $expr = $expr->equals($value); |
||
| 69 | } |
||
| 70 | $qb->addOr($expr); |
||
| 71 | } |
||
| 72 | // @TODO - maybe allow pattern searches some day: new \MongoRegex('/.*'.$value.'.*/') |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | if ($this->orderBy) { |
||
| 78 | foreach ($this->orderBy as $key => $direction) { |
||
| 79 | $qb->sort($key, $direction); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | $qb->limit($this->limit); |
||
| 84 | $qb->skip($this->offset); |
||
| 85 | |||
| 86 | return $qb; |
||
| 87 | } |
||
| 176 |
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