Passed
Pull Request — master (#1)
by Jérémy
02:11
created

TimeEntryRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 26
rs 9.8666
cc 1
nc 1
nop 12

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\Api\TimeEntry;
6
7
class TimeEntryRequest
8
{
9
    private $id;
10
    private $start;
11
    private $billable;
12
    private $description;
13
    private $projectId;
14
    private $userId;
15
    private $taskId;
16
    private $end;
17
    private $tagIds;
18
    private $timeInterval;
19
    private $workspaceId;
20
    private $isLocked;
21
22
    /**
23
     * @param string[] $tagIds
24
     */
25
    public function __construct(
26
        string $id,
27
        string $start,
28
        bool $billable,
29
        string $description,
30
        string $projectId,
31
        string $userId,
32
        string $taskId,
33
        string $end,
34
        array $tagIds,
35
        TimeEntriesDurationRequest $timeInterval,
36
        string $workspaceId,
37
        bool $isLocked
38
    ) {
39
        $this->id = $id;
40
        $this->start = $start;
41
        $this->billable = $billable;
42
        $this->description = $description;
43
        $this->projectId = $projectId;
44
        $this->userId = $userId;
45
        $this->taskId = $taskId;
46
        $this->end = $end;
47
        $this->tagIds = $tagIds;
48
        $this->timeInterval = $timeInterval;
49
        $this->workspaceId = $workspaceId;
50
        $this->isLocked = $isLocked;
51
    }
52
53
    public function id(): string
54
    {
55
        return $this->id;
56
    }
57
58
    public function start(): string
59
    {
60
        return $this->start;
61
    }
62
63
    public function billable(): bool
64
    {
65
        return $this->billable;
66
    }
67
68
    public function description(): string
69
    {
70
        return $this->description;
71
    }
72
73
    public function projectId(): string
74
    {
75
        return $this->projectId;
76
    }
77
78
    public function userId(): string
79
    {
80
        return $this->userId;
81
    }
82
83
    public function taskId(): string
84
    {
85
        return $this->taskId;
86
    }
87
88
    public function end(): string
89
    {
90
        return $this->end;
91
    }
92
93
    /**
94
     * @return string[]
95
     */
96
    public function tagIds(): array
97
    {
98
        return $this->tagIds;
99
    }
100
101
    public function timeInterval(): TimeEntriesDurationRequest
102
    {
103
        return $this->timeInterval;
104
    }
105
106
    public function workspaceId(): string
107
    {
108
        return $this->workspaceId;
109
    }
110
111
    public function isLocked(): bool
112
    {
113
        return $this->isLocked;
114
    }
115
116
    public function toArray(): array
117
    {
118
        return [
119
            'id' => $this->id,
120
            'start' => $this->start,
121
            'billable' => $this->billable,
122
            'description' => $this->description,
123
            'projectId' => $this->projectId,
124
            'userId' => $this->userId,
125
            'taskId' => $this->taskId,
126
            'end' => $this->end,
127
            'tagIds' => $this->tagIds,
128
            'timeInterval' => $this->timeInterval->toArray(),
129
            'workspaceId' => $this->workspaceId,
130
            'isLocked' => $this->isLocked,
131
        ];
132
    }
133
}
134