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 ( 38922b...26dfd6 )
by Simone
07:17
created

BaseRepository::setRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Mado\QueryBundle\Repositories;
4
5
use Doctrine\ORM\EntityRepository;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityRepository 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
use Hateoas\Configuration\Route;
0 ignored issues
show
Bug introduced by
The type Hateoas\Configuration\Route 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...
7
use Hateoas\Representation\Factory\PagerfantaFactory;
0 ignored issues
show
Bug introduced by
The type Hateoas\Representation\Factory\PagerfantaFactory 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...
8
use Pagerfanta\Adapter\DoctrineORMAdapter;
0 ignored issues
show
Bug introduced by
The type Pagerfanta\Adapter\DoctrineORMAdapter 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...
9
use Pagerfanta\Pagerfanta;
0 ignored issues
show
Bug introduced by
The type Pagerfanta\Pagerfanta 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...
10
use Symfony\Component\HttpFoundation\Request;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Request 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...
11
use Mado\QueryBundle\Queries\QueryBuilderOptions;
12
use Mado\QueryBundle\Queries\QueryBuilderFactory;
13
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...ContainerAwareInterface 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...
14
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...ion\ContainerAwareTrait 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...
15
16
class BaseRepository extends EntityRepository implements ContainerAwareInterface
17
{
18
    use ContainerAwareTrait;
19
20
    protected $fields;
21
22
    protected $request;
23
24
    protected $use_result_cache = false;
25
26
    protected $entityAlias;
27
28
    protected $route_name;
29
30
    protected $currentEntityAlias;
31
32
    protected $embeddedFields;
33
34
    protected $joins = [];
35
36 5
    /**
37
     * @var QueryBuilderFactory
38 5
     */
39
    protected $queryBuilderFactory;
40 5
41
    /**
42 5
     * @var QueryBuilderOptions
43 5
     */
44 5
    protected $queryOptions;
45 5
46
    public function __construct($manager, $class)
47 5
    {
48 5
        parent::__construct($manager, $class);
49
50
        $this->fields = array_keys($this->getClassMetadata()->fieldMappings);
51
52
        $entityName = explode('\\', strtolower($this->getEntityName()) );
53
        $entityName = $entityName[count($entityName)-1];
54
        $entityAlias = $entityName[0];
55
        $this->entityAlias = $entityAlias;
56
57
        $this->queryBuilderFactory = new QueryBuilderFactory($this->getEntityManager());
58
    }
59
60
    public function initFromQueryBuilderOptions(QueryBuilderOptions $options)
61
    {
62
        $this->queryBuilderFactory->createQueryBuilder($this->getEntityName(), $this->entityAlias);
63
64
        $fieldMappings = $this->getClassMetadata()->fieldMappings;
65
        $this->fields = array_keys($fieldMappings);
66
67
        $this->queryBuilderFactory->setFields($this->fields ?? []);
68
        $this->queryBuilderFactory->setFilters($options->getFilters());
69
        $this->queryBuilderFactory->setOrFilters($options->getOrFilters());
70
        $this->queryBuilderFactory->setSorting($options->getSorting());
71
        $this->queryBuilderFactory->setRel($options->getRel());
72
        $this->queryBuilderFactory->setPrinting($options->getPrinting());
73
        $this->queryBuilderFactory->setSelect($options->getSelect());
74
    }
75
76
    public function getQueryBuilderFactory()
77
    {
78 1
        $this->initFromQueryBuilderOptions($this->queryOptions);
79
80 1
        return $this->queryBuilderFactory;
81
    }
82
83
    public function useResultCache($bool)
84
    {
85
        $this->use_result_cache = $bool;
86
    }
87
88
    public function setRequest(Request $request)
89
    {
90
        return $this->setQueryOptionsFromRequest($request);
91
    }
92
93
    public function setRequestWithFilter(Request $request, $filter)
94
    {
95
        return $this->setQueryOptionsFromRequestWithCustomFilter($request, $filter);
96
    }
97
98 3
    public function setRequestWithOrFilter(Request $request, $orFilter)
99
    {
100 3
        return $this->setQueryOptionsFromRequestWithCustomOrFilter($request, $orFilter);
101
    }
102 3
103 3
    public function setQueryOptions(QueryBuilderOptions $options)
104 3
    {
105 3
        $this->queryOptions = $options;
106 3
    }
107 3
108 3
    public function setQueryOptionsFromRequest(Request $request = null)
109 3
    {
110 3
        $requestAttributes = [];
111
        foreach ($request->attributes->all() as $attributeName => $attributeValue) {
112 3
            $requestAttributes[$attributeName] = $request->attributes->get(
113
                $attributeName,
114 3
                $attributeValue
115 3
            );
116
        }
117
118
        $filters     = $request->query->get('filtering', []);
119
        $orFilters   = $request->query->get('filtering_or', []);
120
        $sorting     = $request->query->get('sorting', []);
121
        $printing    = $request->query->get('printing', []);
122
        $rel         = $request->query->get('rel', '');
123
        $page        = $request->query->get('page', '');
124
        $select      = $request->query->get('select', $this->entityAlias);
125
        $pageLength  = $request->query->get('limit', 666);
0 ignored issues
show
Unused Code introduced by
The assignment to $pageLength is dead and can be removed.
Loading history...
126
        $filtering   = $request->query->get('filtering', '');
127 3
        $limit       = $request->query->get('limit', '');
128 3
129 3
        $filterOrCorrected = [];
130 3
131 3
        $count = 0;
132 3
        foreach ($orFilters as $key => $filter) {
133 3
            if (is_array($filter)) {
134 3
                foreach ($filter as $keyInternal => $internal) {
135 3
                    $filterOrCorrected[$keyInternal .'|' . $count] = $internal;
136 3
                    $count = $count + 1;
137
                }
138
            } else {
139 3
                $filterOrCorrected[$key] = $filter;
140 3
            }
141 3
        }
142
143
        $requestProperties = [
144 3
            'filtering'   => $filtering,
145
            'orFiltering' => $filterOrCorrected,
146 3
            'limit'       => $limit,
147
            'page'        => $page,
148
            'filters'     => $filters,
149 4
            'orFilters'   => $filterOrCorrected,
150
            'sorting'     => $sorting,
151 4
            'rel'         => $rel,
152
            'printing'    => $printing,
153 4
            'select'      => $select,
154
        ];
155
156
        $options = array_merge(
157
            $requestAttributes,
158
            $requestProperties
159
        );
160 4
161
        $this->queryOptions = QueryBuilderOptions::fromArray($options);
162
163
        return $this;
164
    }
165
166 View Code Duplication
    public function setQueryOptionsFromRequestWithCustomFilter(Request $request = null, $filter)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
167
    {
168
        $filters = $request->query->get('filtering', []);
169
        $orFilters = $request->query->get('filtering_or', []);
170
        $sorting = $request->query->get('sorting', []);
171
        $printing = $request->query->get('printing', []);
172
        $rel = $request->query->get('rel', '');
173
        $page = $request->query->get('page', '');
174
        $select = $request->query->get('select', $this->entityAlias);
175
        $pageLength = $request->query->get('limit', 666);
0 ignored issues
show
Unused Code introduced by
The assignment to $pageLength is dead and can be removed.
Loading history...
176
        $filtering = $request->query->get('filtering', '');
177
        $limit = $request->query->get('limit', '');
178
179
        $filters = array_merge($filters, $filter);
180
181
        $filterOrCorrected = [];
182
183
        $count = 0;
184
        foreach ($orFilters as $key => $filter) {
185
            if (is_array($filter)) {
186
                foreach ($filter as $keyInternal => $internal) {
187
                    $filterOrCorrected[$keyInternal .'|' . $count] = $internal;
188
                    $count = $count + 1;
189
                }
190
            } else {
191
                $filterOrCorrected[$key] = $filter;
192
            }
193
        }
194
195
        $this->queryOptions = QueryBuilderOptions::fromArray([
196
            '_route' => $request->attributes->get('_route'),
197
            'customer_id' => $request->attributes->get('customer_id'),
198
            'id' => $request->attributes->get('id'),
199
            'filtering' => $filtering,
200
            'limit' => $limit,
201
            'page' => $page,
202
            'filters' => $filters,
203
            'orFilters' => $filterOrCorrected,
204
            'sorting' => $sorting,
205
            'rel' => $rel,
206
            'printing' => $printing,
207
            'select' => $select,
208
        ]);
209
210
        return $this;
211
    }
212
213 View Code Duplication
    public function setQueryOptionsFromRequestWithCustomOrFilter(Request $request = null, $orFilter)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
214
    {
215
        $filters = $request->query->get('filtering', []);
216
        $orFilters = $request->query->get('filtering_or', []);
217
        $sorting = $request->query->get('sorting', []);
218 1
        $printing = $request->query->get('printing', []);
219
        $rel = $request->query->get('rel', '');
220 1
        $page = $request->query->get('page', '');
221
        $select = $request->query->get('select', $this->entityAlias);
222 1
        $pageLength = $request->query->get('limit', 666);
0 ignored issues
show
Unused Code introduced by
The assignment to $pageLength is dead and can be removed.
Loading history...
223 1
        $filtering = $request->query->get('filtering', '');
224 1
        $limit = $request->query->get('limit', '');
225 1
226 1
        $orFilters = array_merge($orFilters, $orFilter);
227 1
228 1
        $filterOrCorrected = [];
229 1
230 1
        $count = 0;
231
        foreach ($orFilters as $key => $filter) {
232 1
            if (is_array($filter)) {
233
                foreach ($filter as $keyInternal => $internal) {
234 1
                    $filterOrCorrected[$keyInternal .'|' . $count] = $internal;
235
                    $count = $count + 1;
236 1
                }
237 1
            } else {
238
                $filterOrCorrected[$key] = $filter;
239
            }
240
        }
241
242
        $this->queryOptions = QueryBuilderOptions::fromArray([
243
            '_route' => $request->attributes->get('_route'),
244
            'customer_id' => $request->attributes->get('customer_id'),
245
            'id' => $request->attributes->get('id'),
246
            'filtering' => $filtering,
247
            'limit' => $limit,
248
            'page' => $page,
249 1
            'filters' => $filters,
250 1
            'orFilters' => $filterOrCorrected,
251 1
            'sorting' => $sorting,
252 1
            'rel' => $rel,
253 1
            'printing' => $printing,
254 1
            'select' => $select,
255 1
        ]);
256 1
257 1
        return $this;
258 1
    }
259 1
260 1
    public function getRequest()
261
    {
262
        return $this->request;
263 1
    }
264 1
265 1
    public function setRouteName($route_name = '')
266
    {
267
        $this->route_name = $route_name;
268 1
        return $this;
269
    }
270 1
271
    public function findAllPaginated()
272
    {
273 4
        $this->initFromQueryBuilderOptions($this->queryOptions);
274
275 4
        $this->queryBuilderFactory->filter();
276
        $this->queryBuilderFactory->sort();
277
278
        return $this->paginateResults($this->queryBuilderFactory->getQueryBuilder());
279
    }
280
281
    protected function paginateResults(
282
        \Doctrine\ORM\QueryBuilder $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...
283
    ) {
284
        $limit = $this->queryOptions->get('limit', 10);
285
        $page = $this->queryOptions->get('page', 1);
286
287
288
        $pagerAdapter = new DoctrineORMAdapter($queryBuilder);
289
290
        $query = $pagerAdapter->getQuery();
291
        if(isset($this->use_result_cache) and $this->use_result_cache){
292
            $query->useResultCache(true, 600);
293
        }
294
295
        $pager = new Pagerfanta($pagerAdapter);
296
        $pager->setNormalizeOutOfRangePages(true);
297
        $pager->setMaxPerPage($limit);
298
        $pager->setCurrentPage($page);
299
300
        $pagerFactory = new PagerfantaFactory();
301
302
        $router = $this->createRouter();
303
304
        $results = $pagerFactory->createRepresentation($pager, $router);
305
306
        return $results;
307
    }
308
309
    protected function customQueryStringValues()
310
    {
311
        return [];
312
    }
313
314
    protected function createRouter()
315
    {
316
        $request = $this->getRequest();
0 ignored issues
show
Unused Code introduced by
The assignment to $request is dead and can be removed.
Loading history...
317
        $params = [];
318
319
        $list = array_merge([
320
            'filtering',
321
            'limit',
322
            'page',
323
            'sorting',
324
        ], $this->customQueryStringValues());
325
326
        foreach ($list as $itemKey => $itemValue) {
327
            $params[$itemValue] = $this->queryOptions->get($itemValue);
328
        }
329
330
        if(!isset($this->route_name)){
331
            $this->route_name = $this->queryOptions->get('_route');
332
        }
333
334
        return new Route($this->route_name, $params);
335
    }
336
337
    /** @deprecate use QueryBuilderFatory instead */
338
    public function noExistsJoin($prevEntityAlias, $currentEntityAlias)
339
    {
340
        $needle = $prevEntityAlias . "_" . $currentEntityAlias;
341
        return ! in_array($needle, $this->joins);
342
    }
343
344
    /** @deprecate use QueryBuilderFatory instead */
345
    public function storeJoin($prevEntityAlias, $currentEntityAlias)
346
    {
347
        $needle = $prevEntityAlias . "_" . $currentEntityAlias;
348
        $this->joins[$needle] = $needle;
349
    }
350
351
    /** @deprecate use QueryBuilderFatory instead */
352
    public function join($queryBuilder, $key, $val) 
353
    {
354
        if (strstr($key, '_embedded.')) {
355
            $embeddedFields = explode('.', $key);
356
            $numFields = count($embeddedFields);
357
358
            $prevEntityAlias = $this->entityAlias; // Stocksellouts
359
            $prevEntityName = $this->getEntityName(); // Stocksellouts
360
361
            for ($i = 1; $i < $numFields - 1; $i++) {
362
                $metadata = $this->getEntityManager()->getClassMetadata($prevEntityName);
363
364
                $currentRelation = $embeddedFields[$i];
365
366
                if ($metadata->hasAssociation($currentRelation)) {
367
368
                    $association = $metadata->getAssociationMapping($currentRelation);
369
370
                    $currentEntityAlias = $this->getEntityAlias($association['targetEntity']);
371
372
                    if ($this->noExistsJoin($prevEntityAlias, $currentRelation)) {
373
                        if ($association['isOwningSide']) {
374
                            $queryBuilder->join($association['targetEntity'], "$currentEntityAlias", "WITH", "$currentEntityAlias.id = " . "$prevEntityAlias.$currentRelation");
375
                        } else {
376
                            $mappedBy = $association['mappedBy'];
377
                            $queryBuilder->join($association['targetEntity'], "$currentEntityAlias", "WITH", "$currentEntityAlias.$mappedBy = " . "$prevEntityAlias.id");
378
                        }
379
380
                        $this->storeJoin($prevEntityAlias, $currentRelation);
381
                    }
382
                }
383
384
                $prevEntityAlias = $currentEntityAlias;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $currentEntityAlias does not seem to be defined for all execution paths leading up to this point.
Loading history...
385
                $prevEntityName = $association['targetEntity'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $association does not seem to be defined for all execution paths leading up to this point.
Loading history...
386
            }
387
388
            $this->setEmbeddedFields($embeddedFields);
389
            $this->setCurrentEntityAlias($currentEntityAlias);
390
        }
391
392
        return $queryBuilder;
393
    }
394
395
    protected function getCurrentEntityAlias() : string
396
    {
397
        return $this->currentEntityAlias;
398
    }
399
400
    protected function setCurrentEntityAlias(string $currentEntityAlias) 
401
    {
402
        $this->currentEntityAlias = $currentEntityAlias;
403
    }
404
405
    protected function getEmbeddedFields() : array
406
    {
407
        return $this->embeddedFields;
408
    }
409
410
    protected function setEmbeddedFields(array $embeddedFields) 
411
    {
412
        $this->embeddedFields = $embeddedFields;
413
    }    
414
415
    /** @deprecate use QueryBuilderFatory component instead */
416
    //protected function sort($queryBuilder)
417
    //{
418
        //$request = $this->getRequest();
419
        //$sorting = $request->query->get('sorting', array());
420
421
        //foreach ($this->fields as $field) {
422
            //if (isset($sorting[$field])) {
423
                //$direction = ($sorting[$field] === 'asc') ? 'asc' : 'desc';
424
                //$queryBuilder->addOrderBy($this->entityAlias.'.'.$field, $direction);
425
            //}
426
        //}
427
428
        //// &sorting[_embedded.{{relazione}}.{{campo}}={{val}}
429
        //foreach ($sorting as $sort => $val) {
430
            //if (strstr($sort, '_embedded.')) {
431
432 1
                //$queryBuilder = $this->join($queryBuilder, $sort, $val);
433
434 1
                //$currentEntityAlias = $this->getCurrentEntityAlias();
435 1
                //$embeddedFields = $this->getEmbeddedFields();
436 1
                //$numFields = count($embeddedFields);
437
438
                //$fieldName = $embeddedFields[$numFields - 1];
439
                //$direction = ($val === 'asc') ? 'asc' : 'desc';
440
                //$queryBuilder->addOrderBy("$currentEntityAlias." . $fieldName, $direction);
441
            //}
442
        //}
443
444
        //return $queryBuilder;
445
    //}
446
447
    public function getEntityAlias(string $entityName) : string
448
    {
449
        $arrayEntityName = explode('\\', strtolower($entityName) );
450
        $entityAlias = $arrayEntityName[count($arrayEntityName)-1];
451
        return $entityAlias;
452
    }
453
454
    /** @deprecate use QueryBuilderFatory component instead */
455
    //protected function filter($queryBuilder)
456
    //{
457
        //$request = $this->getRequest();
458
        //$filtering = $request->query->get('filtering', array());
459
460
        //foreach ($this->fields as $field) {
461
            //if (isset($filtering[$field])) {
462
                //switch ($field) {
463
                //case 'id':
464
                //case 'year':
465
                //case 'week':                        
466
                    //$queryBuilder->andWhere($this->entityAlias.'.'.$field.' = :filter_'.$field)
467
                        //->setParameter('filter_'.$field, $filtering[$field]);                        
468
                    //break;
469
                //default:
470
                    //$queryBuilder->andWhere($this->entityAlias.'.'.$field.' LIKE :filter_'.$field)
471
                        //->setParameter('filter_'.$field, '%'.$filtering[$field].'%');
472
                //}
473
            //}
474
        //}
475
476
        //// &filtering[_embedded.{{relazione}}.{{campo}}]={{val}}
477
        //foreach ($filtering as $filter => $val) {
478
            //if (strstr($filter, '_embedded.')) {
479
480
                //$queryBuilder = $this->join($queryBuilder, $filter, $val);
481
482
                //$currentEntityAlias = $this->getCurrentEntityAlias();
483
                //$embeddedFields = $this->getEmbeddedFields();
484
                //$numFields = count($embeddedFields);
485
                //$fieldName = $embeddedFields[$numFields - 1];
486
487
                //$paramName = str_replace(".", "_", $filter);
488
489
                //switch ($fieldName) {
490
                //case 'id':
491
                //case 'codiceClienteFornitore':
492
                //case 'codiceFamily':
493
                //case 'year':
494
                //case 'week':
495
                    //$queryBuilder->andWhere("$currentEntityAlias." . $fieldName . ' = :filter_' . $paramName)
496
                        //->setParameter('filter_' . $paramName, $val);
497
                    //break;
498
                //default :
499
                    //$queryBuilder->andWhere("$currentEntityAlias." . $fieldName . ' LIKE :filter_' . $paramName)
500
                        //->setParameter('filter_' . $paramName, '%' . $val . '%');                        
501
                //}
502
            //}
503
        //}
504
505
        //return $queryBuilder;
506
    //}
507
508
    protected function relationship($queryBuilder)
509
    {
510
        return $queryBuilder;
511
    }
512
513
    /**
514
     *
515
     * @param type $insertFields
0 ignored issues
show
Bug introduced by
The type Mado\QueryBundle\Repositories\type 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...
516
     * @param type $updateFields
517
     *
518
     * USE:
519
     *
520
     * $this->getEntityManager()
521
     *      ->getRepository('User')
522
     *      ->onDuplicateUpdate(['column1' => 'user_reminder_1', 'column2' => 235], ['column2' => 255]);
523
     */
524
    public function onDuplicateUpdate($insertFields, $updateFields)
525
    {
526
        //---CHIAVI
527
        $array_keys = array_keys($insertFields);
0 ignored issues
show
Bug introduced by
$insertFields of type Mado\QueryBundle\Repositories\type is incompatible with the type array expected by parameter $input of array_keys(). ( Ignorable by Annotation )

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

527
        $array_keys = array_keys(/** @scrutinizer ignore-type */ $insertFields);
Loading history...
528
        $list_keys = '`' . implode('`,`', $array_keys) . '`';
529
530
        //---VALORI
531
        $list_values = "'" . implode("', '", $insertFields) . "'";
0 ignored issues
show
Bug introduced by
$insertFields of type Mado\QueryBundle\Repositories\type is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

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

531
        $list_values = "'" . implode("', '", /** @scrutinizer ignore-type */ $insertFields) . "'";
Loading history...
532
533
        $table = $this->getEntityManager()->getClassMetadata($this->getEntityName())->getTableName();
534
535
        $sql = 'INSERT INTO '.$table;
536
        $sql .= '('. $list_keys . ') ';
537
        //$sql .= 'VALUES("'.implode('","', $insertFields).'") ';
538
        $sql .= "VALUES(". $list_values.") ";
539
        $sql .= 'ON DUPLICATE KEY UPDATE ';
540
541
        $c = 0;
542
        foreach($updateFields as $column => $value) {
543
            if($c>0)$sql .= ", ";
544
            $sql .= '`'.$column . "` = '". $value."'";
545
            $c++;
546
        }
547
548
        $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
549
        $stmt->execute();
550
    }
551
552
    public function getQueryBuilderFactoryWithoutInitialization()
553
    {
554
        return $this->queryBuilderFactory;
555
    }
556
}
557