Completed
Push — master ( 1c49db...1a6bbd )
by Julien
02:00
created

UnitOfWork::getCartMetadata()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
dl 24
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
namespace Mapado\RestClientSdk\Tests\Units;
4
5
use atoum;
6
use Mapado\RestClientSdk\Mapping as RestMapping;
7
use Mapado\RestClientSdk\Mapping\Attribute;
8
use Mapado\RestClientSdk\Mapping\ClassMetadata;
9
use Mapado\RestClientSdk\Mapping\Relation;
10
11
/**
12
 * UnitOfWork
13
 *
14
 * @uses atoum
15
 * @author Julien Petit <[email protected]>
16
 */
17
class UnitOfWork extends atoum
18
{
19
    private $unitOfWork;
0 ignored issues
show
Unused Code introduced by
The property $unitOfWork is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
20
21
    public function testRegister()
22
    {
23
        $mapping = $this->getMapping();
24
        $unitOfWork = $this->newTestedInstance($mapping);
25
26
        $ticket = (object) [
27
            'firstname' => 'foo',
28
            'lastname' => 'bar',
29
            'email' => '[email protected]',
30
        ];
31
        $unitOfWork->registerClean('@id1', $ticket);
32
        $this
33
            ->then
34
                ->variable($unitOfWork->getDirtyEntity('@id1'))
35
                    ->isEqualTo($ticket)
36
        ;
37
    }
38
39
    public function testSimpleEntity()
40
    {
41
        $mapping = $this->getMapping();
42
        $unitOfWork = $this->newTestedInstance($mapping);
43
44
        $this
45
            ->array($unitOfWork->getDirtyData(
46
                [
47
                    '@id' => '/v12/carts/1',
48
                ],
49
                [
50
                    '@id' => '/v12/carts/1',
51
                ],
52
                $this->getCartMetadata()
53
            ))
54
            ->isEqualTo([])
55
            ->then
56
            ->array($unitOfWork->getDirtyData(
57
                [
58
                    '@id' => '/v12/carts/1',
59
                    'status' => 'payed',
60
                    'order' => '/v12/orders/1',
61
                ],
62
                [
63
                    '@id' => '/v12/carts/1',
64
                    'status' => 'payed',
65
                    'order' => '/v12/orders/1',
66
                ],
67
                $this->getCartMetadata()
68
            ))
69
            ->isEqualTo([])
70
            ->then
71
            ->array($unitOfWork->getDirtyData(
72
                [
73
                    '@id' => '/v12/carts/1',
74
                    'status' => 'payed',
75
                ],
76
                [
77
                    '@id' => '/v12/carts/1',
78
                    'status' => 'waiting',
79
                ],
80
                $this->getCartMetadata()
81
            ))
82
            ->isEqualTo(['status' => 'payed'])
83
            ->then
84
            ->array($unitOfWork->getDirtyData(
85
                [
86
                    '@id' => '/v12/carts/2',
87
                    'status' => 'payed',
88
                ],
89
                [
90
                    '@id' => '/v12/carts/1',
91
                    'status' => 'waiting',
92
                ],
93
                $this->getCartMetadata()
94
            ))
95
            ->isEqualTo([
96
                '@id' => '/v12/carts/2',
97
                'status' => 'payed',
98
            ])
99
            ->then
100
            ->array($unitOfWork->getDirtyData(
101
                [
102
                    '@id' => '/v12/carts/1',
103
                    'status' => 'payed',
104
                    'someData' => [
105
                        'foo' => 'bar',
106
                        'loo' => 'baz',
107
                    ],
108
                ],
109
                [
110
                    '@id' => '/v12/carts/1',
111
                    'status' => 'payed',
112
                    'someData' => [
113
                        'foo' => 'bar',
114
                    ],
115
                ],
116
                $this->getCartMetadata()
117
            ))
118
            ->isEqualTo([
119
                'someData' => [
120
                    'foo' => 'bar',
121
                    'loo' => 'baz',
122
                ],
123
            ])
124
        ;
125
    }
126
127
    public function testManyToOneRelation()
128
    {
129
        $mapping = $this->getMapping();
130
        $unitOfWork = $this->newTestedInstance($mapping);
131
132
        $this
133
            ->array($unitOfWork->getDirtyData(
134
                [
135
                    '@id' => '/v12/carts/1',
136
                    'order' => '/v1/orders/2',
137
                ],
138
                [
139
                    '@id' => '/v12/carts/1',
140
                    'order' => [ '@id' => '/v1/orders/1' ],
141
                ],
142
                $this->getCartMetadata()
143
            ))
144
            ->isEqualTo([
145
                'order' => '/v1/orders/2',
146
            ])
147
148
            ->then
149
            ->array($unitOfWork->getDirtyData(
150
                [
151
                    '@id' => '/v12/carts/1',
152
                    'order' => [
153
                        '@id' => '/v1/orders/2',
154
                    ]
155
                ],
156
                [
157
                    '@id' => '/v12/carts/1',
158
                    'order' => '/v1/orders/1',
159
                ],
160
                $this->getCartMetadata()
161
            ))
162
            ->isEqualTo([
163
                'order' => [
164
                    '@id' => '/v1/orders/2',
165
                ],
166
            ])
167
168
            ->then
169
            ->array($unitOfWork->getDirtyData(
170
                [
171
                    '@id' => '/v12/carts/1',
172
                    'order' => [
173
                        '@id' => '/v1/orders/2',
174
                        'status' => 'payed',
175
                    ]
176
                ],
177
                [
178
                    '@id' => '/v12/carts/1',
179
                    'order' => [
180
                        '@id' => '/v1/orders/1',
181
                        'status' => 'payed',
182
                    ],
183
                ],
184
                $this->getCartMetadata()
185
            ))
186
            ->isEqualTo([
187
                'order' => [
188
                    '@id' => '/v1/orders/2',
189
                ],
190
            ])
191
192
            ->then
193
            ->array($unitOfWork->getDirtyData(
194
                [
195
                    '@id' => '/v12/carts/1',
196
                    'order' => [
197
                        '@id' => '/v1/orders/2',
198
                        'status' => 'payed',
199
                    ]
200
                ],
201
                [
202
                    '@id' => '/v12/carts/1',
203
                    'order' => [
204
                        '@id' => '/v1/orders/1',
205
                        'status' => 'waiting',
206
                    ],
207
                ],
208
                $this->getCartMetadata()
209
            ))
210
            ->isEqualTo([
211
                'order' => [
212
                    '@id' => '/v1/orders/2',
213
                    'status' => 'payed',
214
                ],
215
            ])
216
        ;
217
    }
218
219 View Code Duplication
    public function testNoChanges()
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...
220
    {
221
        $mapping = $this->getMapping();
222
        $unitOfWork = $this->newTestedInstance($mapping);
223
224
        $this
225
            ->given($newSerializedModel = [
226
                '@id' => '/v12/carts/1',
227
                'cartItemList' => [
228
                    '/v12/cart_items/1',
229
                    '/v12/cart_items/2',
230
                    '/v12/cart_items/3',
231
                ],
232
            ])
233
            ->then
234
                ->variable($unitOfWork->getDirtyData(
235
                    $newSerializedModel,
236
                    [
237
                        '@id' => '/v12/carts/1',
238
                        'cartItemList' => [
239
                            '/v12/cart_items/1',
240
                            '/v12/cart_items/2',
241
                            '/v12/cart_items/3',
242
                        ],
243
                    ],
244
                    $this->getCartMetadata()
245
                ))
246
                ->isEqualTo(
247
                    [
248
                    ]
249
                )
250
            ->then
251
                ->variable($unitOfWork->getDirtyData(
252
                    [
253
                        '@id' => '/v12/carts/1',
254
                        'cartItemList' => [
255
                            [
256
                                '@id' => '/v12/cart_items/1',
257
                                'amount' => 1,
258
                            ],
259
                            [
260
                                '@id' => '/v12/cart_items/2',
261
                                'amount' => 1,
262
                            ],
263
                        ],
264
                    ],
265
                    [
266
                        '@id' => '/v12/carts/1',
267
                        'cartItemList' => [
268
                            [
269
                                '@id' => '/v12/cart_items/1',
270
                                'amount' => 1,
271
                            ],
272
                            [
273
                                '@id' => '/v12/cart_items/2',
274
                                'amount' => 1,
275
                            ],
276
                        ],
277
                    ],
278
                    $this->getCartMetadata()
279
                ))
280
                ->isEqualTo(
281
                    [
282
                    ]
283
                )
284
        ;
285
    }
286
287 View Code Duplication
    public function testNoMetadata()
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...
288
    {
289
        $mapping = $this->getMapping();
290
        $unitOfWork = $this->newTestedInstance($mapping);
291
292
        $this
293
            ->given($newSerializedModel = [
294
                '@id' => '/v12/carts/1',
295
                'cartInfo' => [
296
                    [
297
                        'firstname' => 'john',
298
                        'lastname' => 'doe',
299
                    ],
300
                ],
301
            ])
302
            ->then
303
                ->variable($unitOfWork->getDirtyData(
304
                    $newSerializedModel,
305
                    [
306
                        '@id' => '/v12/carts/1',
307
                        'cartInfo' => [
308
                            [
309
                                'firstname' => 'john',
310
                                'lastname' => 'doe',
311
                            ],
312
                        ],
313
                    ],
314
                    $this->getCartMetadata()
315
                ))
316
                ->isEqualTo(
317
                    [
318
                    ]
319
                )
320
            ->then
321
                ->variable($unitOfWork->getDirtyData(
322
                    [
323
                        '@id' => '/v12/carts/1',
324
                        'cartItemList' => [
325
                            [
326
                                '@id' => '/v12/cart_items/1',
327
                                'amount' => 1,
328
                            ],
329
                            [
330
                                '@id' => '/v12/cart_items/2',
331
                                'amount' => 1,
332
                            ],
333
                        ],
334
                    ],
335
                    [
336
                        '@id' => '/v12/carts/1',
337
                        'cartItemList' => [
338
                            [
339
                                '@id' => '/v12/cart_items/1',
340
                                'amount' => 1,
341
                            ],
342
                            [
343
                                '@id' => '/v12/cart_items/2',
344
                                'amount' => 1,
345
                            ],
346
                        ],
347
                    ],
348
                    $this->getCartMetadata()
349
                ))
350
                ->isEqualTo(
351
                    [
352
                    ]
353
                )
354
        ;
355
    }
356
357
    public function testRemoveItem()
358
    {
359
        $mapping = $this->getMapping();
360
        $unitOfWork = $this->newTestedInstance($mapping);
361
362
        $this
363
            ->then
364
                ->variable($unitOfWork->getDirtyData(
365
                    [
366
                        '@id' => '/v12/carts/1',
367
                        'cartItemList' => [
368
                            '/v12/cart_items/1',
369
                            '/v12/cart_items/2',
370
                        ],
371
                    ],
372
                    [
373
                        '@id' => '/v12/carts/1',
374
                        'cartItemList' => [
375
                            '/v12/cart_items/1',
376
                            '/v12/cart_items/2',
377
                            '/v12/cart_items/3',
378
                        ],
379
                    ],
380
                    $this->getCartMetadata()
381
                ))
382
                ->isEqualTo(
383
                    [
384
                        'cartItemList' => [
385
                            '/v12/cart_items/1',
386
                            '/v12/cart_items/2',
387
                        ],
388
                    ]
389
                )
390
            ->then
391
                ->variable($unitOfWork->getDirtyData(
392
                    [
393
                        '@id' => '/v12/carts/1',
394
                        'cartItemList' => [
395
                            '/v12/cart_items/1',
396
                            '/v12/cart_items/3',
397
                        ],
398
                    ],
399
                    [
400
                        '@id' => '/v12/carts/1',
401
                        'cartItemList' => [
402
                            '/v12/cart_items/1',
403
                            '/v12/cart_items/2',
404
                            '/v12/cart_items/3',
405
                        ],
406
                    ],
407
                    $this->getCartMetadata()
408
                ))
409
                ->isEqualTo(
410
                    [
411
                        'cartItemList' => [
412
                            '/v12/cart_items/1',
413
                            '/v12/cart_items/3',
414
                        ],
415
                    ]
416
                )
417
            ->then
418
                ->variable($unitOfWork->getDirtyData(
419
                    [
420
                        '@id' => '/v12/carts/1',
421
                        'cartItemList' => [
422
                            [
423
                                '@id' => '/v12/cart_items/1',
424
                                'amount' => 2,
425
                            ],
426
                        ],
427
                    ],
428
                    [
429
                        '@id' => '/v12/carts/1',
430
                        'cartItemList' => [
431
                            [
432
                                '@id' => '/v12/cart_items/1',
433
                                'amount' => 2,
434
                            ],
435
                            [
436
                                '@id' => '/v12/cart_items/2',
437
                                'amount' => 1,
438
                            ],
439
                        ],
440
                    ],
441
                    $this->getCartMetadata()
442
                ))
443
                ->isEqualTo(
444
                    [
445
                        'cartItemList' => [
446
                            [
447
                                '@id' => '/v12/cart_items/1',
448
                            ],
449
                        ],
450
                    ]
451
                )
452
            ->then
453
                ->variable($unitOfWork->getDirtyData(
454
                    [
455
                        '@id' => '/v12/carts/1',
456
                        'cartItemList' => [
457
                            [
458
                                '@id' => '/v12/cart_items/2',
459
                                'amount' => 1,
460
                            ],
461
                        ],
462
                    ],
463
                    [
464
                        '@id' => '/v12/carts/1',
465
                        'cartItemList' => [
466
                            [
467
                                '@id' => '/v12/cart_items/1',
468
                                'amount' => 2,
469
                            ],
470
                            [
471
                                '@id' => '/v12/cart_items/2',
472
                                'amount' => 1,
473
                            ],
474
                        ],
475
                    ],
476
                    $this->getCartMetadata()
477
                ))
478
                ->isEqualTo(
479
                    [
480
                        'cartItemList' => [
481
                            [
482
                                '@id' => '/v12/cart_items/2',
483
                            ],
484
                        ],
485
                    ]
486
                )
487
            ->then
488
                ->array($unitOfWork->getDirtyData(
489
                    [
490
                        '@id' => '/v12/carts/1',
491
                        'cartItemList' => [
492
                            [
493
                                '@id' => '/v12/cart_items/2',
494
                                'amount' => 2,
495
                            ],
496
                        ],
497
                    ],
498
                    [
499
                        '@id' => '/v12/carts/1',
500
                        'cartItemList' => [
501
                            [
502
                                '@id' => '/v12/cart_items/1',
503
                                'amount' => 2,
504
                            ],
505
                            [
506
                                '@id' => '/v12/cart_items/2',
507
                                'amount' => 1,
508
                            ],
509
                        ],
510
                    ],
511
                    $this->getCartMetadata()
512
                ))
513
                ->isEqualTo(
514
                    [
515
                        'cartItemList' => [
516
                            [
517
                                '@id' => '/v12/cart_items/2',
518
                                'amount' => 2,
519
                            ],
520
                        ],
521
                    ]
522
                )
523
        ;
524
    }
525
526
    public function testAddItem()
527
    {
528
        $mapping = $this->getMapping();
529
        $unitOfWork = $this->newTestedInstance($mapping);
530
531
        $this
532
            ->then
533
                ->variable($unitOfWork->getDirtyData(
534
                    [
535
                        '@id' => '/v12/carts/1',
536
                        'cartItemList' => [
537
                            '/v12/cart_items/1',
538
                            '/v12/cart_items/2',
539
                            '/v12/cart_items/3',
540
                        ],
541
                    ],
542
                    [
543
                        '@id' => '/v12/carts/1',
544
                        'cartItemList' => [
545
                            '/v12/cart_items/1',
546
                            '/v12/cart_items/2',
547
                        ],
548
                    ],
549
                    $this->getCartMetadata()
550
                ))
551
                ->isEqualTo(
552
                    [
553
                        'cartItemList' => [
554
                            '/v12/cart_items/1',
555
                            '/v12/cart_items/2',
556
                            '/v12/cart_items/3',
557
                        ],
558
                    ]
559
                )
560
            ->then
561
                ->variable($unitOfWork->getDirtyData(
562
                    [
563
                        '@id' => '/v12/carts/1',
564
                        'cartItemList' => [
565
                            [
566
                                '@id' => '/v12/cart_items/1',
567
                                'amount' => 1,
568
                            ],
569
                            [
570
                                '@id' => '/v12/cart_items/2',
571
                                'amount' => 1,
572
                            ],
573
                        ],
574
                    ],
575
                    [
576
                        '@id' => '/v12/carts/1',
577
                        'cartItemList' => [
578
                            [
579
                                '@id' => '/v12/cart_items/1',
580
                                'amount' => 1,
581
                            ],
582
                        ],
583
                    ],
584
                    $this->getCartMetadata()
585
                ))
586
                ->isEqualTo(
587
                    [
588
                        'cartItemList' => [
589
                            [
590
                                '@id' => '/v12/cart_items/1',
591
                            ],
592
                            [
593
                                '@id' => '/v12/cart_items/2',
594
                                'amount' => 1,
595
                            ],
596
                        ],
597
                    ]
598
                )
599
        ;
600
    }
601
602
    public function testSendOnlyDirty()
603
    {
604
        $mapping = $this->getMapping();
605
        $unitOfWork = $this->newTestedInstance($mapping);
606
607
        $this
608
            ->then
609
                ->variable($unitOfWork->getDirtyData(
610
                    [
611
                        '@id' => '/v12/carts/1',
612
                        'cartItemList' => [
613
                            [
614
                                '@id' => '/v12/cart_items/1',
615
                                'amount' => 2,
616
                            ],
617
                            [
618
                                '@id' => '/v12/cart_items/2',
619
                                'amount' => 1,
620
                            ],
621
                        ],
622
                    ],
623
                    [
624
                        '@id' => '/v12/carts/1',
625
                        'cartItemList' => [
626
                            [
627
                                '@id' => '/v12/cart_items/1',
628
                                'amount' => 1,
629
                            ],
630
                            [
631
                                '@id' => '/v12/cart_items/2',
632
                                'amount' => 1,
633
                            ],
634
                        ],
635
                    ],
636
                    $this->getCartMetadata()
637
                ))
638
                ->isEqualTo(
639
                    [
640
                        'cartItemList' => [
641
                            [
642
                                '@id' => '/v12/cart_items/1',
643
                                'amount' => 2,
644
                            ],
645
                        ],
646
                    ]
647
                )
648
             ->then
649
                ->variable($unitOfWork->getDirtyData(
650
                    [
651
                        '@id' => '/v12/carts/1',
652
                        'status' => 'ok',
653
                        'clientPhoneNumber' => '+33123456789',
654
                    ],
655
                    [
656
                        '@id' => '/v12/carts/1',
657
                        'status' => 'ko',
658
                        'clientPhoneNumber' => '+33123456789',
659
                    ],
660
                    $this->getCartMetadata()
661
                ))
662
                ->isEqualTo(
663
                    [
664
                        'status' => 'ok',
665
                    ]
666
                )
667
            ->then
668
                ->variable($unitOfWork->getDirtyData(
669
                    [
670
                        'cartItemList' => [
671
                            [
672
                                '@id' => '/v12/cart_items/1',
673
                                'amount' => 1,
674
                                'cartItemDetailList' => [
675
                                    [
676
                                        '@id' => '/v12/cart_item_details/1',
677
                                        'name' => '',
678
                                    ],
679
                                ],
680
                            ],
681
                            [
682
                                '@id' => '/v12/cart_items/2',
683
                                'amount' => 1,
684
                            ],
685
                            [
686
                                '@id' => '/v12/cart_items/3',
687
                                'amount' => 1,
688
                                'cartItemDetailList' => [
689
                                    [
690
                                        '@id' => '/v12/cart_item_details/2',
691
                                        'name' => '',
692
                                    ],
693
                                ],
694
                            ],
695
                        ],
696
                    ],
697
                    [
698
                        'cartItemList' => [
699
                            [
700
                                '@id' => '/v12/cart_items/1',
701
                                'amount' => 2,
702
                                'cartItemDetailList' => [
703
                                    '@id' => '/v12/cart_item_details/1',
704
                                    'name' => 'foo',
705
                                ],
706
                            ],
707
                            [
708
                                '@id' => '/v12/cart_items/3',
709
                                'amount' => 1,
710
                            ],
711
                        ],
712
                    ],
713
                    $this->getCartMetadata()
714
                ))
715
                ->isEqualTo(
716
                    [
717
                        'cartItemList' => [
718
                            [
719
                                'amount' => 1,
720
                                'cartItemDetailList' => [
721
                                    [
722
                                        '@id' => '/v12/cart_item_details/1',
723
                                        'name' => '',
724
                                    ],
725
                                ],
726
                                '@id' => '/v12/cart_items/1',
727
                            ],
728
                            [
729
                                '@id' => '/v12/cart_items/2',
730
                                'amount' => 1,
731
                            ],
732
                            [
733
                                '@id' => '/v12/cart_items/3',
734
                                'cartItemDetailList' => [
735
                                    [
736
                                        '@id' => '/v12/cart_item_details/2',
737
                                        'name' => '',
738
                                    ]
739
                                ],
740
                            ],
741
                        ]
742
                    ]
743
                )
744
        ;
745
    }
746
747
    public function testNoMetadataChangeArray()
748
    {
749
        $mapping = $this->getMapping();
750
        $unitOfWork = $this->newTestedInstance($mapping);
751
752
        $this
753
            ->given($newSerializedModel = [
754
                '@id' => '/v12/carts/1',
755
                'cartInfo' => [
756
                    [
757
                        'firstname' => 'jane',
758
                        'lastname' => 'doe',
759
                        'children' => ['rusty', 'john-john-junior'],
760
                    ],
761
                ],
762
            ])
763
            ->then
764
            ->variable($unitOfWork->getDirtyData(
765
                $newSerializedModel,
766
                [
767
                    '@id' => '/v12/carts/1',
768
                    'cartInfo' => [
769
                        [
770
                            'firstname' => 'john',
771
                            'lastname' => 'doe',
772
                            'children' => ['rusty', 'john-john-junior'],
773
                        ],
774
                    ],
775
                ],
776
                $this->getCartMetadata()
777
            ))
778
            ->isEqualTo(
779
                [
780
                    'cartInfo' => [
781
                        [
782
                            'firstname' => 'jane',
783
                            'lastname' => 'doe',
784
                            'children' => ['rusty', 'john-john-junior'],
785
                        ],
786
                    ],
787
                ]
788
            )
789
790
            ->then
791
            ->variable($unitOfWork->getDirtyData(
792
                [
793
                    '@id' => '/v12/carts/1',
794
                    'order' => [
795
                        '@id' => '/v12/orders/1',
796
                        'customerPaidAmount' => 1500,
797
                        'status' => 'awaiting_payment',
798
                    ],
799
                ],
800
                [
801
                    '@id' => '/v12/carts/1',
802
                    'order' => [
803
                        '@id' => '/v12/orders/1',
804
                        'customerPaidAmount' => 1000,
805
                        'status' => 'awaiting_payment',
806
                    ],
807
                ],
808
                $this->getCartMetadata()
809
            ))
810
            ->isEqualTo(
811
                [
812
                    'order' => [
813
                        '@id' => '/v12/orders/1',
814
                        'customerPaidAmount' => 1500,
815
                    ],
816
                ]
817
            )
818
819
        ;
820
    }
821
822
    private function getMapping()
823
    {
824
        $mapping = $mapping = new RestMapping();
825
        $mapping->setMapping([
826
            $this->getOrderMetadata(),
827
            $this->getCartMetadata(),
828
            $this->getCartItemMetadata(),
829
            $this->getCartItemDetailMetadata(),
830
        ]);
831
832
        return $mapping;
833
    }
834
835 View Code Duplication
    private function getOrderMetadata()
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...
836
    {
837
        $orderMetadata = new ClassMetadata(
838
            'orders',
839
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Order',
840
            ''
841
        );
842
843
        $orderMetadata->setAttributeList([
844
            new Attribute('@id', 'id', 'string', true),
845
            new Attribute('customerPaidAmount', 'customerPaidAmount', 'int'),
846
            new Attribute('status'),
847
        ]);
848
849
        $orderMetadata->setRelationList([
850
        ]);
851
852
        return $orderMetadata;
853
    }
854
855 View Code Duplication
    private function getCartMetadata()
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...
856
    {
857
        $cartMetadata = new ClassMetadata(
858
            'carts',
859
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
860
            ''
861
        );
862
863
        $cartMetadata->setAttributeList([
864
            new Attribute('@id', 'id', 'string', true),
865
            new Attribute('status'),
866
            new Attribute('clientPhoneNumber', 'clientPhoneNumber', 'phone_number'),
867
            new Attribute('createdAt', 'createdAt', 'datetime'),
868
            new Attribute('cart_items', 'cartItemList'),
869
            new Attribute('order'),
870
        ]);
871
872
        $cartMetadata->setRelationList([
873
            new Relation('cartItemList', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'),
874
            new Relation('order', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Order'),
875
        ]);
876
877
        return $cartMetadata;
878
    }
879
880 View Code Duplication
    private function getCartItemMetadata()
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...
881
    {
882
        $cartItemMetadata = new ClassMetadata(
883
            'cart_items',
884
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem',
885
            ''
886
        );
887
888
        $cartItemMetadata->setAttributeList([
889
            new Attribute('@id', 'id', 'string', true),
890
            new Attribute('amount'),
891
            new Attribute('cartItemDetailList'),
892
        ]);
893
894
        $cartItemMetadata->setRelationList([
895
            new Relation('cartItemDetailList', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail'),
896
        ]);
897
898
        return $cartItemMetadata;
899
    }
900
901 View Code Duplication
    private function getCartItemDetailMetadata()
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...
902
    {
903
        $cartItemDetailMetadata = new ClassMetadata(
904
            'cart_item_details',
905
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail',
906
            ''
907
        );
908
909
        $cartItemDetailMetadata->setAttributeList([
910
            new Attribute('@id', 'id', 'string', true),
911
            new Attribute('name'),
912
        ]);
913
914
        return $cartItemDetailMetadata;
915
    }
916
}
917