Completed
Push — v2 ( b8f0e3...507181 )
by Beñat
02:46
created

InboxItem::getAnswerId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * Copyright (c) 2014-2016 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
namespace BenatEspina\StackExchangeApiClient\Model;
13
14
/**
15
 * Class inbox item model class.
16
 *
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
class InboxItem implements Model
20
{
21
    const ITEM_TYPES = [
22
        'careers_invitations',
23
        'careers_message',
24
        'chat_message', 'comment',
25
        'meta_question',
26
        'moderator_message',
27
        'new_answer',
28
        'post_notice',
29
    ];
30
31
    protected $answerId;
32
    protected $body;
33
    protected $questionId;
34
    protected $commentId;
35
    protected $creationDate;
36
    protected $isUnread;
37
    protected $itemType;
38
    protected $link;
39
    protected $site;
40
    protected $title;
41
42
    public static function fromJson(array $data)
43
    {
44
        $instance = new self();
45
        $instance
46
            ->setAnswerId(array_key_exists('answer_id', $data) ? $data['answer_id'] : null)
47
            ->setBody(array_key_exists('body', $data) ? $data['body'] : null)
48
            ->setCommentId(array_key_exists('comment_id', $data) ? $data['comment_id'] : null)
49
            ->setCreationDate(array_key_exists('creation_date', $data)
50
                ? new \DateTimeImmutable('@' . $data['creation_date'])
51
                : null
52
            )
53
            ->setUnread(array_key_exists('is_unread', $data) ? $data['is_unread'] : null)
54
            ->setItemType(array_key_exists('item_type', $data) ? $data['item_type'] : null)
55
            ->setLink(array_key_exists('link', $data) ? $data['link'] : null)
56
            ->setQuestionId(array_key_exists('question_id', $data) ? $data['question_id'] : null)
57
            ->setSite(array_key_exists('site', $data) ? Site::fromJson($data['site']) : null)
0 ignored issues
show
Bug introduced by
It seems like array_key_exists('site',...n($data['site']) : null can also be of type object<BenatEspina\Stack...eApiClient\Model\Model>; however, BenatEspina\StackExchang...el\InboxItem::setSite() does only seem to accept null|object<BenatEspina\...geApiClient\Model\Site>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
58
            ->setTitle(array_key_exists('title', $data) ? $data['title'] : null);
59
60
        return $instance;
61
    }
62
63
    public static function fromProperties(
64
        $answerId,
65
        $commentId,
66
        \DateTimeInterface $creationDate,
67
        $isUnread,
68
        $itemType,
69
        $link,
70
        $questionId,
71
        Site $site,
72
        $title,
73
        $body = null
74
    ) {
75
        $instance = new self();
76
        $instance
77
            ->setAnswerId($answerId)
78
            ->setBody($body)
79
            ->setCommentId($commentId)
80
            ->setCreationDate($creationDate)
81
            ->setUnread($isUnread)
82
            ->setItemType($itemType)
83
            ->setLink($link)
84
            ->setQuestionId($questionId)
85
            ->setSite($site)
86
            ->setTitle($title);
87
88
        return $instance;
89
    }
90
91
    public function setAnswerId($answerId)
92
    {
93
        $this->answerId = $answerId;
94
95
        return $this;
96
    }
97
98
    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...
99
    {
100
        return $this->answerId;
101
    }
102
103
    public function setBody($body)
104
    {
105
        $this->body = $body;
106
107
        return $this;
108
    }
109
110
    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...
111
    {
112
        return $this->body;
113
    }
114
115
    public function setQuestionId($questionId)
116
    {
117
        $this->questionId = $questionId;
118
119
        return $this;
120
    }
121
122
    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...
123
    {
124
        return $this->questionId;
125
    }
126
127
    public function setCommentId($commentId)
128
    {
129
        $this->commentId = $commentId;
130
131
        return $this;
132
    }
133
134
    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...
135
    {
136
        return $this->commentId;
137
    }
138
139
    public function setCreationDate(\DateTimeInterface $creationDate = null)
140
    {
141
        $this->creationDate = $creationDate;
142
143
        return $this;
144
    }
145
146
    public function getCreationDate()
147
    {
148
        return $this->creationDate;
149
    }
150
151
    public function setUnread($isUnread)
152
    {
153
        $this->isUnread = $isUnread;
154
155
        return $this;
156
    }
157
158
    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...
159
    {
160
        return $this->isUnread;
161
    }
162
163
    public function setItemType($itemType)
164
    {
165
        if (in_array($itemType, self::ITEM_TYPES, true)) {
166
            $this->itemType = $itemType;
167
        }
168
169
        return $this;
170
    }
171
172
    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...
173
    {
174
        return $this->itemType;
175
    }
176
177
    public function setLink($link)
178
    {
179
        $this->link = $link;
180
181
        return $this;
182
    }
183
184
    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...
185
    {
186
        return $this->link;
187
    }
188
189
    public function setSite(Site $site = null)
190
    {
191
        $this->site = $site;
192
193
        return $this;
194
    }
195
196
    public function getSite()
197
    {
198
        return $this->site;
199
    }
200
201
    public function setTitle($title)
202
    {
203
        $this->title = $title;
204
205
        return $this;
206
    }
207
208
    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...
209
    {
210
        return $this->title;
211
    }
212
}
213