| Conditions | 17 |
| Paths | 73 |
| Total Lines | 76 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 16 | protected function getQueryBuilder() |
||
| 17 | { |
||
| 18 | if (!$this->objectManager instanceof EntityManager) { |
||
| 19 | throw new \Exception("Expected EntityManager, instead it's: ", get_class($this->objectManager)); |
||
| 20 | } |
||
| 21 | |||
| 22 | $columns = $this->getColumns(); |
||
| 23 | $fieldList = []; |
||
| 24 | foreach ($columns as $column) { |
||
| 25 | if ($column instanceof GridColumn && $column->isSearchable()) { |
||
| 26 | $fieldList[$column->getField()] = true; |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | $qb = $this->objectManager->createQueryBuilder(); |
||
| 31 | $orderBy = array(); |
||
| 32 | foreach ($this->orderBy as $key => $value) { |
||
| 33 | $orderBy[] = "u.{$key} {$value}"; |
||
| 34 | } |
||
| 35 | |||
| 36 | $qb->add('select', 'u') |
||
| 37 | ->add('from', "{$this->objectName} u") |
||
| 38 | ->setFirstResult($this->offset) |
||
| 39 | ->setMaxResults($this->limit); |
||
| 40 | |||
| 41 | if ($this->orderBy) { |
||
| 42 | $orderByStr = implode(',', $orderBy); |
||
| 43 | $qb->add('orderBy', $orderByStr); |
||
| 44 | } |
||
| 45 | |||
| 46 | if ($this->filter) { |
||
| 47 | /** @var ClassMetadata $classMetaData */ |
||
| 48 | $classMetaData = $this->getClassMetadata(); |
||
| 49 | $classFields = $classMetaData->fieldMappings; |
||
| 50 | |||
| 51 | $validFilters = array_intersect_key($this->filter, $classFields); |
||
| 52 | |||
| 53 | $query = array(); |
||
| 54 | foreach ($validFilters as $key => $value) { |
||
| 55 | if (isset($fieldList[$key])) { |
||
| 56 | if (is_array($value)) { |
||
| 57 | $query[] = "u.{$key} IN :{$key}"; |
||
| 58 | } else { |
||
| 59 | $query[] = "u.{$key} = :{$key}"; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | $qb->setParameter($key, $value); |
||
| 63 | } |
||
| 64 | if ($query) { |
||
| 65 | $qb->add('where', implode(' and ', $query)); |
||
| 66 | } else { |
||
| 67 | $starFilter = array_intersect_key($this->filter, ['*' => null]); |
||
| 68 | if ($starFilter) { |
||
| 69 | $value = current($starFilter); |
||
| 70 | $starQuery = []; |
||
| 71 | foreach (array_keys($classFields) as $key) { |
||
| 72 | if (isset($fieldList[$key])) { |
||
| 73 | $starQuery[] = "u.{$key} like :{$key}"; |
||
| 74 | $qb->setParameter($key, $value); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($starQuery) { |
||
| 79 | $star = implode(' or ', $starQuery); |
||
| 80 | |||
| 81 | if ($query) { |
||
| 82 | $qb->andWhere($star); |
||
| 83 | } else { |
||
| 84 | $qb->add('where', $star); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | return $qb; |
||
| 92 | } |
||
| 192 |
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