Passed
Push — master ( db7b85...c86096 )
by Nico
49:13 queued 24:57
created

ShipRumpModuleLevel   F

Complexity

Total Complexity 85

Size/Duplication

Total Lines 641
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 220
dl 0
loc 641
ccs 0
cts 216
cp 0
rs 2
c 2
b 0
f 0
wmc 85

84 Methods

Rating   Name   Duplication   Size   Complexity  
A setModuleLevel1() 0 5 1
A getModuleLevel11Min() 0 3 1
A setModuleLevel4Min() 0 5 1
A getModuleLevel8Max() 0 3 1
A setRumpId() 0 5 1
A setModuleLevel8Max() 0 5 1
A setModuleLevel1Min() 0 5 1
A setModuleLevel10Min() 0 5 1
A getModuleLevel2Min() 0 3 1
A getModuleLevel10Max() 0 3 1
A setModuleLevel6() 0 5 1
A setModuleLevel5() 0 5 1
A getModuleLevel5Max() 0 3 1
A getModuleLevel5Min() 0 3 1
A setModuleMandatory6() 0 5 1
A getModuleMandatory4() 0 3 1
A getModuleLevel1() 0 3 1
A getModuleMandatory5() 0 3 1
A getModuleMandatory11() 0 3 1
A setModuleLevel4() 0 5 1
A setModuleLevel6Min() 0 5 1
A getModuleLevel11() 0 3 1
A getId() 0 3 1
A setModuleLevel7Max() 0 5 1
A setModuleMandatory5() 0 5 1
A getModuleLevel1Min() 0 3 1
A setModuleMandatory2() 0 5 1
A setModuleLevel1Max() 0 5 1
A getModuleLevel3() 0 3 1
A getModuleMandatory10() 0 3 1
A setModuleLevel4Max() 0 5 1
A getModuleLevel6() 0 3 1
A setModuleLevel3Max() 0 5 1
A setModuleLevel2() 0 5 1
A getModuleLevel6Max() 0 3 1
A setModuleMandatory10() 0 5 1
A setModuleLevel7Min() 0 5 1
A setModuleLevel10() 0 5 1
A setModuleLevel10Max() 0 5 1
A getModuleLevel2() 0 3 1
A setModuleLevel7() 0 5 1
A getModuleMandatory7() 0 3 1
A getModuleLevel11Max() 0 3 1
A getModuleLevel4() 0 3 1
A getRumpId() 0 3 1
A setModuleLevel3Min() 0 5 1
A setModuleLevel3() 0 5 1
A getModuleMandatory1() 0 3 1
A getModuleLevel7() 0 3 1
A getModuleLevel10() 0 3 1
A getModuleLevel8() 0 3 1
A setModuleLevel11Min() 0 5 1
A getModuleMandatory2() 0 3 1
A getModuleLevel8Min() 0 3 1
A getModuleMandatory8() 0 3 1
A getModuleLevel1Max() 0 3 1
A setModuleLevel11() 0 5 1
A setModuleLevel8() 0 5 1
A setModuleMandatory3() 0 5 1
A getModuleLevel5() 0 3 1
A setModuleLevel2Max() 0 5 1
A getModuleLevel7Max() 0 3 1
A getModuleLevel4Min() 0 3 1
A setModuleMandatory7() 0 5 1
A getModuleMandatory3() 0 3 1
A getModuleLevel3Max() 0 3 1
A setModuleMandatory4() 0 5 1
A getMandatoryModulesCount() 0 10 2
A setModuleLevel2Min() 0 5 1
A getModuleLevel7Min() 0 3 1
A getModuleMandatory6() 0 3 1
A getModuleLevel4Max() 0 3 1
A getModuleLevel3Min() 0 3 1
A getModuleLevel10Min() 0 3 1
A setModuleMandatory1() 0 5 1
A setModuleMandatory11() 0 5 1
A setModuleLevel5Max() 0 5 1
A setModuleMandatory8() 0 5 1
A setModuleLevel8Min() 0 5 1
A setModuleLevel11Max() 0 5 1
A setModuleLevel6Max() 0 5 1
A getModuleLevel6Min() 0 3 1
A setModuleLevel5Min() 0 5 1
A getModuleLevel2Max() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like ShipRumpModuleLevel often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ShipRumpModuleLevel, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\ORM\Mapping\Column;
8
use Doctrine\ORM\Mapping\Entity;
9
use Doctrine\ORM\Mapping\GeneratedValue;
10
use Doctrine\ORM\Mapping\Id;
11
use Doctrine\ORM\Mapping\Index;
12
use Doctrine\ORM\Mapping\Table;
13
use Stu\Component\Ship\ShipModuleTypeEnum;
14
15
#[Table(name: 'stu_rumps_module_level')]
16
#[Index(name: 'rump_module_level_ship_rump_idx', columns: ['rump_id'])]
17
#[Entity(repositoryClass: 'Stu\Orm\Repository\ShipRumpModuleLevelRepository')]
18
class ShipRumpModuleLevel implements ShipRumpModuleLevelInterface
19
{
20
    #[Id]
21
    #[Column(type: 'integer')]
22
    #[GeneratedValue(strategy: 'IDENTITY')]
23
    private int $id;
24
25
    #[Column(type: 'integer')]
26
    private int $rump_id = 0;
27
28
    #[Column(type: 'smallint')]
29
    private int $module_level_1 = 0;
30
31
    #[Column(type: 'smallint')]
32
    private int $module_mandatory_1 = 0;
33
34
    #[Column(type: 'smallint')]
35
    private int $module_level_1_min = 0;
36
37
    #[Column(type: 'smallint')]
38
    private int $module_level_1_max = 0;
39
40
    #[Column(type: 'smallint')]
41
    private int $module_level_2 = 0;
42
43
    #[Column(type: 'smallint')]
44
    private int $module_mandatory_2 = 0;
45
46
    #[Column(type: 'smallint')]
47
    private int $module_level_2_min = 0;
48
49
    #[Column(type: 'smallint')]
50
    private int $module_level_2_max = 0;
51
52
    #[Column(type: 'smallint')]
53
    private int $module_level_3 = 0;
54
55
    #[Column(type: 'smallint')]
56
    private int $module_mandatory_3 = 0;
57
58
    #[Column(type: 'smallint')]
59
    private int $module_level_3_min = 0;
60
61
    #[Column(type: 'smallint')]
62
    private int $module_level_3_max = 0;
63
64
    #[Column(type: 'smallint')]
65
    private int $module_level_4 = 0;
66
67
    #[Column(type: 'smallint')]
68
    private int $module_mandatory_4 = 0;
69
70
    #[Column(type: 'smallint')]
71
    private int $module_level_4_min = 0;
72
73
    #[Column(type: 'smallint')]
74
    private int $module_level_4_max = 0;
75
76
    #[Column(type: 'smallint')]
77
    private int $module_level_5 = 0;
78
79
    #[Column(type: 'smallint')]
80
    private int $module_mandatory_5 = 0;
81
82
    #[Column(type: 'smallint')]
83
    private int $module_level_5_min = 0;
84
85
    #[Column(type: 'smallint')]
86
    private int $module_level_5_max = 0;
87
88
    #[Column(type: 'smallint')]
89
    private int $module_level_6 = 0;
90
91
    #[Column(type: 'smallint')]
92
    private int $module_mandatory_6 = 0;
93
94
    #[Column(type: 'smallint')]
95
    private int $module_level_6_min = 0;
96
97
    #[Column(type: 'smallint')]
98
    private int $module_level_6_max = 0;
99
100
    #[Column(type: 'smallint')]
101
    private int $module_level_7 = 0;
102
103
    #[Column(type: 'smallint')]
104
    private int $module_mandatory_7 = 0;
105
106
    #[Column(type: 'smallint')]
107
    private int $module_level_7_min = 0;
108
109
    #[Column(type: 'smallint')]
110
    private int $module_level_7_max = 0;
111
112
    #[Column(type: 'smallint')]
113
    private int $module_level_8 = 0;
114
115
    #[Column(type: 'smallint')]
116
    private int $module_mandatory_8 = 0;
117
118
    #[Column(type: 'smallint')]
119
    private int $module_level_8_min = 0;
120
121
    #[Column(type: 'smallint')]
122
    private int $module_level_8_max = 0;
123
124
    #[Column(type: 'smallint')]
125
    private int $module_level_10 = 0;
126
127
    #[Column(type: 'smallint')]
128
    private int $module_mandatory_10 = 0;
129
130
    #[Column(type: 'smallint')]
131
    private int $module_level_10_min = 0;
132
133
    #[Column(type: 'smallint')]
134
    private int $module_level_10_max = 0;
135
136
    #[Column(type: 'smallint')]
137
    private int $module_level_11 = 0;
138
139
    #[Column(type: 'smallint')]
140
    private int $module_mandatory_11 = 0;
141
142
    #[Column(type: 'smallint')]
143
    private int $module_level_11_min = 0;
144
145
    #[Column(type: 'smallint')]
146
    private int $module_level_11_max = 0;
147
148
    public function getId(): int
149
    {
150
        return $this->id;
151
    }
152
153
    public function getRumpId(): int
154
    {
155
        return $this->rump_id;
156
    }
157
158
    public function setRumpId(int $shipRumpId): ShipRumpModuleLevelInterface
159
    {
160
        $this->rump_id = $shipRumpId;
161
162
        return $this;
163
    }
164
165
    public function getModuleLevel1(): int
166
    {
167
        return $this->module_level_1;
168
    }
169
170
    public function setModuleLevel1(int $moduleLevel1): ShipRumpModuleLevelInterface
171
    {
172
        $this->module_level_1 = $moduleLevel1;
173
174
        return $this;
175
    }
176
177
    public function getModuleMandatory1(): bool
178
    {
179
        return $this->module_mandatory_1 === self::MODULE_MANDATORY;
180
    }
181
182
    public function setModuleMandatory1(int $moduleMandatory1): ShipRumpModuleLevelInterface
183
    {
184
        $this->module_mandatory_1 = $moduleMandatory1;
185
186
        return $this;
187
    }
188
189
    public function getModuleLevel1Min(): int
190
    {
191
        return $this->module_level_1_min;
192
    }
193
194
    public function setModuleLevel1Min(int $moduleLevel1Min): ShipRumpModuleLevelInterface
195
    {
196
        $this->module_level_1_min = $moduleLevel1Min;
197
198
        return $this;
199
    }
200
201
    public function getModuleLevel1Max(): int
202
    {
203
        return $this->module_level_1_max;
204
    }
205
206
    public function setModuleLevel1Max(int $moduleLevel1Max): ShipRumpModuleLevelInterface
207
    {
208
        $this->module_level_1_max = $moduleLevel1Max;
209
210
        return $this;
211
    }
212
213
    public function getModuleLevel2(): int
214
    {
215
        return $this->module_level_2;
216
    }
217
218
    public function setModuleLevel2(int $moduleLevel2): ShipRumpModuleLevelInterface
219
    {
220
        $this->module_level_2 = $moduleLevel2;
221
222
        return $this;
223
    }
224
225
    public function getModuleMandatory2(): bool
226
    {
227
        return $this->module_mandatory_2 === self::MODULE_MANDATORY;
228
    }
229
230
    public function setModuleMandatory2(int $moduleMandatory2): ShipRumpModuleLevelInterface
231
    {
232
        $this->module_mandatory_2 = $moduleMandatory2;
233
234
        return $this;
235
    }
236
237
    public function getModuleLevel2Min(): int
238
    {
239
        return $this->module_level_2_min;
240
    }
241
242
    public function setModuleLevel2Min(int $moduleLevel2Min): ShipRumpModuleLevelInterface
243
    {
244
        $this->module_level_2_min = $moduleLevel2Min;
245
246
        return $this;
247
    }
248
249
    public function getModuleLevel2Max(): int
250
    {
251
        return $this->module_level_2_max;
252
    }
253
254
    public function setModuleLevel2Max(int $moduleLevel2Max): ShipRumpModuleLevelInterface
255
    {
256
        $this->module_level_2_max = $moduleLevel2Max;
257
258
        return $this;
259
    }
260
261
    public function getModuleLevel3(): int
262
    {
263
        return $this->module_level_3;
264
    }
265
266
    public function setModuleLevel3(int $moduleLevel3): ShipRumpModuleLevelInterface
267
    {
268
        $this->module_level_3 = $moduleLevel3;
269
270
        return $this;
271
    }
272
273
    public function getModuleMandatory3(): bool
274
    {
275
        return $this->module_mandatory_3 === self::MODULE_MANDATORY;
276
    }
277
278
    public function setModuleMandatory3(int $moduleMandatory3): ShipRumpModuleLevelInterface
279
    {
280
        $this->module_mandatory_3 = $moduleMandatory3;
281
282
        return $this;
283
    }
284
285
    public function getModuleLevel3Min(): int
286
    {
287
        return $this->module_level_3_min;
288
    }
289
290
    public function setModuleLevel3Min(int $moduleLevel3Min): ShipRumpModuleLevelInterface
291
    {
292
        $this->module_level_3_min = $moduleLevel3Min;
293
294
        return $this;
295
    }
296
297
    public function getModuleLevel3Max(): int
298
    {
299
        return $this->module_level_3_max;
300
    }
301
302
    public function setModuleLevel3Max(int $moduleLevel3Max): ShipRumpModuleLevelInterface
303
    {
304
        $this->module_level_3_max = $moduleLevel3Max;
305
306
        return $this;
307
    }
308
309
    public function getModuleLevel4(): int
310
    {
311
        return $this->module_level_4;
312
    }
313
314
    public function setModuleLevel4(int $moduleLevel4): ShipRumpModuleLevelInterface
315
    {
316
        $this->module_level_4 = $moduleLevel4;
317
318
        return $this;
319
    }
320
321
    public function getModuleMandatory4(): bool
322
    {
323
        return $this->module_mandatory_4 === self::MODULE_MANDATORY;
324
    }
325
326
    public function setModuleMandatory4(int $moduleMandatory4): ShipRumpModuleLevelInterface
327
    {
328
        $this->module_mandatory_4 = $moduleMandatory4;
329
330
        return $this;
331
    }
332
333
    public function getModuleLevel4Min(): int
334
    {
335
        return $this->module_level_4_min;
336
    }
337
338
    public function setModuleLevel4Min(int $moduleLevel4Min): ShipRumpModuleLevelInterface
339
    {
340
        $this->module_level_4_min = $moduleLevel4Min;
341
342
        return $this;
343
    }
344
345
    public function getModuleLevel4Max(): int
346
    {
347
        return $this->module_level_4_max;
348
    }
349
350
    public function setModuleLevel4Max(int $moduleLevel4Max): ShipRumpModuleLevelInterface
351
    {
352
        $this->module_level_4_max = $moduleLevel4Max;
353
354
        return $this;
355
    }
356
357
    public function getModuleLevel5(): int
358
    {
359
        return $this->module_level_5;
360
    }
361
362
    public function setModuleLevel5(int $moduleLevel5): ShipRumpModuleLevelInterface
363
    {
364
        $this->module_level_5 = $moduleLevel5;
365
366
        return $this;
367
    }
368
369
    public function getModuleMandatory5(): bool
370
    {
371
        return $this->module_mandatory_5 === self::MODULE_MANDATORY;
372
    }
373
374
    public function setModuleMandatory5(int $moduleMandatory5): ShipRumpModuleLevelInterface
375
    {
376
        $this->module_mandatory_5 = $moduleMandatory5;
377
378
        return $this;
379
    }
380
381
    public function getModuleLevel5Min(): int
382
    {
383
        return $this->module_level_5_min;
384
    }
385
386
    public function setModuleLevel5Min(int $moduleLevel5Min): ShipRumpModuleLevelInterface
387
    {
388
        $this->module_level_5_min = $moduleLevel5Min;
389
390
        return $this;
391
    }
392
393
    public function getModuleLevel5Max(): int
394
    {
395
        return $this->module_level_5_max;
396
    }
397
398
    public function setModuleLevel5Max(int $moduleLevel5Max): ShipRumpModuleLevelInterface
399
    {
400
        $this->module_level_5_max = $moduleLevel5Max;
401
402
        return $this;
403
    }
404
405
    public function getModuleLevel6(): int
406
    {
407
        return $this->module_level_6;
408
    }
409
410
    public function setModuleLevel6(int $moduleLevel6): ShipRumpModuleLevelInterface
411
    {
412
        $this->module_level_6 = $moduleLevel6;
413
414
        return $this;
415
    }
416
417
    public function getModuleMandatory6(): bool
418
    {
419
        return $this->module_mandatory_6 === self::MODULE_MANDATORY;
420
    }
421
422
    public function setModuleMandatory6(int $moduleMandatory6): ShipRumpModuleLevelInterface
423
    {
424
        $this->module_mandatory_6 = $moduleMandatory6;
425
426
        return $this;
427
    }
428
429
    public function getModuleLevel6Min(): int
430
    {
431
        return $this->module_level_6_min;
432
    }
433
434
    public function setModuleLevel6Min(int $moduleLevel6Min): ShipRumpModuleLevelInterface
435
    {
436
        $this->module_level_6_min = $moduleLevel6Min;
437
438
        return $this;
439
    }
440
441
    public function getModuleLevel6Max(): int
442
    {
443
        return $this->module_level_6_max;
444
    }
445
446
    public function setModuleLevel6Max(int $moduleLevel6Max): ShipRumpModuleLevelInterface
447
    {
448
        $this->module_level_6_max = $moduleLevel6Max;
449
450
        return $this;
451
    }
452
453
    public function getModuleLevel7(): int
454
    {
455
        return $this->module_level_7;
456
    }
457
458
    public function setModuleLevel7(int $moduleLevel7): ShipRumpModuleLevelInterface
459
    {
460
        $this->module_level_7 = $moduleLevel7;
461
462
        return $this;
463
    }
464
465
    public function getModuleMandatory7(): bool
466
    {
467
        return $this->module_mandatory_7 === self::MODULE_MANDATORY;
468
    }
469
470
    public function setModuleMandatory7(int $moduleMandatory7): ShipRumpModuleLevelInterface
471
    {
472
        $this->module_mandatory_7 = $moduleMandatory7;
473
474
        return $this;
475
    }
476
477
    public function getModuleLevel7Min(): int
478
    {
479
        return $this->module_level_7_min;
480
    }
481
482
    public function setModuleLevel7Min(int $moduleLevel7Min): ShipRumpModuleLevelInterface
483
    {
484
        $this->module_level_7_min = $moduleLevel7Min;
485
486
        return $this;
487
    }
488
489
    public function getModuleLevel7Max(): int
490
    {
491
        return $this->module_level_7_max;
492
    }
493
494
    public function setModuleLevel7Max(int $moduleLevel7Max): ShipRumpModuleLevelInterface
495
    {
496
        $this->module_level_7_max = $moduleLevel7Max;
497
498
        return $this;
499
    }
500
501
    public function getModuleLevel8(): int
502
    {
503
        return $this->module_level_8;
504
    }
505
506
    public function setModuleLevel8(int $moduleLevel8): ShipRumpModuleLevelInterface
507
    {
508
        $this->module_level_8 = $moduleLevel8;
509
510
        return $this;
511
    }
512
513
    public function getModuleMandatory8(): bool
514
    {
515
        return $this->module_mandatory_8 === self::MODULE_MANDATORY;
516
    }
517
518
    public function setModuleMandatory8(int $moduleMandatory8): ShipRumpModuleLevelInterface
519
    {
520
        $this->module_mandatory_8 = $moduleMandatory8;
521
522
        return $this;
523
    }
524
525
    public function getModuleLevel8Min(): int
526
    {
527
        return $this->module_level_8_min;
528
    }
529
530
    public function setModuleLevel8Min(int $moduleLevel8Min): ShipRumpModuleLevelInterface
531
    {
532
        $this->module_level_8_min = $moduleLevel8Min;
533
534
        return $this;
535
    }
536
537
    public function getModuleLevel8Max(): int
538
    {
539
        return $this->module_level_8_max;
540
    }
541
542
    public function setModuleLevel8Max(int $moduleLevel8Max): ShipRumpModuleLevelInterface
543
    {
544
        $this->module_level_8_max = $moduleLevel8Max;
545
546
        return $this;
547
    }
548
549
    public function getModuleLevel10(): int
550
    {
551
        return $this->module_level_10;
552
    }
553
554
    public function setModuleLevel10(int $moduleLevel10): ShipRumpModuleLevelInterface
555
    {
556
        $this->module_level_10 = $moduleLevel10;
557
558
        return $this;
559
    }
560
561
    public function getModuleMandatory10(): bool
562
    {
563
        return $this->module_mandatory_10 === self::MODULE_MANDATORY;
564
    }
565
566
    public function setModuleMandatory10(int $moduleMandatory10): ShipRumpModuleLevelInterface
567
    {
568
        $this->module_mandatory_10 = $moduleMandatory10;
569
570
        return $this;
571
    }
572
573
    public function getModuleLevel10Min(): int
574
    {
575
        return $this->module_level_10_min;
576
    }
577
578
    public function setModuleLevel10Min(int $moduleLevel10Min): ShipRumpModuleLevelInterface
579
    {
580
        $this->module_level_10_min = $moduleLevel10Min;
581
582
        return $this;
583
    }
584
585
    public function getModuleLevel10Max(): int
586
    {
587
        return $this->module_level_10_max;
588
    }
589
590
    public function setModuleLevel10Max(int $moduleLevel10Max): ShipRumpModuleLevelInterface
591
    {
592
        $this->module_level_10_max = $moduleLevel10Max;
593
594
        return $this;
595
    }
596
597
    public function getModuleLevel11(): int
598
    {
599
        return $this->module_level_11;
600
    }
601
602
    public function setModuleLevel11(int $moduleLevel11): ShipRumpModuleLevelInterface
603
    {
604
        $this->module_level_11 = $moduleLevel11;
605
606
        return $this;
607
    }
608
609
    public function getModuleMandatory11(): bool
610
    {
611
        return $this->module_mandatory_11 === self::MODULE_MANDATORY;
612
    }
613
614
    public function setModuleMandatory11(int $moduleMandatory11): ShipRumpModuleLevelInterface
615
    {
616
        $this->module_mandatory_11 = $moduleMandatory11;
617
618
        return $this;
619
    }
620
621
    public function getModuleLevel11Min(): int
622
    {
623
        return $this->module_level_11_min;
624
    }
625
626
    public function setModuleLevel11Min(int $moduleLevel11Min): ShipRumpModuleLevelInterface
627
    {
628
        $this->module_level_11_min = $moduleLevel11Min;
629
630
        return $this;
631
    }
632
633
    public function getModuleLevel11Max(): int
634
    {
635
        return $this->module_level_11_max;
636
    }
637
638
    public function setModuleLevel11Max(int $moduleLevel11Max): ShipRumpModuleLevelInterface
639
    {
640
        $this->module_level_11_max = $moduleLevel11Max;
641
642
        return $this;
643
    }
644
645
646
    public function getMandatoryModulesCount(): int
647
    {
648
        return array_reduce(
649
            array_map(
650
                fn (ShipModuleTypeEnum $type) =>
651
                sprintf('getModuleMandatory%d', $type->value),
652
                array_filter(ShipModuleTypeEnum::cases(), fn (ShipModuleTypeEnum $type) => !$type->isSpecialSystemType())
653
            ),
654
            fn (int $value, string $method) => $value + $this->$method() ? 1 : 0,
655
            0
656
        );
657
    }
658
}
659