GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( fb7788...85cabe )
by Alessandro
06:03
created

QueryBuilderFactory::buildSelectValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 4
cp 0
crap 6
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Mado\QueryBundle\Queries;
4
5
use Doctrine\ORM\QueryBuilder;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\QueryBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
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);
0 ignored issues
show
Bug introduced by
Since $operatorMap is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $operatorMap to at least protected.
Loading history...
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 = [])
117
    {
118
        $this->filtering = $filtering;
119
120
        return $this;
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]);
0 ignored issues
show
Unused Code introduced by
The assignment to $relation is dead and can be removed.
Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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]) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
353
                if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) {
354
                    $value = explode(',', $value);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type array; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

354
                    $value = explode(',', /** @scrutinizer ignore-type */ $value);
Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
416
                $orCondition['orCondition'] .= ' OR ' . $whereCondition;
417
            } else {
418
                $orCondition['orCondition'] = $whereCondition;
419
            }
420
421 View Code Duplication
            if (isset($operator['substitution_pattern'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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]) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
473
                $orCondition['orCondition'] .= ' OR ' . $whereCondition;
474
            } else {
475
                $orCondition['orCondition'] = $whereCondition;
476
            }
477
478 View Code Duplication
            if (isset($operator['substitution_pattern'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
479
                if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) {
480
                    $value = explode(',', $value);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type array; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

480
                    $value = explode(',', /** @scrutinizer ignore-type */ $value);
Loading history...
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(
0 ignored issues
show
Bug introduced by
The method getEntityAlias() does not exist on Mado\QueryBundle\Queries\QueryBuilderFactory. Did you maybe mean getEntityName()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

553
            return $this->/** @scrutinizer ignore-call */ getEntityAlias(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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()
591
    {
592
        return $this->printing;
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()
627
    {
628
        return $this->select;
629
    }
630
631
    public function getEntityManager()
632
    {
633
        return $this->manager;
634
    }
635
}
636