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
Pull Request — master (#61)
by Simone
10:22
created

BaseRepository::paginateResults()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 2
nop 1
dl 0
loc 28
ccs 0
cts 15
cp 0
crap 12
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Mado\QueryBundle\Repositories;
4
5
use Doctrine\ORM\EntityRepository;
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 Mado\QueryBundle\Queries\QueryBuilderFactory;
9
use Mado\QueryBundle\Queries\QueryBuilderOptions;
10
use Mado\QueryBundle\Component\ConfigProvider;
11
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...
12
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...
13
use Symfony\Component\HttpFoundation\Request;
14
15
class BaseRepository extends EntityRepository
16
{
17
    protected $fields;
18
19
    protected $request;
20
21
    protected $use_result_cache = false;
22
23
    protected $entityAlias;
24
25
    protected $route_name;
26
27
    protected $currentEntityAlias;
28
29
    protected $embeddedFields;
30
31
    protected $joins = [];
32
33
    protected $queryBuilderFactory;
34
35
    protected $queryOptions;
36 5
37
    protected $configProvider;
38 5
39
    public function __construct($manager, $class)
40 5
    {
41
        parent::__construct($manager, $class);
42 5
43 5
        $this->fields = array_keys($this->getClassMetadata()->fieldMappings);
44 5
45 5
        $entityName = explode('\\', strtolower($this->getEntityName()) );
46
        $entityName = $entityName[count($entityName)-1];
47 5
        $entityAlias = $entityName[0];
48 5
        $this->entityAlias = $entityAlias;
49
50
        $this->queryBuilderFactory = new QueryBuilderFactory($this->getEntityManager());
51
    }
52
53
    public function initFromQueryBuilderOptions(QueryBuilderOptions $options)
54
    {
55
        $this->queryBuilderFactory->createQueryBuilder($this->getEntityName(), $this->entityAlias);
56
57
        $fieldMappings = $this->getClassMetadata()->fieldMappings;
58
        $this->fields = array_keys($fieldMappings);
59
60
        $this->queryBuilderFactory->setFields($this->fields ?? []);
61
        $this->queryBuilderFactory->setFilters($options->getFilters());
62
        $this->queryBuilderFactory->setOrFilters($options->getOrFilters());
63
        $this->queryBuilderFactory->setSorting($options->getSorting());
64
        $this->queryBuilderFactory->setRel($options->getRel());
65
        $this->queryBuilderFactory->setPrinting($options->getPrinting());
66
        $this->queryBuilderFactory->setSelect($options->getSelect());
67
    }
68
69
    public function getQueryBuilderFactory()
70
    {
71
        $this->ensureQueryOptionIsDefined();
72
73
        $this->initFromQueryBuilderOptions($this->queryOptions);
74
75
        return $this->queryBuilderFactory;
76
    }
77
78 1
    public function useResultCache($bool)
79
    {
80 1
        $this->use_result_cache = $bool;
81
    }
82
83
    public function setRequest(Request $request)
84
    {
85
        return $this->setQueryOptionsFromRequest($request);
86
    }
87
88
    public function setRequestWithFilter(Request $request, $filter)
89
    {
90
        return $this->setQueryOptionsFromRequestWithCustomFilter($request, $filter);
91
    }
92
93
    public function setRequestWithOrFilter(Request $request, $orFilter)
94
    {
95
        return $this->setQueryOptionsFromRequestWithCustomOrFilter($request, $orFilter);
96
    }
97
98 3
    public function setQueryOptions(QueryBuilderOptions $options)
99
    {
100 3
        $this->queryOptions = $options;
101
    }
102 3
103 3
    public function setQueryOptionsFromRequest(Request $request = null)
104 3
    {
105 3
        $requestAttributes = [];
106 3
        foreach ($request->attributes->all() as $attributeName => $attributeValue) {
107 3
            $requestAttributes[$attributeName] = $request->attributes->get(
108 3
                $attributeName,
109 3
                $attributeValue
110 3
            );
111
        }
112 3
113
        $filters     = $request->query->get('filtering', []);
114 3
        $orFilters   = $request->query->get('filtering_or', []);
115 3
        $sorting     = $request->query->get('sorting', []);
116
        $printing    = $request->query->get('printing', []);
117
        $rel         = $request->query->get('rel', '');
118
        $page        = $request->query->get('page', '');
119
        $select      = $request->query->get('select', $this->entityAlias);
120
        $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...
121
        $filtering   = $request->query->get('filtering', '');
122
        $limit       = $request->query->get('limit', '');
123
124
        $filterOrCorrected = [];
125
126
        $count = 0;
127 3
        foreach ($orFilters as $key => $filter) {
128 3
            if (is_array($filter)) {
129 3
                foreach ($filter as $keyInternal => $internal) {
130 3
                    $filterOrCorrected[$keyInternal .'|' . $count] = $internal;
131 3
                    $count = $count + 1;
132 3
                }
133 3
            } else {
134 3
                $filterOrCorrected[$key] = $filter;
135 3
            }
136 3
        }
137
138
        $requestProperties = [
139 3
            'filtering'   => $filtering,
140 3
            'orFiltering' => $filterOrCorrected,
141 3
            'limit'       => $limit,
142
            'page'        => $page,
143
            'filters'     => $filters,
144 3
            'orFilters'   => $filterOrCorrected,
145
            'sorting'     => $sorting,
146 3
            'rel'         => $rel,
147
            'printing'    => $printing,
148
            'select'      => $select,
149 4
        ];
150
151 4
        $options = array_merge(
152
            $requestAttributes,
153 4
            $requestProperties
154
        );
155
156
        $this->queryOptions = QueryBuilderOptions::fromArray($options);
157
158
        return $this;
159
    }
160 4
161 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...
162
    {
163
        $filters = $request->query->get('filtering', []);
164
        $orFilters = $request->query->get('filtering_or', []);
165
        $sorting = $request->query->get('sorting', []);
166
        $printing = $request->query->get('printing', []);
167
        $rel = $request->query->get('rel', '');
168
        $page = $request->query->get('page', '');
169
        $select = $request->query->get('select', $this->entityAlias);
170
        $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...
171
        $filtering = $request->query->get('filtering', '');
172
        $limit = $request->query->get('limit', '');
173
174
        $filters = array_merge($filters, $filter);
175
176
        $filterOrCorrected = [];
177
178
        $count = 0;
179
        foreach ($orFilters as $key => $filter) {
180
            if (is_array($filter)) {
181
                foreach ($filter as $keyInternal => $internal) {
182
                    $filterOrCorrected[$keyInternal .'|' . $count] = $internal;
183
                    $count = $count + 1;
184
                }
185
            } else {
186
                $filterOrCorrected[$key] = $filter;
187
            }
188
        }
189
190
        $this->queryOptions = QueryBuilderOptions::fromArray([
191
            '_route' => $request->attributes->get('_route'),
192
            'customer_id' => $request->attributes->get('customer_id'),
193
            'id' => $request->attributes->get('id'),
194
            'filtering' => $filtering,
195
            'limit' => $limit,
196
            'page' => $page,
197
            'filters' => $filters,
198
            'orFilters' => $filterOrCorrected,
199
            'sorting' => $sorting,
200
            'rel' => $rel,
201
            'printing' => $printing,
202
            'select' => $select,
203
        ]);
204
205
        return $this;
206
    }
207
208 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...
209
    {
210
        $filters = $request->query->get('filtering', []);
211
        $orFilters = $request->query->get('filtering_or', []);
212
        $sorting = $request->query->get('sorting', []);
213
        $printing = $request->query->get('printing', []);
214
        $rel = $request->query->get('rel', '');
215
        $page = $request->query->get('page', '');
216
        $select = $request->query->get('select', $this->entityAlias);
217
        $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...
218 1
        $filtering = $request->query->get('filtering', '');
219
        $limit = $request->query->get('limit', '');
220 1
221
        $orFilters = array_merge($orFilters, $orFilter);
222 1
223 1
        $filterOrCorrected = [];
224 1
225 1
        $count = 0;
226 1
        foreach ($orFilters as $key => $filter) {
227 1
            if (is_array($filter)) {
228 1
                foreach ($filter as $keyInternal => $internal) {
229 1
                    $filterOrCorrected[$keyInternal .'|' . $count] = $internal;
230 1
                    $count = $count + 1;
231
                }
232 1
            } else {
233
                $filterOrCorrected[$key] = $filter;
234 1
            }
235
        }
236 1
237 1
        $this->queryOptions = QueryBuilderOptions::fromArray([
238
            '_route' => $request->attributes->get('_route'),
239
            'customer_id' => $request->attributes->get('customer_id'),
240
            'id' => $request->attributes->get('id'),
241
            'filtering' => $filtering,
242
            'limit' => $limit,
243
            'page' => $page,
244
            'filters' => $filters,
245
            'orFilters' => $filterOrCorrected,
246
            'sorting' => $sorting,
247
            'rel' => $rel,
248
            'printing' => $printing,
249 1
            'select' => $select,
250 1
        ]);
251 1
252 1
        return $this;
253 1
    }
254 1
255 1
    public function getRequest()
256 1
    {
257 1
        return $this->request;
258 1
    }
259 1
260 1
    public function setRouteName($route_name = '')
261
    {
262
        $this->route_name = $route_name;
263 1
        return $this;
264 1
    }
265 1
266
    public function findAllPaginated()
267
    {
268 1
        if ($this->configProvider) {
269
            $this->setRequest($this->configProvider->getRequest());
270 1
            $this->queryBuilderFactory->setConfigProvider($this->configProvider);
271
        }
272
273 4
        $this->ensureQueryOptionIsDefined();
274
275 4
        $this->initFromQueryBuilderOptions($this->queryOptions);
276
277
        $this->queryBuilderFactory->filter();
278
        $this->queryBuilderFactory->sort();
279
280
        return $this->paginateResults($this->queryBuilderFactory->getQueryBuilder());
281
    }
282
283
    protected function paginateResults(
284
        \Doctrine\ORM\QueryBuilder $queryBuilder
285
    ) {
286
        $this->ensureQueryOptionIsDefined();
287
288
        $limit = $this->queryOptions->get('limit', 10);
289
        $page = $this->queryOptions->get('page', 1);
290
291
292
        $pagerAdapter = new DoctrineORMAdapter($queryBuilder);
293
294
        $query = $pagerAdapter->getQuery();
295
        if(isset($this->use_result_cache) and $this->use_result_cache){
296
            $query->useResultCache(true, 600);
297
        }
298
299
        $pager = new Pagerfanta($pagerAdapter);
300
        $pager->setNormalizeOutOfRangePages(true);
301
        $pager->setMaxPerPage($limit);
302
        $pager->setCurrentPage($page);
303
304
        $pagerFactory = new PagerfantaFactory();
305
306
        $router = $this->createRouter();
307
308
        $results = $pagerFactory->createRepresentation($pager, $router);
309
310
        return $results;
311
    }
312
313
    protected function customQueryStringValues()
314
    {
315
        return [];
316
    }
317
318
    protected function createRouter()
319
    {
320
        $request = $this->getRequest();
0 ignored issues
show
Unused Code introduced by
The assignment to $request is dead and can be removed.
Loading history...
321
        $params = [];
322
323
        $list = array_merge([
324
            'filtering',
325
            'limit',
326
            'page',
327
            'sorting',
328
        ], $this->customQueryStringValues());
329
330
        $this->ensureQueryOptionIsDefined();
331
332
        foreach ($list as $itemKey => $itemValue) {
333
            $params[$itemValue] = $this->queryOptions->get($itemValue);
334
        }
335
336
        if(!isset($this->route_name)){
337
            $this->route_name = $this->queryOptions->get('_route');
338
        }
339
340
        return new Route($this->route_name, $params);
341
    }
342
343
    /** @deprecate use QueryBuilderFatory instead */
344
    public function noExistsJoin($prevEntityAlias, $currentEntityAlias)
345
    {
346
        $needle = $prevEntityAlias . "_" . $currentEntityAlias;
347
        return ! in_array($needle, $this->joins);
348
    }
349
350
    /** @deprecate use QueryBuilderFatory instead */
351
    public function storeJoin($prevEntityAlias, $currentEntityAlias)
352
    {
353
        $needle = $prevEntityAlias . "_" . $currentEntityAlias;
354
        $this->joins[$needle] = $needle;
355
    }
356
357
    /** @deprecate use QueryBuilderFatory instead */
358
    public function join($queryBuilder, $key, $val) 
0 ignored issues
show
Unused Code introduced by
The parameter $val is not used and could be removed. ( Ignorable by Annotation )

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

358
    public function join($queryBuilder, $key, /** @scrutinizer ignore-unused */ $val) 

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
359
    {
360
        if (strstr($key, '_embedded.')) {
361
            $embeddedFields = explode('.', $key);
362
            $numFields = count($embeddedFields);
363
364
            $prevEntityAlias = $this->entityAlias; // Stocksellouts
365
            $prevEntityName = $this->getEntityName(); // Stocksellouts
366
367
            for ($i = 1; $i < $numFields - 1; $i++) {
368
                $metadata = $this->getEntityManager()->getClassMetadata($prevEntityName);
369
370
                $currentRelation = $embeddedFields[$i];
371
372
                if ($metadata->hasAssociation($currentRelation)) {
373
374
                    $association = $metadata->getAssociationMapping($currentRelation);
375
376
                    $currentEntityAlias = $this->getEntityAlias($association['targetEntity']);
377
378
                    if ($this->noExistsJoin($prevEntityAlias, $currentRelation)) {
379
                        if ($association['isOwningSide']) {
380
                            $queryBuilder->join($association['targetEntity'], "$currentEntityAlias", "WITH", "$currentEntityAlias.id = " . "$prevEntityAlias.$currentRelation");
381
                        } else {
382
                            $mappedBy = $association['mappedBy'];
383
                            $queryBuilder->join($association['targetEntity'], "$currentEntityAlias", "WITH", "$currentEntityAlias.$mappedBy = " . "$prevEntityAlias.id");
384
                        }
385
386
                        $this->storeJoin($prevEntityAlias, $currentRelation);
387
                    }
388
                }
389
390
                $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...
391
                $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...
392
            }
393
394
            $this->setEmbeddedFields($embeddedFields);
395
            $this->setCurrentEntityAlias($currentEntityAlias);
396
        }
397
398
        return $queryBuilder;
399
    }
400
401
    protected function getCurrentEntityAlias() : string
402
    {
403
        return $this->currentEntityAlias;
404
    }
405
406
    protected function setCurrentEntityAlias(string $currentEntityAlias) 
407
    {
408
        $this->currentEntityAlias = $currentEntityAlias;
409
    }
410
411
    protected function getEmbeddedFields() : array
412
    {
413
        return $this->embeddedFields;
414
    }
415
416
    protected function setEmbeddedFields(array $embeddedFields) 
417
    {
418
        $this->embeddedFields = $embeddedFields;
419
    }    
420
421
    /** @deprecate use QueryBuilderFatory component instead */
422
    //protected function sort($queryBuilder)
423
    //{
424
        //$request = $this->getRequest();
425
        //$sorting = $request->query->get('sorting', array());
426
427
        //foreach ($this->fields as $field) {
428
            //if (isset($sorting[$field])) {
429
                //$direction = ($sorting[$field] === 'asc') ? 'asc' : 'desc';
430
                //$queryBuilder->addOrderBy($this->entityAlias.'.'.$field, $direction);
431
            //}
432 1
        //}
433
434 1
        //// &sorting[_embedded.{{relazione}}.{{campo}}={{val}}
435 1
        //foreach ($sorting as $sort => $val) {
436 1
            //if (strstr($sort, '_embedded.')) {
437
438
                //$queryBuilder = $this->join($queryBuilder, $sort, $val);
439
440
                //$currentEntityAlias = $this->getCurrentEntityAlias();
441
                //$embeddedFields = $this->getEmbeddedFields();
442
                //$numFields = count($embeddedFields);
443
444
                //$fieldName = $embeddedFields[$numFields - 1];
445
                //$direction = ($val === 'asc') ? 'asc' : 'desc';
446
                //$queryBuilder->addOrderBy("$currentEntityAlias." . $fieldName, $direction);
447
            //}
448
        //}
449
450
        //return $queryBuilder;
451
    //}
452
453
    public function getEntityAlias(string $entityName) : string
454
    {
455
        $arrayEntityName = explode('\\', strtolower($entityName) );
456
        $entityAlias = $arrayEntityName[count($arrayEntityName)-1];
457
        return $entityAlias;
458
    }
459
460
    /** @deprecate use QueryBuilderFatory component instead */
461
    //protected function filter($queryBuilder)
462
    //{
463
        //$request = $this->getRequest();
464
        //$filtering = $request->query->get('filtering', array());
465
466
        //foreach ($this->fields as $field) {
467
            //if (isset($filtering[$field])) {
468
                //switch ($field) {
469
                //case 'id':
470
                //case 'year':
471
                //case 'week':                        
472
                    //$queryBuilder->andWhere($this->entityAlias.'.'.$field.' = :filter_'.$field)
473
                        //->setParameter('filter_'.$field, $filtering[$field]);                        
474
                    //break;
475
                //default:
476
                    //$queryBuilder->andWhere($this->entityAlias.'.'.$field.' LIKE :filter_'.$field)
477
                        //->setParameter('filter_'.$field, '%'.$filtering[$field].'%');
478
                //}
479
            //}
480
        //}
481
482
        //// &filtering[_embedded.{{relazione}}.{{campo}}]={{val}}
483
        //foreach ($filtering as $filter => $val) {
484
            //if (strstr($filter, '_embedded.')) {
485
486
                //$queryBuilder = $this->join($queryBuilder, $filter, $val);
487
488
                //$currentEntityAlias = $this->getCurrentEntityAlias();
489
                //$embeddedFields = $this->getEmbeddedFields();
490
                //$numFields = count($embeddedFields);
491
                //$fieldName = $embeddedFields[$numFields - 1];
492
493
                //$paramName = str_replace(".", "_", $filter);
494
495
                //switch ($fieldName) {
496
                //case 'id':
497
                //case 'codiceClienteFornitore':
498
                //case 'codiceFamily':
499
                //case 'year':
500
                //case 'week':
501
                    //$queryBuilder->andWhere("$currentEntityAlias." . $fieldName . ' = :filter_' . $paramName)
502
                        //->setParameter('filter_' . $paramName, $val);
503
                    //break;
504
                //default :
505
                    //$queryBuilder->andWhere("$currentEntityAlias." . $fieldName . ' LIKE :filter_' . $paramName)
506
                        //->setParameter('filter_' . $paramName, '%' . $val . '%');                        
507
                //}
508
            //}
509
        //}
510
511
        //return $queryBuilder;
512
    //}
513
514
    protected function relationship($queryBuilder)
515
    {
516
        return $queryBuilder;
517
    }
518
519
    /**
520
     *
521
     * @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...
522
     * @param type $updateFields
523
     *
524
     * USE:
525
     *
526
     * $this->getEntityManager()
527
     *      ->getRepository('User')
528
     *      ->onDuplicateUpdate(['column1' => 'user_reminder_1', 'column2' => 235], ['column2' => 255]);
529
     */
530
    public function onDuplicateUpdate($insertFields, $updateFields)
531
    {
532
        //---CHIAVI
533
        $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

533
        $array_keys = array_keys(/** @scrutinizer ignore-type */ $insertFields);
Loading history...
534
        $list_keys = '`' . implode('`,`', $array_keys) . '`';
535
536
        //---VALORI
537
        $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

537
        $list_values = "'" . implode("', '", /** @scrutinizer ignore-type */ $insertFields) . "'";
Loading history...
538
539
        $table = $this->getEntityManager()->getClassMetadata($this->getEntityName())->getTableName();
540
541
        $sql = 'INSERT INTO '.$table;
542
        $sql .= '('. $list_keys . ') ';
543
        //$sql .= 'VALUES("'.implode('","', $insertFields).'") ';
544
        $sql .= "VALUES(". $list_values.") ";
545
        $sql .= 'ON DUPLICATE KEY UPDATE ';
546
547
        $c = 0;
548
        foreach($updateFields as $column => $value) {
549
            if($c>0)$sql .= ", ";
550
            $sql .= '`'.$column . "` = '". $value."'";
551
            $c++;
552
        }
553
554
        $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
555
        $stmt->execute();
556
    }
557
558
    public function getQueryBuilderFactoryWithoutInitialization()
559
    {
560
        return $this->queryBuilderFactory;
561
    }
562
563
    public function setConfigProvider(ConfigProvider $provider)
564
    {
565
        $this->configProvider = $provider;
566
567
        return $this;
568
    }
569
570
    public function ensureQueryOptionIsDefined()
571
    {
572
        if (!$this->queryOptions) {
573
            throw new \RuntimeException(
574
                'Oops! QueryBuilderOptions was never defined.'
575
            );
576
        }
577
    }
578
}
579