InboxItem   A
last analyzed

Complexity

Total Complexity 33

Size/Duplication

Total Lines 194
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 33
lcom 1
cbo 1
dl 0
loc 194
rs 9.3999
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
B fromJson() 0 20 11
B fromProperties() 0 27 1
A setAnswerId() 0 6 1
A getAnswerId() 0 4 1
A setBody() 0 6 1
A getBody() 0 4 1
A setQuestionId() 0 6 1
A getQuestionId() 0 4 1
A setCommentId() 0 6 1
A getCommentId() 0 4 1
A setCreationDate() 0 6 1
A getCreationDate() 0 4 1
A setUnread() 0 6 1
A isUnread() 0 4 1
A setItemType() 0 8 2
A getItemType() 0 4 1
A setLink() 0 6 1
A getLink() 0 4 1
A setSite() 0 6 1
A getSite() 0 4 1
A setTitle() 0 6 1
A getTitle() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
/*
14
 * This file is part of the Stack Exchange Api Client library.
15
 *
16
 * (c) Beñat Espiña <[email protected]>
17
 *
18
 * For the full copyright and license information, please view the LICENSE
19
 * file that was distributed with this source code.
20
 */
21
22
namespace BenatEspina\StackExchangeApiClient\Model;
23
24
/**
25
 * Class inbox item model class.
26
 *
27
 * @author Beñat Espiña <[email protected]>
28
 */
29
class InboxItem implements Model
30
{
31
    const ITEM_TYPES = [
32
        'careers_invitations',
33
        'careers_message',
34
        'chat_message', 'comment',
35
        'meta_question',
36
        'moderator_message',
37
        'new_answer',
38
        'post_notice',
39
    ];
40
41
    protected $answerId;
42
    protected $body;
43
    protected $questionId;
44
    protected $commentId;
45
    protected $creationDate;
46
    protected $isUnread;
47
    protected $itemType;
48
    protected $link;
49
    protected $site;
50
    protected $title;
51
52
    public static function fromJson(array $data)
53
    {
54
        $instance = new self();
55
        $instance
56
            ->setAnswerId(array_key_exists('answer_id', $data) ? $data['answer_id'] : null)
57
            ->setBody(array_key_exists('body', $data) ? $data['body'] : null)
58
            ->setCommentId(array_key_exists('comment_id', $data) ? $data['comment_id'] : null)
59
            ->setCreationDate(array_key_exists('creation_date', $data)
60
                ? new \DateTimeImmutable('@' . $data['creation_date'])
61
                : null
62
            )
63
            ->setUnread(array_key_exists('is_unread', $data) ? $data['is_unread'] : null)
64
            ->setItemType(array_key_exists('item_type', $data) ? $data['item_type'] : null)
65
            ->setLink(array_key_exists('link', $data) ? $data['link'] : null)
66
            ->setQuestionId(array_key_exists('question_id', $data) ? $data['question_id'] : null)
67
            ->setSite(array_key_exists('site', $data) ? Site::fromJson($data['site']) : null)
68
            ->setTitle(array_key_exists('title', $data) ? $data['title'] : null);
69
70
        return $instance;
71
    }
72
73
    public static function fromProperties(
74
        $answerId,
75
        $commentId,
76
        \DateTimeInterface $creationDate,
77
        $isUnread,
78
        $itemType,
79
        $link,
80
        $questionId,
81
        Site $site,
82
        $title,
83
        $body = null
84
    ) {
85
        $instance = new self();
86
        $instance
87
            ->setAnswerId($answerId)
88
            ->setBody($body)
89
            ->setCommentId($commentId)
90
            ->setCreationDate($creationDate)
91
            ->setUnread($isUnread)
92
            ->setItemType($itemType)
93
            ->setLink($link)
94
            ->setQuestionId($questionId)
95
            ->setSite($site)
96
            ->setTitle($title);
97
98
        return $instance;
99
    }
100
101
    public function setAnswerId($answerId)
102
    {
103
        $this->answerId = $answerId;
104
105
        return $this;
106
    }
107
108
    public function getAnswerId()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
109
    {
110
        return $this->answerId;
111
    }
112
113
    public function setBody($body)
114
    {
115
        $this->body = $body;
116
117
        return $this;
118
    }
119
120
    public function getBody()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
121
    {
122
        return $this->body;
123
    }
124
125
    public function setQuestionId($questionId)
126
    {
127
        $this->questionId = $questionId;
128
129
        return $this;
130
    }
131
132
    public function getQuestionId()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
133
    {
134
        return $this->questionId;
135
    }
136
137
    public function setCommentId($commentId)
138
    {
139
        $this->commentId = $commentId;
140
141
        return $this;
142
    }
143
144
    public function getCommentId()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
145
    {
146
        return $this->commentId;
147
    }
148
149
    public function setCreationDate(\DateTimeInterface $creationDate = null)
150
    {
151
        $this->creationDate = $creationDate;
152
153
        return $this;
154
    }
155
156
    public function getCreationDate()
157
    {
158
        return $this->creationDate;
159
    }
160
161
    public function setUnread($isUnread)
162
    {
163
        $this->isUnread = $isUnread;
164
165
        return $this;
166
    }
167
168
    public function isUnread()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
169
    {
170
        return $this->isUnread;
171
    }
172
173
    public function setItemType($itemType)
174
    {
175
        if (in_array($itemType, self::ITEM_TYPES, true)) {
176
            $this->itemType = $itemType;
177
        }
178
179
        return $this;
180
    }
181
182
    public function getItemType()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
183
    {
184
        return $this->itemType;
185
    }
186
187
    public function setLink($link)
188
    {
189
        $this->link = $link;
190
191
        return $this;
192
    }
193
194
    public function getLink()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
195
    {
196
        return $this->link;
197
    }
198
199
    public function setSite(Site $site = null)
200
    {
201
        $this->site = $site;
202
203
        return $this;
204
    }
205
206
    public function getSite()
207
    {
208
        return $this->site;
209
    }
210
211
    public function setTitle($title)
212
    {
213
        $this->title = $title;
214
215
        return $this;
216
    }
217
218
    public function getTitle()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
219
    {
220
        return $this->title;
221
    }
222
}
223