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
01:46
created

BaseRepository::findAllPaginated()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 2
nop 0
dl 0
loc 19
ccs 6
cts 8
cp 0.75
crap 3.1406
rs 9.4285
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->initFromQueryBuilderOptions($this->queryOptions);
72
73
        return $this->queryBuilderFactory;
74
    }
75
76
    public function useResultCache($bool)
77
    {
78 1
        $this->use_result_cache = $bool;
79
    }
80 1
81
    public function setRequest(Request $request)
82
    {
83
        return $this->setQueryOptionsFromRequest($request);
84
    }
85
86
    public function setRequestWithFilter(Request $request, $filter)
87
    {
88
        return $this->setQueryOptionsFromRequestWithCustomFilter($request, $filter);
89
    }
90
91
    public function setRequestWithOrFilter(Request $request, $orFilter)
92
    {
93
        return $this->setQueryOptionsFromRequestWithCustomOrFilter($request, $orFilter);
94
    }
95
96
    public function setQueryOptions(QueryBuilderOptions $options)
97
    {
98 3
        $this->queryOptions = $options;
99
    }
100 3
101
    public function setQueryOptionsFromRequest(Request $request = null)
102 3
    {
103 3
        $requestAttributes = [];
104 3
        foreach ($request->attributes->all() as $attributeName => $attributeValue) {
105 3
            $requestAttributes[$attributeName] = $request->attributes->get(
106 3
                $attributeName,
107 3
                $attributeValue
108 3
            );
109 3
        }
110 3
111
        $filters     = $request->query->get('filtering', []);
112 3
        $orFilters   = $request->query->get('filtering_or', []);
113
        $sorting     = $request->query->get('sorting', []);
114 3
        $printing    = $request->query->get('printing', []);
115 3
        $rel         = $request->query->get('rel', '');
116
        $page        = $request->query->get('page', '');
117
        $select      = $request->query->get('select', $this->entityAlias);
118
        $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...
119
        $filtering   = $request->query->get('filtering', '');
120
        $limit       = $request->query->get('limit', '');
121
122
        $filterOrCorrected = [];
123
124
        $count = 0;
125
        foreach ($orFilters as $key => $filter) {
126
            if (is_array($filter)) {
127 3
                foreach ($filter as $keyInternal => $internal) {
128 3
                    $filterOrCorrected[$keyInternal .'|' . $count] = $internal;
129 3
                    $count = $count + 1;
130 3
                }
131 3
            } else {
132 3
                $filterOrCorrected[$key] = $filter;
133 3
            }
134 3
        }
135 3
136 3
        $requestProperties = [
137
            'filtering'   => $filtering,
138
            'orFiltering' => $filterOrCorrected,
139 3
            'limit'       => $limit,
140 3
            'page'        => $page,
141 3
            'filters'     => $filters,
142
            'orFilters'   => $filterOrCorrected,
143
            'sorting'     => $sorting,
144 3
            'rel'         => $rel,
145
            'printing'    => $printing,
146 3
            'select'      => $select,
147
        ];
148
149 4
        $options = array_merge(
150
            $requestAttributes,
151 4
            $requestProperties
152
        );
153 4
154
        $this->queryOptions = QueryBuilderOptions::fromArray($options);
155
156
        return $this;
157
    }
158
159 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...
160 4
    {
161
        $filters = $request->query->get('filtering', []);
162
        $orFilters = $request->query->get('filtering_or', []);
163
        $sorting = $request->query->get('sorting', []);
164
        $printing = $request->query->get('printing', []);
165
        $rel = $request->query->get('rel', '');
166
        $page = $request->query->get('page', '');
167
        $select = $request->query->get('select', $this->entityAlias);
168
        $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...
169
        $filtering = $request->query->get('filtering', '');
170
        $limit = $request->query->get('limit', '');
171
172
        $filters = array_merge($filters, $filter);
173
174
        $filterOrCorrected = [];
175
176
        $count = 0;
177
        foreach ($orFilters as $key => $filter) {
178
            if (is_array($filter)) {
179
                foreach ($filter as $keyInternal => $internal) {
180
                    $filterOrCorrected[$keyInternal .'|' . $count] = $internal;
181
                    $count = $count + 1;
182
                }
183
            } else {
184
                $filterOrCorrected[$key] = $filter;
185
            }
186
        }
187
188
        $this->queryOptions = QueryBuilderOptions::fromArray([
189
            '_route' => $request->attributes->get('_route'),
190
            'customer_id' => $request->attributes->get('customer_id'),
191
            'id' => $request->attributes->get('id'),
192
            'filtering' => $filtering,
193
            'limit' => $limit,
194
            'page' => $page,
195
            'filters' => $filters,
196
            'orFilters' => $filterOrCorrected,
197
            'sorting' => $sorting,
198
            'rel' => $rel,
199
            'printing' => $printing,
200
            'select' => $select,
201
        ]);
202
203
        return $this;
204
    }
205
206 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...
207
    {
208
        $filters = $request->query->get('filtering', []);
209
        $orFilters = $request->query->get('filtering_or', []);
210
        $sorting = $request->query->get('sorting', []);
211
        $printing = $request->query->get('printing', []);
212
        $rel = $request->query->get('rel', '');
213
        $page = $request->query->get('page', '');
214
        $select = $request->query->get('select', $this->entityAlias);
215
        $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...
216
        $filtering = $request->query->get('filtering', '');
217
        $limit = $request->query->get('limit', '');
218 1
219
        $orFilters = array_merge($orFilters, $orFilter);
220 1
221
        $filterOrCorrected = [];
222 1
223 1
        $count = 0;
224 1
        foreach ($orFilters as $key => $filter) {
225 1
            if (is_array($filter)) {
226 1
                foreach ($filter as $keyInternal => $internal) {
227 1
                    $filterOrCorrected[$keyInternal .'|' . $count] = $internal;
228 1
                    $count = $count + 1;
229 1
                }
230 1
            } else {
231
                $filterOrCorrected[$key] = $filter;
232 1
            }
233
        }
234 1
235
        $this->queryOptions = QueryBuilderOptions::fromArray([
236 1
            '_route' => $request->attributes->get('_route'),
237 1
            'customer_id' => $request->attributes->get('customer_id'),
238
            'id' => $request->attributes->get('id'),
239
            'filtering' => $filtering,
240
            'limit' => $limit,
241
            'page' => $page,
242
            'filters' => $filters,
243
            'orFilters' => $filterOrCorrected,
244
            'sorting' => $sorting,
245
            'rel' => $rel,
246
            'printing' => $printing,
247
            'select' => $select,
248
        ]);
249 1
250 1
        return $this;
251 1
    }
252 1
253 1
    public function getRequest()
254 1
    {
255 1
        return $this->request;
256 1
    }
257 1
258 1
    public function setRouteName($route_name = '')
259 1
    {
260 1
        $this->route_name = $route_name;
261
        return $this;
262
    }
263 1
264 1
    public function findAllPaginated()
265 1
    {
266
        if ($this->configProvider) {
267
            $this->setRequest($this->configProvider->getRequest());
268 1
            $this->queryBuilderFactory->setConfigProvider($this->configProvider);
269
        }
270 1
271
        if (!$this->queryOptions) {
272
            throw new \RuntimeException(
273 4
                'Oops! QueryBuilderOptions was never defined.'
274
            );
275 4
        }
276
277
        $this->initFromQueryBuilderOptions($this->queryOptions);
278
279
        $this->queryBuilderFactory->filter();
280
        $this->queryBuilderFactory->sort();
281
282
        return $this->paginateResults($this->queryBuilderFactory->getQueryBuilder());
283
    }
284
285
    protected function paginateResults(
286
        \Doctrine\ORM\QueryBuilder $queryBuilder
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
        foreach ($list as $itemKey => $itemValue) {
331
            $params[$itemValue] = $this->queryOptions->get($itemValue);
332
        }
333
334
        if(!isset($this->route_name)){
335
            $this->route_name = $this->queryOptions->get('_route');
336
        }
337
338
        return new Route($this->route_name, $params);
339
    }
340
341
    /** @deprecate use QueryBuilderFatory instead */
342
    public function noExistsJoin($prevEntityAlias, $currentEntityAlias)
343
    {
344
        $needle = $prevEntityAlias . "_" . $currentEntityAlias;
345
        return ! in_array($needle, $this->joins);
346
    }
347
348
    /** @deprecate use QueryBuilderFatory instead */
349
    public function storeJoin($prevEntityAlias, $currentEntityAlias)
350
    {
351
        $needle = $prevEntityAlias . "_" . $currentEntityAlias;
352
        $this->joins[$needle] = $needle;
353
    }
354
355
    /** @deprecate use QueryBuilderFatory instead */
356
    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

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

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

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