Passed
Push — master ( 9b3fb0...881b80 )
by Jérémy
02:18
created

WorkspaceSettingsDto::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 21
c 1
b 0
f 0
nc 1
nop 21
dl 0
loc 44
rs 9.584

How to fix   Many Parameters   

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 JDecool\Clockify\Model;
6
7
class WorkspaceSettingsDto
8
{
9
    private $adminOnlyPages;
10
    private $automaticLock;
11
    private $canSeeTimeSheet;
12
    private $defaultBillableProjects;
13
    private $forceDescription;
14
    private $forceProjects;
15
    private $forceTags;
16
    private $forceTasks;
17
    private $lockTimeEntries;
18
    private $onlyAdminsCreateProject;
19
    private $onlyAdminsCreateTag;
20
    private $onlyAdminsSeeAllTimeEntries;
21
    private $onlyAdminsSeeBillableRates;
22
    private $onlyAdminsSeeDashboard;
23
    private $onlyAdminsSeePublicProjectsEntries;
24
    private $projectFavorites;
25
    private $projectGroupingLabel;
26
    private $projectPickerSpecialFilter;
27
    private $round;
28
    private $timeRoundingInReports;
29
    private $trackTimeDownToSecond;
30
31
    public static function fromArray(array $data): self
32
    {
33
        return new self(
34
            array_map(
35
                static function(string $page): PagesEnum {
36
                    return new PagesEnum($page);
37
                },
38
                $data['adminOnlyPages']
39
            ),
40
            $data['automaticLock'] ? AutomaticLockDto::fromArray($data['automaticLock']) : null,
41
            $data['canSeeTimeSheet'],
42
            $data['defaultBillableProjects'],
43
            $data['forceDescription'],
44
            $data['forceProjects'],
45
            $data['forceTags'],
46
            $data['forceTasks'],
47
            $data['lockTimeEntries'],
48
            $data['onlyAdminsCreateProject'],
49
            $data['onlyAdminsCreateTag'],
50
            $data['onlyAdminsSeeAllTimeEntries'],
51
            $data['onlyAdminsSeeBillableRates'],
52
            $data['onlyAdminsSeeDashboard'],
53
            $data['onlyAdminsSeePublicProjectsEntries'],
54
            $data['projectFavorites'],
55
            $data['projectGroupingLabel'],
56
            $data['projectPickerSpecialFilter'],
57
            Round::fromArray($data['round']),
58
            $data['timeRoundingInReports'],
59
            $data['trackTimeDownToSecond']
60
        );
61
    }
62
63
    /**
64
     * @param PagesEnum[] $adminOnlyPages
65
     */
66
    public function __construct(
67
        array $adminOnlyPages,
68
        ?AutomaticLockDto $automaticLock,
69
        bool $canSeeTimeSheet,
70
        bool $defaultBillableProjects,
71
        bool $forceDescription,
72
        bool $forceProjects,
73
        bool $forceTags,
74
        bool $forceTasks,
75
        ?string $lockTimeEntries,
76
        bool $onlyAdminsCreateProject,
77
        bool $onlyAdminsCreateTag,
78
        bool $onlyAdminsSeeAllTimeEntries,
79
        bool $onlyAdminsSeeBillableRates,
80
        bool $onlyAdminsSeeDashboard,
81
        bool $onlyAdminsSeePublicProjectsEntries,
82
        bool $projectFavorites,
83
        string $projectGroupingLabel,
84
        bool $projectPickerSpecialFilter,
85
        Round $round,
86
        bool $timeRoundingInReports,
87
        bool $trackTimeDownToSecond
88
    ) {
89
        $this->adminOnlyPages = $adminOnlyPages;
90
        $this->automaticLock = $automaticLock;
91
        $this->canSeeTimeSheet = $canSeeTimeSheet;
92
        $this->defaultBillableProjects = $defaultBillableProjects;
93
        $this->forceDescription = $forceDescription;
94
        $this->forceProjects = $forceProjects;
95
        $this->forceTags = $forceTags;
96
        $this->forceTasks = $forceTasks;
97
        $this->lockTimeEntries = $lockTimeEntries;
98
        $this->onlyAdminsCreateProject = $onlyAdminsCreateProject;
99
        $this->onlyAdminsCreateTag = $onlyAdminsCreateTag;
100
        $this->onlyAdminsSeeAllTimeEntries = $onlyAdminsSeeAllTimeEntries;
101
        $this->onlyAdminsSeeBillableRates = $onlyAdminsSeeBillableRates;
102
        $this->onlyAdminsSeeDashboard = $onlyAdminsSeeDashboard;
103
        $this->onlyAdminsSeePublicProjectsEntries = $onlyAdminsSeePublicProjectsEntries;
104
        $this->projectFavorites = $projectFavorites;
105
        $this->projectGroupingLabel = $projectGroupingLabel;
106
        $this->projectPickerSpecialFilter = $projectPickerSpecialFilter;
107
        $this->round = $round;
108
        $this->timeRoundingInReports = $timeRoundingInReports;
109
        $this->trackTimeDownToSecond = $trackTimeDownToSecond;
110
    }
111
112
    /**
113
     * @return PagesEnum[]
114
     */
115
    public function adminOnlyPages(): array
116
    {
117
        return $this->adminOnlyPages;
118
    }
119
120
    public function automaticLock(): ?AutomaticLockDto
121
    {
122
        return $this->automaticLock;
123
    }
124
125
    public function canSeeTimeSheet(): bool
126
    {
127
        return $this->canSeeTimeSheet;
128
    }
129
130
    public function defaultBillableProjects(): bool
131
    {
132
        return $this->defaultBillableProjects;
133
    }
134
135
    public function forceDescription(): bool
136
    {
137
        return $this->forceDescription;
138
    }
139
140
    public function forceProjects(): bool
141
    {
142
        return $this->forceProjects;
143
    }
144
145
    public function forceTags(): bool
146
    {
147
        return $this->forceTags;
148
    }
149
150
    public function forceTasks(): bool
151
    {
152
        return $this->forceTasks;
153
    }
154
155
    public function lockTimeEntries(): ?string
156
    {
157
        return $this->lockTimeEntries;
158
    }
159
160
    public function onlyAdminsCreateProject(): bool
161
    {
162
        return $this->onlyAdminsCreateProject;
163
    }
164
165
    public function onlyAdminsCreateTag(): bool
166
    {
167
        return $this->onlyAdminsCreateTag;
168
    }
169
170
    public function onlyAdminsSeeAllTimeEntries(): bool
171
    {
172
        return $this->onlyAdminsSeeAllTimeEntries;
173
    }
174
175
    public function onlyAdminsSeeBillableRates(): bool
176
    {
177
        return $this->onlyAdminsSeeBillableRates;
178
    }
179
180
    public function onlyAdminsSeeDashboard(): bool
181
    {
182
        return $this->onlyAdminsSeeDashboard;
183
    }
184
185
    public function onlyAdminsSeePublicProjectsEntries(): bool
186
    {
187
        return $this->onlyAdminsSeePublicProjectsEntries;
188
    }
189
190
    public function projectFavorites(): bool
191
    {
192
        return $this->projectFavorites;
193
    }
194
195
    public function projectGroupingLabel(): string
196
    {
197
        return $this->projectGroupingLabel;
198
    }
199
200
    public function projectPickerSpecialFilter(): bool
201
    {
202
        return $this->projectPickerSpecialFilter;
203
    }
204
205
    public function round(): Round
206
    {
207
        return $this->round;
208
    }
209
210
    public function timeRoundingInReports(): bool
211
    {
212
        return $this->timeRoundingInReports;
213
    }
214
215
    public function trackTimeDownToSecond(): bool
216
    {
217
        return $this->trackTimeDownToSecond;
218
    }
219
}
220