Test Setup Failed
Push — master ( cec486...d03ce1 )
by Raí
09:22 queued 01:32
created
Bludata/Doctrine/ORM/Repositories/QueryWorker.php 1 patch
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -15,40 +15,40 @@  discard block
 block discarded – undo
15 15
 
16 16
     protected $classMetadata;
17 17
 
18
-    protected $entitys = [];
18
+    protected $entitys = [ ];
19 19
 
20
-    protected $tables = [];
20
+    protected $tables = [ ];
21 21
 
22
-    protected $queryFields = [];
22
+    protected $queryFields = [ ];
23 23
 
24
-    protected $expressions = [];
24
+    protected $expressions = [ ];
25 25
 
26
-    protected $groupFields = [];
26
+    protected $groupFields = [ ];
27 27
 
28
-    protected $field = [];
28
+    protected $field = [ ];
29 29
 
30 30
     protected $position = 0;
31 31
 
32
-    protected $fieldValue = [];
32
+    protected $fieldValue = [ ];
33 33
 
34
-    public function __construct(BdContracts\RepositoryContract $repository)
34
+    public function __construct (BdContracts\RepositoryContract $repository)
35 35
     {
36 36
         $this->em = $repository->getEntityManager();
37 37
         $this->queryBuilder = $repository->createQueryBuilder(self::DEFAULT_TABLE_ALIAS);
38 38
         $this->classMetadata = $repository->getClassMetadata();
39 39
     }
40 40
 
41
-    public function getResult(): ArrayCollection
41
+    public function getResult (): ArrayCollection
42 42
     {
43 43
         return new ArrayCollection($this->queryBuilder->getQuery()->execute());
44 44
     }
45 45
 
46
-    public function getOneResult(): ?BdContracts\EntityContract
46
+    public function getOneResult (): ?BdContracts\EntityContract
47 47
     {
48 48
         return $this->queryBuilder->getQuery()->getOneOrNullResult();
49 49
     }
50 50
 
51
-    public function toArray(array $options = []): array
51
+    public function toArray (array $options = [ ]): array
52 52
     {
53 53
         return $this->getResult()
54 54
                     ->map(function ($element) use ($options) {
@@ -63,40 +63,40 @@  discard block
 block discarded – undo
63 63
      *
64 64
      * @return QueryWorker
65 65
      */
66
-    public function withFilters(array $filters = null)
66
+    public function withFilters (array $filters = null)
67 67
     {
68 68
         if ($filters) {
69 69
             foreach ($filters as $filter) {
70
-                switch ($filter['type']) {
70
+                switch ($filter[ 'type' ]) {
71 71
                     case 'select':
72
-                        $this->select($filter['fields']);
72
+                        $this->select($filter[ 'fields' ]);
73 73
                         break;
74 74
                     case 'andWhere':
75
-                        $this->andWhere($filter['field'], $filter['operation'], $filter['value']);
75
+                        $this->andWhere($filter[ 'field' ], $filter[ 'operation' ], $filter[ 'value' ]);
76 76
                         break;
77 77
                     case 'orWhere':
78
-                        $this->orWhere($filter['field'], $filter['operation'], $filter['value']);
78
+                        $this->orWhere($filter[ 'field' ], $filter[ 'operation' ], $filter[ 'value' ]);
79 79
                         break;
80 80
                     case 'andHaving':
81
-                        $this->andHaving($filter['field'], $filter['operation'], $filter['value']);
81
+                        $this->andHaving($filter[ 'field' ], $filter[ 'operation' ], $filter[ 'value' ]);
82 82
                         break;
83 83
                     case 'orHaving':
84
-                        $this->orHaving($filter['field'], $filter['operation'], $filter['value']);
84
+                        $this->orHaving($filter[ 'field' ], $filter[ 'operation' ], $filter[ 'value' ]);
85 85
                         break;
86 86
                     case 'addGroupBy':
87
-                        $this->addGroupBy($filter['field']);
87
+                        $this->addGroupBy($filter[ 'field' ]);
88 88
                         break;
89 89
                     case 'addOrderBy':
90
-                        $this->addOrderBy($filter['field'], $filter['order']);
90
+                        $this->addOrderBy($filter[ 'field' ], $filter[ 'order' ]);
91 91
                         break;
92 92
                     case 'fkAddOrderBy':
93
-                        $this->fkAddOrderBy($filter['field'], $filter['fkField'], $filter['order']);
93
+                        $this->fkAddOrderBy($filter[ 'field' ], $filter[ 'fkField' ], $filter[ 'order' ]);
94 94
                         break;
95 95
                     case 'paginate':
96
-                        if (isset($filter['page'])) {
97
-                            $this->paginate($filter['limit'], $filter['page']);
96
+                        if (isset($filter[ 'page' ])) {
97
+                            $this->paginate($filter[ 'limit' ], $filter[ 'page' ]);
98 98
                         } else {
99
-                            $this->paginate($filter['limit']);
99
+                            $this->paginate($filter[ 'limit' ]);
100 100
                         }
101 101
                         break;
102 102
                 }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      *
115 115
      * @return $this
116 116
      */
117
-    public function paginate($limit = 25, $page = 0)
117
+    public function paginate ($limit = 25, $page = 0)
118 118
     {
119 119
         if ($limit > 0) {
120 120
             $this->queryBuilder->setMaxResults($limit);
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      *
137 137
      * @return $this
138 138
      */
139
-    public function andWhere($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS)
139
+    public function andWhere ($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS)
140 140
     {
141 141
         if (strpos($field, '.') > 0) {
142 142
             //monta os joins
@@ -145,8 +145,8 @@  discard block
 block discarded – undo
145 145
                 'operation' => $operation,
146 146
             ];
147 147
             $newAliasField = $this->associationQueryFields($field);
148
-            $alias = $newAliasField['alias'];
149
-            $field = $newAliasField['field'];
148
+            $alias = $newAliasField[ 'alias' ];
149
+            $field = $newAliasField[ 'field' ];
150 150
         }
151 151
         $this->queryBuilder->andWhere($this->makeExpression($field, $operation, $value, $alias));
152 152
 
@@ -162,13 +162,13 @@  discard block
 block discarded – undo
162 162
      *
163 163
      * @return $this
164 164
      */
165
-    public function orWhere($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS)
165
+    public function orWhere ($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS)
166 166
     {
167 167
         if (strpos($field, '.') > 0) {
168 168
             //monta os joins
169 169
             $newAliasField = $this->associationQueryFields($field);
170
-            $alias = $newAliasField['alias'];
171
-            $field = $newAliasField['field'];
170
+            $alias = $newAliasField[ 'alias' ];
171
+            $field = $newAliasField[ 'field' ];
172 172
         }
173 173
         $this->queryBuilder->orWhere($this->makeExpression($field, $operation, $value, $alias));
174 174
 
@@ -182,18 +182,18 @@  discard block
 block discarded – undo
182 182
      *
183 183
      * @return $this
184 184
      */
185
-    private function makeExpressions($conditions, $alias = self::DEFAULT_TABLE_ALIAS)
185
+    private function makeExpressions ($conditions, $alias = self::DEFAULT_TABLE_ALIAS)
186 186
     {
187
-        $expressions = [];
187
+        $expressions = [ ];
188 188
         foreach ($conditions as $attr) {
189
-            $field = $attr['field'];
189
+            $field = $attr[ 'field' ];
190 190
             if (strpos($field, '.') > 0) {
191 191
                 //monta os joins
192 192
                 $newAliasField = $this->associationQueryFields($field);
193
-                $alias = $newAliasField['alias'];
194
-                $field = $newAliasField['field'];
193
+                $alias = $newAliasField[ 'alias' ];
194
+                $field = $newAliasField[ 'field' ];
195 195
             }
196
-            $expressions[] = $this->makeExpression($field, $attr['operation'], $attr['value'], $alias);
196
+            $expressions[ ] = $this->makeExpression($field, $attr[ 'operation' ], $attr[ 'value' ], $alias);
197 197
         }
198 198
 
199 199
         return $expressions;
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      *
205 205
      * @param string $field
206 206
      */
207
-    public function addGroupBy($field)
207
+    public function addGroupBy ($field)
208 208
     {
209 209
         $alias = self::DEFAULT_TABLE_ALIAS;
210 210
         if (strpos($field, '.') > 0) {
@@ -213,15 +213,15 @@  discard block
 block discarded – undo
213 213
         }
214 214
         if (count($this->queryFields) > 0) {
215 215
             foreach ($this->queryFields as $item) {
216
-                $parts = [];
216
+                $parts = [ ];
217 217
                 if (strpos($item, ' AS ')) {
218 218
                     $item = str_replace(')', '', str_replace('(', '', $item));
219 219
                     $parts = explode('AS', $item);
220
-                    $item = trim($parts[0]);
220
+                    $item = trim($parts[ 0 ]);
221 221
                 }
222 222
                 if (!in_array($item, $this->groupFields)) {
223 223
                     $this->queryBuilder->addGroupBy($item);
224
-                    $this->groupFields[] = $item;
224
+                    $this->groupFields[ ] = $item;
225 225
                 }
226 226
             }
227 227
         }
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      *
239 239
      * @return $this
240 240
      */
241
-    public function andHaving($field, $operation, $value = null)
241
+    public function andHaving ($field, $operation, $value = null)
242 242
     {
243 243
         throw new \Exception('Not implemented');
244 244
     }
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      *
249 249
      * @param string $field
250 250
      */
251
-    public function orHaving($field, $operation, $value = null)
251
+    public function orHaving ($field, $operation, $value = null)
252 252
     {
253 253
         throw new \Exception('Not implemented');
254 254
     }
@@ -259,14 +259,14 @@  discard block
 block discarded – undo
259 259
      * @param string $field
260 260
      * @param string $order
261 261
      */
262
-    public function addOrderBy($field, $order = 'ASC')
262
+    public function addOrderBy ($field, $order = 'ASC')
263 263
     {
264 264
         $alias = self::DEFAULT_TABLE_ALIAS;
265 265
         if (strpos($field, '.') > 0) {
266 266
             //monta os joins
267 267
             $newAliasField = $this->associationQueryFields($field);
268
-            $alias = $newAliasField['alias'];
269
-            $field = $newAliasField['field'];
268
+            $alias = $newAliasField[ 'alias' ];
269
+            $field = $newAliasField[ 'field' ];
270 270
         }
271 271
         $this->queryBuilder->addOrderBy($this->getFullFieldName($field, $alias), $order);
272 272
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      * @param string $field
280 280
      * @param string $order
281 281
      */
282
-    public function fkAddOrderBy($field, $fkField, $order = 'ASC')
282
+    public function fkAddOrderBy ($field, $fkField, $order = 'ASC')
283 283
     {
284 284
         $alias = $this->tableAlias();
285 285
         $this->queryBuilder->join($this->getFullFieldName($field), $alias);
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      * @param associationField.fkField
295 295
      * @param $field
296 296
      */
297
-    public function select($fields)
297
+    public function select ($fields)
298 298
     {
299 299
         foreach ($fields as $key => $value) {
300 300
             if (is_int($key)) {
@@ -303,10 +303,10 @@  discard block
 block discarded – undo
303 303
                 $alias = $this->tableAlias();
304 304
                 $this->queryBuilder->join($this->getFullFieldName($key, self::DEFAULT_TABLE_ALIAS), $alias);
305 305
                 foreach ($value as $valueField) {
306
-                    $this->queryFields[] = $this->getFullFieldName($valueField, $alias);
306
+                    $this->queryFields[ ] = $this->getFullFieldName($valueField, $alias);
307 307
                 }
308 308
             } else {
309
-                $this->queryFields[] = $value;
309
+                $this->queryFields[ ] = $value;
310 310
             }
311 311
         }
312 312
         $this->queryBuilder->select(implode(',', $this->queryFields));
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      * @param associationField.fkField
321 321
      * @param $field
322 322
      */
323
-    public function associationQueryFields($campo)
323
+    public function associationQueryFields ($campo)
324 324
     {
325 325
         $this->field = $campo;
326 326
         $pos = strpos($campo, '.');
@@ -328,11 +328,11 @@  discard block
 block discarded – undo
328 328
             $arr = explode('.', $campo);
329 329
             $lastField = end($arr);
330 330
 
331
-            if (count($arr) == 2 && $arr[0] == self::DEFAULT_TABLE_ALIAS) {
331
+            if (count($arr) == 2 && $arr[ 0 ] == self::DEFAULT_TABLE_ALIAS) {
332 332
                 //não é um campo composto
333 333
                 return [
334 334
                     'field' => $lastField,
335
-                    'alias' => $arr[0],
335
+                    'alias' => $arr[ 0 ],
336 336
                 ];
337 337
             }
338 338
 
@@ -343,14 +343,14 @@  discard block
 block discarded – undo
343 343
                 if ($this->position < count($arr) - 1) {
344 344
                     $dados = $this->getMetaAndAliases();
345 345
 
346
-                    $alias = $dados['alias'];
347
-                    $parentAlias = $dados['parentAlias'];
346
+                    $alias = $dados[ 'alias' ];
347
+                    $parentAlias = $dados[ 'parentAlias' ];
348 348
 
349 349
                     if ($tempMeta) {
350 350
                         $meta = $tempMeta;
351 351
                         $tempMeta = '';
352 352
                     } else {
353
-                        $meta = $dados['parentMeta'];
353
+                        $meta = $dados[ 'parentMeta' ];
354 354
                     }
355 355
 
356 356
                     if ($meta->isAssociationWithSingleJoinColumn($value)) {
@@ -358,22 +358,22 @@  discard block
 block discarded – undo
358 358
                         $association = $meta->getAssociationMapping($value);
359 359
                         $this->setLeftJoin(
360 360
                             $meta->getAssociationTargetClass($value),
361
-                            $association['joinColumns'][0]['referencedColumnName'],
362
-                            $association['fieldName'],
361
+                            $association[ 'joinColumns' ][ 0 ][ 'referencedColumnName' ],
362
+                            $association[ 'fieldName' ],
363 363
                             $alias,
364 364
                             $parentAlias
365 365
                         );
366 366
                     } elseif ($meta->isCollectionValuedAssociation($value)) {
367 367
                         $association = $meta->getAssociationMapping($value);
368
-                        if (empty($association['mappedBy']) && empty($association['joinTable'])) {
368
+                        if (empty($association[ 'mappedBy' ]) && empty($association[ 'joinTable' ])) {
369 369
                             //não tem como fazer o join
370 370
                             $this->critical(sprintf('"%s" não é uma associação válida', $campo));
371 371
                             continue;
372 372
                         }
373
-                        if (!empty($association['joinTable'])) {
373
+                        if (!empty($association[ 'joinTable' ])) {
374 374
                             //manyToMany
375 375
                             $this->setManyToManyJoin(
376
-                                $this->getFullFieldName($association['fieldName'], $parentAlias),
376
+                                $this->getFullFieldName($association[ 'fieldName' ], $parentAlias),
377 377
                                 $alias,
378 378
                                 $this->setManyToManyValuedCondition($association, $alias, $arr)
379 379
                             );
@@ -381,8 +381,8 @@  discard block
 block discarded – undo
381 381
                             //oneToMany
382 382
                             $this->setLeftJoin(
383 383
                                 $meta->getAssociationTargetClass($value),
384
-                                $this->getTargetField($dados['meta'], $meta, $value),
385
-                                $meta->getIdentifierColumnNames()[0],
384
+                                $this->getTargetField($dados[ 'meta' ], $meta, $value),
385
+                                $meta->getIdentifierColumnNames()[ 0 ],
386 386
                                 $alias,
387 387
                                 $parentAlias
388 388
                             );
@@ -391,9 +391,9 @@  discard block
 block discarded – undo
391 391
                         //subClass
392 392
                         if (count($meta->subClasses) > 0) {
393 393
                             $temp = $this->getSubClassFields($meta, $value);
394
-                            if (!empty($temp['meta'])) {
395
-                                $this->setLeftJoin($temp['table'], $temp['targetField'], $temp['parentField'], $alias, $parentAlias);
396
-                                $tempMeta = $temp['meta'];
394
+                            if (!empty($temp[ 'meta' ])) {
395
+                                $this->setLeftJoin($temp[ 'table' ], $temp[ 'targetField' ], $temp[ 'parentField' ], $alias, $parentAlias);
396
+                                $tempMeta = $temp[ 'meta' ];
397 397
                             }
398 398
                         }
399 399
                     }
@@ -420,23 +420,23 @@  discard block
 block discarded – undo
420 420
      *
421 421
      * @return string
422 422
      */
423
-    private function getMetaAndAliases()
423
+    private function getMetaAndAliases ()
424 424
     {
425 425
         $arr = explode('.', $this->field);
426 426
         $meta = $this->classMetadata;
427
-        $metaAnterior = [];
427
+        $metaAnterior = [ ];
428 428
         $parent = '';
429 429
         $alias = '';
430 430
 
431 431
         for ($i = 0; $i <= $this->position; $i++) {
432 432
             $metaAnterior = $meta;
433 433
 
434
-            if ($meta->hasAssociation($arr[$i])) {
435
-                $class = $meta->getAssociationTargetClass($arr[$i]);
434
+            if ($meta->hasAssociation($arr[ $i ])) {
435
+                $class = $meta->getAssociationTargetClass($arr[ $i ]);
436 436
             } elseif (count($meta->subClasses) > 0) {
437
-                $temp = $this->getSubClassFields($meta, $arr[$i]);
438
-                if (!empty($temp['meta'])) {
439
-                    $class = $temp['table'];
437
+                $temp = $this->getSubClassFields($meta, $arr[ $i ]);
438
+                if (!empty($temp[ 'meta' ])) {
439
+                    $class = $temp[ 'table' ];
440 440
                 }
441 441
             }
442 442
 
@@ -444,12 +444,12 @@  discard block
 block discarded – undo
444 444
 
445 445
             if ($i < $this->position) {
446 446
                 $parent .= $parent != '' ? '_' : '';
447
-                $parent .= $arr[$i];
447
+                $parent .= $arr[ $i ];
448 448
             }
449 449
             if ($i == $this->position) {
450 450
                 $alias .= $parent;
451 451
                 $alias .= $parent != '' ? '_' : '';
452
-                $alias .= $arr[$i];
452
+                $alias .= $arr[ $i ];
453 453
             }
454 454
         }
455 455
 
@@ -477,12 +477,12 @@  discard block
 block discarded – undo
477 477
      * @param string $alias
478 478
      * @param string $parentAlias
479 479
      */
480
-    private function setJoin($table, $field, $parentField, $alias, $parentAlias)
480
+    private function setJoin ($table, $field, $parentField, $alias, $parentAlias)
481 481
     {
482 482
         if (!in_array($alias, $this->tables)) {
483 483
             $condition = $this->getFullFieldName($field, $alias).' = '.$this->getFullFieldName($parentField, $parentAlias);
484 484
             $this->queryBuilder->join($table, $alias, 'WITH', $condition);
485
-            $this->tables[] = $alias;
485
+            $this->tables[ ] = $alias;
486 486
         }
487 487
     }
488 488
 
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
      * @param string $parentAlias
497 497
      * @param bool   $withWhere
498 498
      */
499
-    private function setLeftJoin($table, $field, $parentField, $alias, $parentAlias, $withWhere = false)
499
+    private function setLeftJoin ($table, $field, $parentField, $alias, $parentAlias, $withWhere = false)
500 500
     {
501 501
         if (!in_array($alias, $this->tables)) {
502 502
             $condition = $this->getFullFieldName($field, $alias).' = '.$this->getFullFieldName($parentField, $parentAlias);
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
             if ($withWhere) {
505 505
                 $this->queryBuilder->andWhere($condition);
506 506
             }
507
-            $this->tables[] = $alias;
507
+            $this->tables[ ] = $alias;
508 508
         }
509 509
     }
510 510
 
@@ -517,14 +517,14 @@  discard block
 block discarded – undo
517 517
      *
518 518
      * @return mix|null
519 519
      */
520
-    private function setManyToManyValuedCondition($association, $alias, $arr)
520
+    private function setManyToManyValuedCondition ($association, $alias, $arr)
521 521
     {
522
-        if (empty($this->fieldValue['value']) || $this->position < count($arr) - 2) {
522
+        if (empty($this->fieldValue[ 'value' ]) || $this->position < count($arr) - 2) {
523 523
             return null;
524 524
         }
525
-        $targetField = $this->position == count($arr) - 1 ? $association['joinTable']['joinColumns'][0]['referencedColumnName'] : end($arr);
525
+        $targetField = $this->position == count($arr) - 1 ? $association[ 'joinTable' ][ 'joinColumns' ][ 0 ][ 'referencedColumnName' ] : end($arr);
526 526
 
527
-        return $this->makeExpression($targetField, $this->fieldValue['operation'], $this->fieldValue['value'], $alias);
527
+        return $this->makeExpression($targetField, $this->fieldValue[ 'operation' ], $this->fieldValue[ 'value' ], $alias);
528 528
     }
529 529
 
530 530
     /**
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
      * @param string $alias
535 535
      * @param mix    $condition
536 536
      */
537
-    private function setManyToManyJoin($table, $alias, $condition = null)
537
+    private function setManyToManyJoin ($table, $alias, $condition = null)
538 538
     {
539 539
         if (!in_array($alias, $this->tables)) {
540 540
             if ($condition) {
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
             } else {
543 543
                 $this->queryBuilder->join($table, $alias);
544 544
             }
545
-            $this->tables[] = $alias;
545
+            $this->tables[ ] = $alias;
546 546
         }
547 547
     }
548 548
 
@@ -553,19 +553,19 @@  discard block
 block discarded – undo
553 553
      * @param $value
554 554
      * @param $alias
555 555
      */
556
-    private function setQueryField($meta, $value, $alias)
556
+    private function setQueryField ($meta, $value, $alias)
557 557
     {
558 558
         $campo = $this->getFullFieldName($value, $alias);
559 559
 
560 560
         if ($meta->isSingleValuedAssociation($value)) {
561
-            $targetField = $meta->getAssociationMapping($value)['joinColumns'][0]['referencedColumnName'];
561
+            $targetField = $meta->getAssociationMapping($value)[ 'joinColumns' ][ 0 ][ 'referencedColumnName' ];
562 562
             $alias = $alias == self::DEFAULT_TABLE_ALIAS ? substr($campo, strpos($campo, '.') + 1) : $alias.'_'.$targetField;
563 563
             $campo = 'IDENTITY('.$campo.') '.$alias;
564 564
         } elseif ($this->position > 0) {
565 565
             $campo = '('.$campo.') AS '.$alias.'_'.$value;
566 566
         }
567 567
         // acrescenta o campo ao select
568
-        $this->queryFields[] = $campo;
568
+        $this->queryFields[ ] = $campo;
569 569
     }
570 570
 
571 571
     /**
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
      *
577 577
      * @return string
578 578
      */
579
-    private function getSubClassFields($meta, $value)
579
+    private function getSubClassFields ($meta, $value)
580 580
     {
581 581
         foreach ($meta->subClasses as $subClass) {
582 582
             $delimiter = strpos($subClass, '/') > 0 ? '/' : '\\';
@@ -585,8 +585,8 @@  discard block
 block discarded – undo
585 585
             if (end($temp) == $value) {
586 586
                 return [
587 587
                     'table'       => $subClass,
588
-                    'parentField' => $meta->getIdentifierColumnNames()[0],
589
-                    'targetField' => $tempMeta->getIdentifierColumnNames()[0],
588
+                    'parentField' => $meta->getIdentifierColumnNames()[ 0 ],
589
+                    'targetField' => $tempMeta->getIdentifierColumnNames()[ 0 ],
590 590
                     'meta'        => $tempMeta,
591 591
                 ];
592 592
             }
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
      *
603 603
      * @return string
604 604
      */
605
-    private function getTargetField($meta, $parentMeta, $value)
605
+    private function getTargetField ($meta, $parentMeta, $value)
606 606
     {
607 607
         if (count($parentMeta->parentClasses) > 0) {
608 608
             foreach ($parentMeta->parentClasses as $classe) {
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
             return $field;
623 623
         }
624 624
 
625
-        return $meta->getIdentifierColumnNames()[0];
625
+        return $meta->getIdentifierColumnNames()[ 0 ];
626 626
     }
627 627
 
628 628
     /**
@@ -634,11 +634,11 @@  discard block
 block discarded – undo
634 634
      *
635 635
      * @return string
636 636
      */
637
-    private function searchAssociationField($associationsByTargetClass, $parentTable, $value)
637
+    private function searchAssociationField ($associationsByTargetClass, $parentTable, $value)
638 638
     {
639 639
         foreach ($associationsByTargetClass as $table => $association) {
640
-            if ($table == $parentTable && $association['inversedBy'] == $value) {
641
-                return $association['fieldName'];
640
+            if ($table == $parentTable && $association[ 'inversedBy' ] == $value) {
641
+                return $association[ 'fieldName' ];
642 642
             }
643 643
         }
644 644
     }
@@ -648,14 +648,14 @@  discard block
 block discarded – undo
648 648
      * @param string $expression
649 649
      * @param string $alias
650 650
      */
651
-    private function getSelectExpression($expression, $field, $alias, $fieldAlias = self::DEFAULT_TABLE_ALIAS)
651
+    private function getSelectExpression ($expression, $field, $alias, $fieldAlias = self::DEFAULT_TABLE_ALIAS)
652 652
     {
653
-        $validExpressions = ['SUM', 'MIN', 'MAX', 'AVG', 'COUNT'];
653
+        $validExpressions = [ 'SUM', 'MIN', 'MAX', 'AVG', 'COUNT' ];
654 654
         if (in_array(trim(strtoupper($expression)), $validExpressions)) {
655 655
             if (strpos($field, '.') === false) {
656 656
                 $field = getFullFieldName($field, $fieldAlias);
657 657
             }
658
-            $this->queryFields[] = sprintf('%s(%s) AS %s', $expression, $field, $alias);
658
+            $this->queryFields[ ] = sprintf('%s(%s) AS %s', $expression, $field, $alias);
659 659
         }
660 660
     }
661 661
 
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
      *
666 666
      * @return string
667 667
      */
668
-    protected function getFullFieldName($field, $alias = self::DEFAULT_TABLE_ALIAS, $separator = '.')
668
+    protected function getFullFieldName ($field, $alias = self::DEFAULT_TABLE_ALIAS, $separator = '.')
669 669
     {
670 670
         return sprintf('%s%s%s', $alias, $separator, $field);
671 671
     }
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
      * @param null   $value
677 677
      * @param string $alias
678 678
      */
679
-    protected function makeExpression($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS)
679
+    protected function makeExpression ($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS)
680 680
     {
681 681
         $originalValue = $value;
682 682
 
@@ -738,10 +738,10 @@  discard block
 block discarded – undo
738 738
                 $expression = $alias.' INSTANCE OF '.$value;
739 739
                 break;
740 740
             case 'between':
741
-                $expression = $this->queryBuilder->expr()->between($field, $this->queryBuilder->expr()->literal($value[0]), $this->queryBuilder->expr()->literal($value[1]));
741
+                $expression = $this->queryBuilder->expr()->between($field, $this->queryBuilder->expr()->literal($value[ 0 ]), $this->queryBuilder->expr()->literal($value[ 1 ]));
742 742
                 break;
743 743
             case 'dateparteq':
744
-                $expression = $this->queryBuilder->expr()->eq("DATEPART('".$value['format']."', ".$field.')', $value['value']);
744
+                $expression = $this->queryBuilder->expr()->eq("DATEPART('".$value[ 'format' ]."', ".$field.')', $value[ 'value' ]);
745 745
         }
746 746
 
747 747
         return $expression;
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
     /**
751 751
      * @return string
752 752
      */
753
-    protected function tableAlias()
753
+    protected function tableAlias ()
754 754
     {
755 755
         return self::DEFAULT_TABLE_ALIAS.count($this->queryBuilder->getAllAliases());
756 756
     }
Please login to merge, or discard this patch.
Bludata/Doctrine/ORM/Traits/ToArrayTrait.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -11,24 +11,24 @@  discard block
 block discarded – undo
11 11
 
12 12
 trait ToArrayTrait
13 13
 {
14
-    private function isOnly(ReflectionProperty $property, array $optionsToArray): bool
14
+    private function isOnly (ReflectionProperty $property, array $optionsToArray): bool
15 15
     {
16
-        if (!isset($optionsToArray['only']) && !isset($optionsToArray['except'])) {
16
+        if (!isset($optionsToArray[ 'only' ]) && !isset($optionsToArray[ 'except' ])) {
17 17
             return true;
18 18
         }
19 19
 
20
-        if (isset($optionsToArray['only'])) {
21
-            if (in_array($property->getName(), $optionsToArray['only'])) {
20
+        if (isset($optionsToArray[ 'only' ])) {
21
+            if (in_array($property->getName(), $optionsToArray[ 'only' ])) {
22 22
                 return true;
23 23
             }
24
-        } elseif (isset($optionsToArray['except']) && !in_array($property->getName(), $optionsToArray['except'])) {
24
+        } elseif (isset($optionsToArray[ 'except' ]) && !in_array($property->getName(), $optionsToArray[ 'except' ])) {
25 25
             return true;
26 26
         }
27 27
 
28 28
         return false;
29 29
     }
30 30
 
31
-    private function getPropertiesFillable(): array
31
+    private function getPropertiesFillable (): array
32 32
     {
33 33
         $allProperties = $this->getRepository()
34 34
                               ->getClassMetadata()
@@ -44,14 +44,14 @@  discard block
 block discarded – undo
44 44
         });
45 45
     }
46 46
 
47
-    public function toArray(array $options = []): array
47
+    public function toArray (array $options = [ ]): array
48 48
     {
49 49
         $classMetadata = $this->getRepository()
50 50
                               ->getClassMetadata();
51 51
 
52 52
         $propertiesFillable = $this->getPropertiesFillable();
53 53
 
54
-        $array = [];
54
+        $array = [ ];
55 55
 
56 56
         foreach ($propertiesFillable as $property) {
57 57
             if ($this->isOnly($property, $options)) {
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
                             $dateFormat = 'Y-m-d';
65 65
 
66 66
                             if ($metaDataKey) {
67
-                                switch ($metaDataKey['type']) {
67
+                                switch ($metaDataKey[ 'type' ]) {
68 68
                                     case 'datetime':
69 69
                                         $dateFormat = 'Y-m-d H:i:s';
70 70
                                         break;
@@ -76,24 +76,24 @@  discard block
 block discarded – undo
76 76
                                 }
77 77
                             }
78 78
 
79
-                            $array[$key] = $this->$key->format($dateFormat);
79
+                            $array[ $key ] = $this->$key->format($dateFormat);
80 80
                         }
81 81
                     } elseif ($this->$key instanceof ArrayCollection || $this->$key instanceof PersistentCollection) {
82
-                        $array[$key] = array_map(function ($item) {
82
+                        $array[ $key ] = array_map(function ($item) {
83 83
                             return $item->getId();
84 84
                         }, $this->$key->getValues());
85 85
                     } else {
86 86
                         if (method_exists($this->$key, 'getId')) {
87
-                            $array[$key] = $this->$key->getId();
87
+                            $array[ $key ] = $this->$key->getId();
88 88
                         } else {
89
-                            $array[$key] = $this->$key;
89
+                            $array[ $key ] = $this->$key;
90 90
                         }
91 91
                     }
92 92
                 } else {
93
-                    if (in_array($metaDataKey['type'], ['decimal', 'float'])) {
94
-                        $array[$key] = (float) $this->$key;
93
+                    if (in_array($metaDataKey[ 'type' ], [ 'decimal', 'float' ])) {
94
+                        $array[ $key ] = (float) $this->$key;
95 95
                     } else {
96
-                        $array[$key] = $this->$key;
96
+                        $array[ $key ] = $this->$key;
97 97
                     }
98 98
                 }
99 99
             }
Please login to merge, or discard this patch.