Situation::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 53
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 33
crap 1

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Swis\Melvin\Models;
6
7
use GeoJson\Geometry\Geometry;
8
use Swis\Melvin\Enums\ActivityType;
9
use Swis\Melvin\Enums\Delay;
10
use Swis\Melvin\Enums\EventType;
11
use Swis\Melvin\Enums\Impact;
12
use Swis\Melvin\Enums\SituationStatus;
13
use Swis\Melvin\Enums\Source;
14
use Swis\Melvin\Enums\WorkObject;
15
use Swis\Melvin\Enums\WorkType;
16
17
class Situation
18
{
19 6
    public function __construct(
20
        public string $id,
21
        public bool $external,
22
        public Geometry $geometry,
23
        public string $name,
24
        public ?ActivityType $activityType,
25
        public ?WorkObject $workObject,
26
        public ?Impact $impact,
27
        public ?string $impactDescription,
28
        public bool $project,
29
        public Source $source,
30
        public bool $published,
31
        public ?string $url,
32
        public ?string $urlDescription,
33
        public Delay $delay,
34
        public ?WorkType $workType,
35
        public ?EventType $eventType,
36
        public ?string $eventName,
37
        public ?string $addition,
38
        public SituationStatus $status,
39
        public ?RoadAuthority $roadAuthority,
40
        public Location $location,
41
        /**
42
         * @var \Swis\Melvin\Models\Period[]
43
         */
44
        public array $periods,
45
        public ?\DateTime $createdAt,
46
        public ?Person $createdBy,
47
        public ?\DateTime $lastChangedAt,
48
        public ?Person $lastChangedBy,
49
        /**
50
         * @var \Swis\Melvin\Models\Attachment[]
51
         */
52
        public array $attachments,
53
        /**
54
         * @var \Swis\Melvin\Models\Restriction[]
55
         */
56
        public array $restrictions,
57
        /**
58
         * @var \Swis\Melvin\Models\Detour[]
59
         */
60
        public array $detours,
61
        public ?string $permitId,
62
        public ?string $referenceId,
63
        /**
64
         * @var string[]
65
         */
66
        public array $remarks,
67
        /**
68
         * @var \Swis\Melvin\Models\Contact[]
69
         */
70
        public array $contacts
71
    ) {
72 6
    }
73
}
74