Completed
Push — master ( e20f04...ac8bb1 )
by Daniel
02:05
created

MergeRequest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 206
Duplicated Lines 0 %

Test Coverage

Coverage 80.77%

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 206
ccs 42
cts 52
cp 0.8077
rs 10
c 0
b 0
f 0
wmc 16

16 Methods

Rating   Name   Duplication   Size   Complexity  
A getIid() 0 3 1
A isClosed() 0 3 1
A isOpened() 0 3 1
A getId() 0 3 1
A isMerged() 0 3 1
A getProject() 0 3 1
A __construct() 0 22 1
A fromArray() 0 13 1
A getState() 0 3 1
A isLocked() 0 3 1
A getTitle() 0 3 1
A getDescription() 0 3 1
A getAuthor() 0 3 1
A getWebUrl() 0 3 1
A isWorkInProgress() 0 3 1
A getAssignee() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace DanielPieper\MergeReminder\ValueObject;
4
5
class MergeRequest
6
{
7
    public const STATE_OPENED = 'opened';
8
    public const STATE_CLOSED = 'closed';
9
    public const STATE_LOCKED = 'locked';
10
    public const STATE_MERGED = 'merged';
11
12
    /** @var int */
13
    private $id;
14
15
    /** @var int */
16
    private $iid;
17
18
    /** @var string */
19
    private $title;
20
21
    /** @var string */
22
    private $description;
23
24
    /** @var string */
25
    private $state;
26
27
    /** @var string */
28
    private $webUrl;
29
30
    /** @var bool */
31
    private $isWorkInProgress;
32
33
    /** @var Project */
34
    private $project;
35
36
    /** @var User */
37
    private $author;
38
39
    /** @var User */
40
    private $assignee;
41
42
    /**
43
     * Project constructor.
44
     * @param int $id
45
     * @param int $iid
46
     * @param string $title
47
     * @param string $description
48
     * @param string $state
49
     * @param string $webUrl
50
     * @param bool $isWorkInProgress
51
     * @param Project $project
52
     * @param User $author
53
     * @param User $assignee
54
     *
55
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
56
     */
57 33
    public function __construct(
58
        int $id,
59
        int $iid,
60
        string $title,
61
        string $description,
62
        string $state,
63
        string $webUrl,
64
        bool $isWorkInProgress,
65
        Project $project,
66
        User $author,
67
        ?User $assignee = null
68
    ) {
69 33
        $this->id = $id;
70 33
        $this->iid = $iid;
71 33
        $this->title = $title;
72 33
        $this->description = $description;
73 33
        $this->state = $state;
74 33
        $this->webUrl = $webUrl;
75 33
        $this->isWorkInProgress = $isWorkInProgress;
76 33
        $this->project = $project;
77 33
        $this->author = $author;
78 33
        $this->assignee = $assignee;
79 33
    }
80
81
    /**
82
     * @param array $mergeRequest
83
     * @return MergeRequest
84
     */
85 33
    public static function fromArray(array $mergeRequest): self
86
    {
87 33
        return new self(
88 33
            (int)$mergeRequest['id'],
89 33
            (int)$mergeRequest['iid'],
90 33
            (string)$mergeRequest['title'],
91 33
            (string)$mergeRequest['description'],
92 33
            (string)$mergeRequest['state'],
93 33
            (string)$mergeRequest['web_url'],
94 33
            (bool)$mergeRequest['work_in_progress'],
95 33
            $mergeRequest['project'],
96 33
            $mergeRequest['author'],
97 33
            $mergeRequest['assignee']
98
        );
99
    }
100
101
    /**
102
     * @return int
103
     */
104 5
    public function getIid(): int
105
    {
106 5
        return $this->iid;
107
    }
108
109
    /**
110
     * @return int
111
     */
112 1
    public function getId(): int
113
    {
114 1
        return $this->id;
115
    }
116
117
    /**
118
     * @return string
119
     */
120 2
    public function getTitle(): string
121
    {
122 2
        return $this->title;
123
    }
124
125
    /**
126
     * @return string
127
     */
128 2
    public function getDescription(): string
129
    {
130 2
        return $this->description;
131
    }
132
133
    /**
134
     * @return string
135
     */
136
    public function getState(): string
137
    {
138
        return $this->state;
139
    }
140
141
    /**
142
     * @return bool
143
     */
144
    public function isOpened(): bool
145
    {
146
        return $this->state === self::STATE_OPENED;
147
    }
148
149
    /**
150
     * @return bool
151
     */
152
    public function isClosed(): bool
153
    {
154
        return $this->state === self::STATE_CLOSED;
155
    }
156
157
    /**
158
     * @return bool
159
     */
160
    public function isLocked(): bool
161
    {
162
        return $this->state === self::STATE_LOCKED;
163
    }
164
165
    /**
166
     * @return bool
167
     */
168
    public function isMerged(): bool
169
    {
170
        return $this->state === self::STATE_MERGED;
171
    }
172
173
    /**
174
     * @return string
175
     */
176 2
    public function getWebUrl(): string
177
    {
178 2
        return $this->webUrl;
179
    }
180
181
    /**
182
     * @return Project
183
     */
184 8
    public function getProject(): Project
185
    {
186 8
        return $this->project;
187
    }
188
189
    /**
190
     * @return User
191
     */
192 2
    public function getAuthor(): User
193
    {
194 2
        return $this->author;
195
    }
196
197
    /**
198
     * @return User|null
199
     */
200 2
    public function getAssignee(): ?User
201
    {
202 2
        return $this->assignee;
203
    }
204
205
    /**
206
     * @return bool
207
     */
208 5
    public function isWorkInProgress(): bool
209
    {
210 5
        return $this->isWorkInProgress;
211
    }
212
}
213