| Total Complexity | 94 |
| Total Lines | 627 |
| Duplicated Lines | 20.26 % |
| Coverage | 0.72% |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like QueryBuilderFactory often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use QueryBuilderFactory, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class QueryBuilderFactory extends AbstractQuery |
||
| 8 | { |
||
| 9 | const DIRECTION_AZ = 'asc'; |
||
| 10 | |||
| 11 | const DIRECTION_ZA = 'desc'; |
||
| 12 | |||
| 13 | const DEFAULT_OPERATOR = 'eq'; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var QueryBuilder |
||
| 17 | */ |
||
| 18 | protected $qBuilder; |
||
| 19 | |||
| 20 | protected $fields; |
||
| 21 | |||
| 22 | protected $filtering; |
||
| 23 | |||
| 24 | protected $orFiltering; |
||
| 25 | |||
| 26 | protected $relationEntityAlias; |
||
| 27 | |||
| 28 | protected $sorting; |
||
| 29 | |||
| 30 | protected $joins; |
||
| 31 | |||
| 32 | protected $rel; |
||
| 33 | |||
| 34 | protected $printing; |
||
| 35 | |||
| 36 | protected $page; |
||
| 37 | |||
| 38 | protected $pageLength; |
||
| 39 | |||
| 40 | protected $select; |
||
| 41 | |||
| 42 | /** @todo move this file in configuration */ |
||
| 43 | /** @todo type number|text */ |
||
| 44 | private static $operatorMap = [ |
||
| 45 | //'eq' => [ |
||
| 46 | //'filtro' => '=', |
||
| 47 | //'tipo' => 'data|numero|stringa', |
||
| 48 | //'meta' => '%{foo}%' |
||
| 49 | //], |
||
| 50 | 'eq' => [ |
||
| 51 | 'meta' => '=', |
||
| 52 | ], |
||
| 53 | 'neq' => [ |
||
| 54 | 'meta' => '!=', |
||
| 55 | ], |
||
| 56 | 'gt' => [ |
||
| 57 | 'meta' => '>', |
||
| 58 | ], |
||
| 59 | 'gte' => [ |
||
| 60 | 'meta' => '>=', |
||
| 61 | ], |
||
| 62 | 'lt' => [ |
||
| 63 | 'meta' => '<', |
||
| 64 | ], |
||
| 65 | 'lte' => [ |
||
| 66 | 'meta' => '<=', |
||
| 67 | ], |
||
| 68 | 'startswith' => [ |
||
| 69 | 'meta' => 'LIKE', |
||
| 70 | 'substitution_pattern' => '{string}%' |
||
| 71 | ], |
||
| 72 | 'contains' => [ |
||
| 73 | 'meta' => 'LIKE', |
||
| 74 | 'substitution_pattern' => '%{string}%' |
||
| 75 | ], |
||
| 76 | 1 | 'notcontains' => [ |
|
| 77 | 'meta' => 'NOT LIKE', |
||
| 78 | 1 | 'substitution_pattern' => '%{string}%' |
|
| 79 | ], |
||
| 80 | 'endswith' => [ |
||
| 81 | 'meta' => 'LIKE', |
||
| 82 | 'substitution_pattern' => '%{string}' |
||
| 83 | ], |
||
| 84 | 'list' => [ |
||
| 85 | 'meta' => 'IN', |
||
| 86 | 'substitution_pattern' => '({string})', |
||
| 87 | ], |
||
| 88 | 'field_eq' => [ |
||
| 89 | 'meta' => '=', |
||
| 90 | ], |
||
| 91 | ]; |
||
| 92 | |||
| 93 | public function getAvailableFilters() |
||
| 94 | { |
||
| 95 | return array_keys(static::$operatorMap); |
||
| 96 | } |
||
| 97 | |||
| 98 | public function setFields(array $fields = []) |
||
| 99 | { |
||
| 100 | $this->fields = $fields; |
||
| 101 | |||
| 102 | return $this; |
||
| 103 | } |
||
| 104 | |||
| 105 | public function getFields() |
||
| 106 | { |
||
| 107 | if (null === $this->fields) { |
||
| 108 | throw new \RuntimeException( |
||
| 109 | 'Oops! Fields are not defined' |
||
| 110 | ); |
||
| 111 | } |
||
| 112 | |||
| 113 | return $this->fields; |
||
| 114 | } |
||
| 115 | |||
| 116 | public function setFilters(array $filtering = []) |
||
| 121 | } |
||
| 122 | |||
| 123 | public function setOrFilters(array $orFiltering = []) |
||
| 124 | { |
||
| 125 | $this->orFiltering = $orFiltering; |
||
| 126 | |||
| 127 | return $this; |
||
| 128 | } |
||
| 129 | |||
| 130 | public function setSorting(array $sorting = []) |
||
| 131 | { |
||
| 132 | $this->sorting = $sorting; |
||
| 133 | |||
| 134 | return $this; |
||
| 135 | } |
||
| 136 | |||
| 137 | public function getFilters() |
||
| 138 | { |
||
| 139 | return $this->filtering; |
||
| 140 | } |
||
| 141 | |||
| 142 | public function getOrFilters() |
||
| 143 | { |
||
| 144 | return $this->orFiltering; |
||
| 145 | } |
||
| 146 | |||
| 147 | private function noExistsJoin($prevEntityAlias, $currentEntityAlias) |
||
| 148 | { |
||
| 149 | if (null === $this->joins) { |
||
| 150 | $this->joins = []; |
||
| 151 | } |
||
| 152 | |||
| 153 | $needle = $prevEntityAlias . "_" . $currentEntityAlias; |
||
| 154 | |||
| 155 | return ! in_array($needle, $this->joins); |
||
| 156 | } |
||
| 157 | |||
| 158 | private function storeJoin($prevEntityAlias, $currentEntityAlias) |
||
| 159 | { |
||
| 160 | $needle = $prevEntityAlias . "_" . $currentEntityAlias; |
||
| 161 | $this->joins[$needle] = $needle; |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param String $relation Nome della relazione semplice (groups.name) o con embedded (_embedded.groups.name) |
||
| 166 | * @return $this |
||
| 167 | */ |
||
| 168 | public function join(String $relation) |
||
| 169 | { |
||
| 170 | $relation = explode('|', $relation)[0]; |
||
| 171 | $relations = [$relation]; |
||
| 172 | |||
| 173 | if (strstr($relation, '_embedded.')) { |
||
| 174 | $embeddedFields = explode('.', $relation); |
||
| 175 | $relation = $this->parser->camelize($embeddedFields[1]); |
||
| 176 | |||
| 177 | // elimino l'ultimo elemento che dovrebbe essere il nome del campo |
||
| 178 | unset($embeddedFields[count($embeddedFields) - 1]); |
||
| 179 | |||
| 180 | // elimino il primo elemento _embedded |
||
| 181 | unset($embeddedFields[0]); |
||
| 182 | |||
| 183 | $relations = $embeddedFields; |
||
| 184 | } |
||
| 185 | |||
| 186 | $entityName = $this->getEntityName(); |
||
| 187 | $entityAlias = $this->entityAlias; |
||
| 188 | |||
| 189 | foreach ($relations as $relation) { |
||
| 190 | |||
| 191 | $relation = $this->parser->camelize($relation); |
||
| 192 | $relationEntityAlias = 'table_' . $relation; |
||
| 193 | |||
| 194 | $metadata = $this->manager->getClassMetadata($entityName); |
||
| 195 | |||
| 196 | if ($metadata->hasAssociation($relation)) { |
||
| 197 | |||
| 198 | $association = $metadata->getAssociationMapping($relation); |
||
| 199 | |||
| 200 | $fieldName = $this->parser->camelize($association['fieldName']); |
||
| 201 | |||
| 202 | if ($this->noExistsJoin($relationEntityAlias, $relation)) { |
||
| 203 | |||
| 204 | $this->qBuilder |
||
| 205 | ->join($entityAlias . "." . $fieldName, $relationEntityAlias); |
||
| 206 | |||
| 207 | $this->storeJoin($relationEntityAlias, $relation); |
||
| 208 | } |
||
| 209 | $entityName = $association['targetEntity']; |
||
| 210 | $entityAlias = $relationEntityAlias; |
||
| 211 | } |
||
| 212 | |||
| 213 | $this->setRelationEntityAlias($relationEntityAlias); |
||
| 214 | } |
||
| 215 | |||
| 216 | return $this; |
||
| 217 | } |
||
| 218 | |||
| 219 | public function filter() |
||
| 220 | { |
||
| 221 | if (null === $this->filtering) { |
||
| 222 | throw new \RuntimeException( |
||
| 223 | 'Oops! Filtering is not defined' |
||
| 224 | ); |
||
| 225 | } |
||
| 226 | |||
| 227 | if (!$this->fields) { |
||
| 228 | throw new \RuntimeException( |
||
| 229 | 'Oops! Fields are not defined' |
||
| 230 | ); |
||
| 231 | } |
||
| 232 | |||
| 233 | foreach ($this->filtering as $filter => $value) { |
||
| 234 | $this->applyFilterAnd($filter, $value); |
||
| 235 | } |
||
| 236 | |||
| 237 | if (null !== $this->orFiltering) { |
||
| 238 | $orFilter = []; |
||
| 239 | $orFilter['orCondition'] = null; |
||
| 240 | $orFilter['parameters'] = []; |
||
| 241 | |||
| 242 | foreach ($this->orFiltering as $filter => $value) { |
||
| 243 | $orFilter = $this->applyFilterOr($filter, $value, $orFilter); |
||
| 244 | } |
||
| 245 | |||
| 246 | if ((count($orFilter) > 0) && ($orFilter['orCondition'] != null)) { |
||
| 247 | $this->qBuilder->andWhere($orFilter['orCondition']); |
||
| 248 | |||
| 249 | foreach ($orFilter['parameters'] as $parameter) { |
||
| 250 | $this->qBuilder->setParameter($parameter['field'], $parameter['value']); |
||
| 251 | } |
||
| 252 | } |
||
| 253 | } |
||
| 254 | |||
| 255 | return $this; |
||
| 256 | } |
||
| 257 | |||
| 258 | private function applyFilterAnd($filter, $value) |
||
| 259 | { |
||
| 260 | $whereCondition = null; |
||
| 261 | $filterAndOperator = explode('|',$filter); |
||
| 262 | |||
| 263 | $fieldName = $filterAndOperator[0]; |
||
| 264 | $fieldName = $this->parser->camelize($fieldName); |
||
| 265 | |||
| 266 | $operator = self::$operatorMap[self::DEFAULT_OPERATOR]; |
||
| 267 | if(isset($filterAndOperator[1])){ |
||
| 268 | $operator = self::$operatorMap[$filterAndOperator[1]]; |
||
| 269 | } |
||
| 270 | |||
| 271 | // controllo se il filtro che mi arriva dalla richiesta è una proprietà di questa entità |
||
| 272 | // esempio per users: filtering[username|contains]=mado |
||
| 273 | if (in_array($fieldName, $this->fields)) { |
||
| 274 | |||
| 275 | $salt = ''; |
||
| 276 | View Code Duplication | foreach ($this->qBuilder->getParameters() as $parameter) { |
|
| 277 | if ($parameter->getName() == 'field_' . $fieldName) { |
||
| 278 | $salt = '_' . rand(111, 999); |
||
| 279 | } |
||
| 280 | } |
||
| 281 | |||
| 282 | // filtering[foo|bar] |
||
| 283 | // $filterAndOperator[0] = 'foo' |
||
| 284 | // $filterAndOperator[1] = 'bar' |
||
| 285 | View Code Duplication | if (isset($filterAndOperator[1])) { |
|
| 286 | if ('list' == $filterAndOperator[1]) { |
||
| 287 | $whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' (:field_'.$fieldName . $salt . ')'; |
||
| 288 | } else if ('field_eq' == $filterAndOperator[1]) { |
||
| 289 | $whereCondition = |
||
| 290 | $this->entityAlias . '.' . $fieldName . ' '. |
||
| 291 | $operator['meta'] . '' . |
||
| 292 | $this->entityAlias . '.' . $value |
||
| 293 | ; |
||
| 294 | //} else { |
||
| 295 | //throw new \RuntimeException( |
||
| 296 | //'Oops! Eccezzione' |
||
| 297 | //); |
||
| 298 | } else { |
||
| 299 | $whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' :field_'.$fieldName . $salt; |
||
| 300 | } |
||
| 301 | } else { |
||
| 302 | $whereCondition = $this->entityAlias.'.'.$fieldName.' = :field_'.$fieldName . $salt; |
||
| 303 | } |
||
| 304 | |||
| 305 | $this->qBuilder->andWhere($whereCondition); |
||
| 306 | |||
| 307 | View Code Duplication | if (isset($operator['substitution_pattern'])) { |
|
| 308 | if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
||
| 309 | $value = explode(',', $value); |
||
| 310 | } else { |
||
| 311 | $value = str_replace( |
||
| 312 | '{string}', |
||
| 313 | $value, |
||
| 314 | $operator['substitution_pattern'] |
||
| 315 | ); |
||
| 316 | } |
||
| 317 | } |
||
| 318 | |||
| 319 | $this->qBuilder->setParameter('field_' . $fieldName . $salt, $value); |
||
| 320 | } else { |
||
| 321 | $isNotARelation = 0 !== strpos($fieldName, 'Embedded.'); |
||
| 322 | if ($isNotARelation) { |
||
| 323 | $whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' ' . $this->entityAlias . '.' . $value; |
||
| 324 | $this->qBuilder->andWhere($whereCondition); |
||
| 325 | } |
||
| 326 | } |
||
| 327 | |||
| 328 | // controllo se il filtro si riferisce ad una relazione dell'entità quindi devo fare dei join |
||
| 329 | // esempio per users: filtering[_embedded.groups.name|eq]=admin |
||
| 330 | if (strstr($filter, '_embedded.')) { |
||
| 331 | |||
| 332 | $this->join($filter); |
||
| 333 | $relationEntityAlias = $this->getRelationEntityAlias(); |
||
| 334 | |||
| 335 | $embeddedFields = explode('.', $fieldName); |
||
| 336 | $fieldName = $this->parser->camelize($embeddedFields[count($embeddedFields)-1]); |
||
| 337 | |||
| 338 | $salt = ''; |
||
| 339 | View Code Duplication | foreach ($this->qBuilder->getParameters() as $parameter) { |
|
| 340 | if ($parameter->getName() == 'field_' . $fieldName) { |
||
| 341 | $salt = '_' . rand(111, 999); |
||
| 342 | } |
||
| 343 | } |
||
| 344 | |||
| 345 | View Code Duplication | if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
|
| 346 | $whereCondition = $relationEntityAlias.'.'.$fieldName.' '.$operator['meta'].' (:field_'.$fieldName . $salt . ')'; |
||
| 347 | } else { |
||
| 348 | $whereCondition = $relationEntityAlias.'.'.$fieldName.' '.$operator['meta'].' :field_'.$fieldName . $salt; |
||
| 349 | } |
||
| 350 | |||
| 351 | $this->qBuilder->andWhere($whereCondition); |
||
| 352 | View Code Duplication | if (isset($operator['substitution_pattern'])) { |
|
| 353 | if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
||
| 354 | $value = explode(',', $value); |
||
| 355 | } else { |
||
| 356 | $value = str_replace( |
||
| 357 | '{string}', |
||
| 358 | $value, |
||
| 359 | $operator['substitution_pattern'] |
||
| 360 | ); |
||
| 361 | } |
||
| 362 | } |
||
| 363 | |||
| 364 | $this->qBuilder->setParameter('field_' . $fieldName . $salt, $value); |
||
| 365 | } |
||
| 366 | } |
||
| 367 | |||
| 368 | private function applyFilterOr($filter, $value, $orCondition) |
||
| 369 | { |
||
| 370 | $whereCondition = null; |
||
| 371 | $filterAndOperator = explode('|',$filter); |
||
| 372 | |||
| 373 | $fieldName = $filterAndOperator[0]; |
||
| 374 | $fieldName = $this->parser->camelize($fieldName); |
||
| 375 | |||
| 376 | $operator = self::$operatorMap[self::DEFAULT_OPERATOR]; |
||
| 377 | if(isset($filterAndOperator[1])){ |
||
| 378 | $operator = self::$operatorMap[$filterAndOperator[1]]; |
||
| 379 | } |
||
| 380 | |||
| 381 | // controllo se il filtro che mi arriva dalla richiesta è una proprietà di questa entità |
||
| 382 | // esempio per users: filtering[username|contains]=mado |
||
| 383 | if (in_array($fieldName, $this->fields)) { |
||
| 384 | |||
| 385 | $salt = ''; |
||
| 386 | View Code Duplication | foreach ($this->qBuilder->getParameters() as $parameter) { |
|
| 387 | if ($parameter->getName() == 'field_' . $fieldName) { |
||
| 388 | $salt = '_' . rand(111, 999); |
||
| 389 | } |
||
| 390 | } |
||
| 391 | |||
| 392 | // filtering[foo|bar] |
||
| 393 | // $filterAndOperator[0] = 'foo' |
||
| 394 | // $filterAndOperator[1] = 'bar' |
||
| 395 | View Code Duplication | if (isset($filterAndOperator[1])) { |
|
| 396 | if ('list' == $filterAndOperator[1]) { |
||
| 397 | $whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' (:field_'.$fieldName . $salt . ')'; |
||
| 398 | } else if ('field_eq' == $filterAndOperator[1]) { |
||
| 399 | $whereCondition = |
||
| 400 | $this->entityAlias . '.' . $fieldName . ' '. |
||
| 401 | $operator['meta'] . '' . |
||
| 402 | $this->entityAlias . '.' . $value |
||
| 403 | ; |
||
| 404 | //} else { |
||
| 405 | //throw new \RuntimeException( |
||
| 406 | //'Oops! Eccezzione' |
||
| 407 | //); |
||
| 408 | } else { |
||
| 409 | $whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' :field_'.$fieldName . $salt; |
||
| 410 | } |
||
| 411 | } else { |
||
| 412 | $whereCondition = $this->entityAlias.'.'.$fieldName.' = :field_'.$fieldName . $salt; |
||
| 413 | } |
||
| 414 | |||
| 415 | View Code Duplication | if ($orCondition['orCondition'] != null) { |
|
| 416 | $orCondition['orCondition'] .= ' OR ' . $whereCondition; |
||
| 417 | } else { |
||
| 418 | $orCondition['orCondition'] = $whereCondition; |
||
| 419 | } |
||
| 420 | |||
| 421 | View Code Duplication | if (isset($operator['substitution_pattern'])) { |
|
| 422 | if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
||
| 423 | $value = explode(',', $value); |
||
| 424 | } else { |
||
| 425 | $value = str_replace( |
||
| 426 | '{string}', |
||
| 427 | $value, |
||
| 428 | $operator['substitution_pattern'] |
||
| 429 | ); |
||
| 430 | } |
||
| 431 | } |
||
| 432 | |||
| 433 | $orCondition['parameters'][] = [ |
||
| 434 | 'field' => 'field_' . $fieldName . $salt, |
||
| 435 | 'value' => $value |
||
| 436 | ]; |
||
| 437 | } else { |
||
| 438 | $isNotARelation = 0 !== strpos($fieldName, 'Embedded.'); |
||
| 439 | if ($isNotARelation) { |
||
| 440 | $whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' ' . $this->entityAlias . '.' . $value; |
||
| 441 | View Code Duplication | if ($orCondition['orCondition'] != null) { |
|
| 442 | $orCondition['orCondition'] .= ' OR ' . $whereCondition; |
||
| 443 | } else { |
||
| 444 | $orCondition['orCondition'] = $whereCondition; |
||
| 445 | } |
||
| 446 | } |
||
| 447 | } |
||
| 448 | |||
| 449 | // controllo se il filtro si riferisce ad una relazione dell'entità quindi devo fare dei join |
||
| 450 | // esempio per users: filtering[_embedded.groups.name|eq]=admin |
||
| 451 | if (strstr($filter, '_embedded.')) { |
||
| 452 | |||
| 453 | $this->join($filter); |
||
| 454 | $relationEntityAlias = $this->getRelationEntityAlias(); |
||
| 455 | |||
| 456 | $embeddedFields = explode('.', $fieldName); |
||
| 457 | $fieldName = $this->parser->camelize($embeddedFields[count($embeddedFields)-1]); |
||
| 458 | |||
| 459 | $salt = ''; |
||
| 460 | View Code Duplication | foreach ($this->qBuilder->getParameters() as $parameter) { |
|
| 461 | if ($parameter->getName() == 'field_' . $fieldName) { |
||
| 462 | $salt = '_' . rand(111, 999); |
||
| 463 | } |
||
| 464 | } |
||
| 465 | |||
| 466 | View Code Duplication | if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
|
| 467 | $whereCondition = $relationEntityAlias.'.'.$fieldName.' '.$operator['meta'].' (:field_'.$fieldName . $salt . ')'; |
||
| 468 | } else { |
||
| 469 | $whereCondition = $relationEntityAlias.'.'.$fieldName.' '.$operator['meta'].' :field_'.$fieldName . $salt; |
||
| 470 | } |
||
| 471 | |||
| 472 | View Code Duplication | if ($orCondition['orCondition'] != null) { |
|
| 473 | $orCondition['orCondition'] .= ' OR ' . $whereCondition; |
||
| 474 | } else { |
||
| 475 | $orCondition['orCondition'] = $whereCondition; |
||
| 476 | } |
||
| 477 | |||
| 478 | View Code Duplication | if (isset($operator['substitution_pattern'])) { |
|
| 479 | if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
||
| 480 | $value = explode(',', $value); |
||
| 481 | } else { |
||
| 482 | $value = str_replace( |
||
| 483 | '{string}', |
||
| 484 | $value, |
||
| 485 | $operator['substitution_pattern'] |
||
| 486 | ); |
||
| 487 | } |
||
| 488 | } |
||
| 489 | |||
| 490 | $orCondition['parameters'][] = [ |
||
| 491 | 'field' => 'field_' . $fieldName . $salt, |
||
| 492 | 'value' => $value |
||
| 493 | ]; |
||
| 494 | } |
||
| 495 | |||
| 496 | return $orCondition; |
||
| 497 | } |
||
| 498 | |||
| 499 | public function sort() |
||
| 500 | { |
||
| 501 | if (!$this->fields) { |
||
| 502 | throw new \RuntimeException( |
||
| 503 | 'Oops! Fields are not defined' |
||
| 504 | ); |
||
| 505 | } |
||
| 506 | |||
| 507 | if (null === $this->sorting) { |
||
| 508 | throw new \RuntimeException( |
||
| 509 | 'Oops! Sorting is not defined' |
||
| 510 | ); |
||
| 511 | } |
||
| 512 | |||
| 513 | foreach ($this->sorting as $sort => $val) { |
||
| 514 | $val = strtolower($val); |
||
| 515 | |||
| 516 | $fieldName = $this->parser->camelize($sort); |
||
| 517 | |||
| 518 | if (in_array($fieldName, $this->fields)) { |
||
| 519 | $direction = ($val === self::DIRECTION_AZ) ? self::DIRECTION_AZ : self::DIRECTION_ZA; |
||
| 520 | $this->qBuilder->addOrderBy($this->entityAlias .'.'. $fieldName, $direction); |
||
| 521 | } |
||
| 522 | |||
| 523 | if (strstr($sort, '_embedded.')) { |
||
| 524 | $this->join($sort); |
||
| 525 | $relationEntityAlias = $this->getRelationEntityAlias(); |
||
| 526 | |||
| 527 | $embeddedFields = explode('.', $sort); |
||
| 528 | $fieldName = $this->parser->camelize($embeddedFields[2]); |
||
| 529 | $direction = ($val === self::DIRECTION_AZ) ? self::DIRECTION_AZ : self::DIRECTION_ZA; |
||
| 530 | |||
| 531 | $this->qBuilder->addOrderBy($relationEntityAlias.'.'.$fieldName, $direction); |
||
| 532 | } |
||
| 533 | |||
| 534 | } |
||
| 535 | |||
| 536 | return $this; |
||
| 537 | } |
||
| 538 | |||
| 539 | public function getQueryBuilder() |
||
| 540 | { |
||
| 541 | if (!$this->qBuilder) { |
||
| 542 | throw new \RuntimeException( |
||
| 543 | "Oops! Query builder was never initialized! call ::createQueryBuilder('entityName', 'alias') to start." |
||
| 544 | ); |
||
| 545 | } |
||
| 546 | |||
| 547 | return $this->qBuilder; |
||
| 548 | } |
||
| 549 | |||
| 550 | public function buildSelectValue() : string |
||
| 551 | { |
||
| 552 | if ("" == $this->getSelect()) { |
||
| 553 | return $this->getEntityAlias( |
||
| 554 | $this->getEntityName() |
||
| 555 | ); |
||
| 556 | } |
||
| 557 | |||
| 558 | return $this->getSelect(); |
||
| 559 | } |
||
| 560 | |||
| 561 | private function setRelationEntityAlias(string $relationEntityAlias) |
||
| 562 | { |
||
| 563 | $this->relationEntityAlias = $relationEntityAlias; |
||
| 564 | } |
||
| 565 | |||
| 566 | private function getRelationEntityAlias() |
||
| 567 | { |
||
| 568 | return $this->relationEntityAlias; |
||
| 569 | } |
||
| 570 | |||
| 571 | public function setRel($rel) |
||
| 572 | { |
||
| 573 | $this->rel = $rel; |
||
| 574 | |||
| 575 | return $this; |
||
| 576 | } |
||
| 577 | |||
| 578 | public function getRel() |
||
| 579 | { |
||
| 580 | return $this->rel; |
||
| 581 | } |
||
| 582 | |||
| 583 | public function setPrinting($printing) |
||
| 584 | { |
||
| 585 | $this->printing = $printing; |
||
| 586 | |||
| 587 | return $this; |
||
| 588 | } |
||
| 589 | |||
| 590 | public function getPrinting() |
||
| 593 | } |
||
| 594 | |||
| 595 | public function setPage($page) |
||
| 596 | { |
||
| 597 | $this->page = $page; |
||
| 598 | |||
| 599 | return $this; |
||
| 600 | } |
||
| 601 | |||
| 602 | public function getPage() |
||
| 603 | { |
||
| 604 | return $this->page; |
||
| 605 | } |
||
| 606 | |||
| 607 | public function setPageLength($pageLength) |
||
| 608 | { |
||
| 609 | $this->pageLength = $pageLength; |
||
| 610 | |||
| 611 | return $this; |
||
| 612 | } |
||
| 613 | |||
| 614 | public function getPageLength() |
||
| 615 | { |
||
| 616 | return $this->pageLength; |
||
| 617 | } |
||
| 618 | |||
| 619 | public function setSelect(string $select) : QueryBuilderFactory |
||
| 620 | { |
||
| 621 | $this->select = $select; |
||
| 622 | |||
| 623 | return $this; |
||
| 624 | } |
||
| 625 | |||
| 626 | public function getSelect() |
||
| 629 | } |
||
| 630 | |||
| 631 | public function getEntityManager() |
||
| 632 | { |
||
| 633 | return $this->manager; |
||
| 634 | } |
||
| 635 | } |
||
| 636 |
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