Completed
Push — v2 ( 507181...9b4b78 )
by Beñat
02:57
created

NetworkActivity::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
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 network activity model class.
16
 *
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
class NetworkActivity implements Model
20
{
21
    const ACTIVITY_TYPES = [
22
        'answer_posted',
23
        'badge_earned',
24
        'comment_posted',
25
        'question_posted',
26
    ];
27
28
    protected $accountId;
29
    protected $activityType;
30
    protected $apiSiteParameter;
31
    protected $badgeId;
32
    protected $description;
33
    protected $link;
34
    protected $postId;
35
    protected $score;
36
    protected $creationDate;
37
    protected $tags;
38
    protected $title;
39
40
    public static function fromJson(array $data)
41
    {
42
        $tags = [];
43 View Code Duplication
        if (array_key_exists('tags', $data) && is_array($data['tags'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
            foreach ($data['tags'] as $tag) {
45
                $tags[] = Tag::fromJson($tag);
46
            }
47
        }
48
49
        $instance = new self();
50
        $instance
51
            ->setAccountId(array_key_exists('account_id', $data) ? $data['account_id'] : null)
52
            ->setActivityType(array_key_exists('activity_type', $data) ? $data['activity_type'] : null)
53
            ->setApiSiteParameter(array_key_exists('api_site_parameter', $data) ? $data['api_site_parameter'] : null)
54
            ->setBadgeId(array_key_exists('badge_id', $data) ? $data['badge_id'] : null)
55
            ->setDescription(array_key_exists('description', $data) ? $data['description'] : null)
56
            ->setLink(array_key_exists('link', $data) ? $data['link'] : null)
57
            ->setPostId(array_key_exists('post_id', $data) ? $data['post_id'] : null)
58
            ->setScore(array_key_exists('score', $data) ? $data['score'] : null)
59
            ->setCreationDate(
60
                array_key_exists('creation_date', $data)
61
                    ? new \DateTimeImmutable('@' . $data['creation_date'])
62
                    : null
63
            )
64
            ->setTags($tags)
65
            ->setTitle(array_key_exists('title', $data) ? $data['title'] : null);
66
67
        return $instance;
68
    }
69
70
    public static function fromProperties(
71
        $accountId,
72
        $activityType,
73
        $apiSiteParameter,
74
        $badgeId,
75
        $description,
76
        $link,
77
        $postId,
78
        $score,
79
        \DateTimeInterface $creationDate,
80
        $tags,
81
        $title
82
    ) {
83
        $instance = new self();
84
        $instance
85
            ->setAccountId($accountId)
86
            ->setActivityType($activityType)
87
            ->setApiSiteParameter($apiSiteParameter)
88
            ->setBadgeId($badgeId)
89
            ->setDescription($description)
90
            ->setLink($link)
91
            ->setPostId($postId)
92
            ->setScore($score)
93
            ->setCreationDate($creationDate)
94
            ->setTags($tags)
95
            ->setTitle($title);
96
97
        return $instance;
98
    }
99
100
    public function setAccountId($accountId)
101
    {
102
        $this->accountId = $accountId;
103
104
        return $this;
105
    }
106
107
    public function getAccountId()
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...
108
    {
109
        return $this->accountId;
110
    }
111
112
    public function setActivityType($activityType)
113
    {
114
        if (in_array($activityType, self::ACTIVITY_TYPES, true)) {
115
            $this->activityType = $activityType;
116
        }
117
118
        return $this;
119
    }
120
121
    public function getActivityType()
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...
122
    {
123
        return $this->activityType;
124
    }
125
126
    public function setApiSiteParameter($apiSiteParameter)
127
    {
128
        $this->apiSiteParameter = $apiSiteParameter;
129
130
        return $this;
131
    }
132
133
    public function getApiSiteParameter()
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...
134
    {
135
        return $this->apiSiteParameter;
136
    }
137
138
    public function setBadgeId($badgeId)
139
    {
140
        $this->badgeId = $badgeId;
141
142
        return $this;
143
    }
144
145
    public function getBadgeId()
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...
146
    {
147
        return $this->badgeId;
148
    }
149
150
    public function setDescription($description)
151
    {
152
        $this->description = $description;
153
154
        return $this;
155
    }
156
157
    public function getDescription()
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...
158
    {
159
        return $this->description;
160
    }
161
162
    public function setLink($link)
163
    {
164
        $this->link = $link;
165
166
        return $this;
167
    }
168
169
    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...
170
    {
171
        return $this->link;
172
    }
173
174
    public function setPostId($postId)
175
    {
176
        $this->postId = $postId;
177
178
        return $this;
179
    }
180
181
    public function getPostId()
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...
182
    {
183
        return $this->postId;
184
    }
185
186
    public function setScore($score)
187
    {
188
        $this->score = $score;
189
190
        return $this;
191
    }
192
193
    public function getScore()
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...
194
    {
195
        return $this->score;
196
    }
197
198
    public function setCreationDate(\DateTimeInterface $creationDate = null)
199
    {
200
        $this->creationDate = $creationDate;
201
202
        return $this;
203
    }
204
205
    public function getCreationDate()
206
    {
207
        return $this->creationDate;
208
    }
209
210
    public function setTags($tags)
211
    {
212
        $this->tags = $tags;
213
214
        return $this;
215
    }
216
217
    public function getTags()
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...
218
    {
219
        return $this->tags;
220
    }
221
222
    public function setTitle($title)
223
    {
224
        $this->title = $title;
225
226
        return $this;
227
    }
228
229
    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...
230
    {
231
        return $this->title;
232
    }
233
}
234