Completed
Push — v3 ( d12fea )
by Beñat
05:39
created

AnemicNetworkUser::getQuestionCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
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\Infrastructure\Domain\Model;
13
14
use BenatEspina\StackExchangeApiClient\Domain\Model\BadgeCount;
15
use BenatEspina\StackExchangeApiClient\Domain\Model\NetworkUser;
16
17
/**
18
 * The anemic implementation of network user domain class.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
class AnemicNetworkUser implements NetworkUser
23
{
24
    const USER_TYPE_DOES_NOT_EXIST = 'does_not_exist';
25
    const USER_TYPE_MODERATOR = 'moderator';
26
    const USER_TYPE_REGISTERED = 'registered';
27
    const USER_TYPE_UNREGISTERED = 'unregistered';
28
29
    private $id;
30
    private $answerCount;
31
    private $badgeCounts;
32
    private $creationDate;
33
    private $lastAccessDate;
34
    private $questionCount;
35
    private $reputation;
36
    private $siteName;
37
    private $siteUrl;
38
    private $topAnswers;
39
    private $topQuestions;
40
    private $userType;
41
42
    public static function fromJson($data)
43
    {
44
        $topAnswers = [];
45
        $topQuestions = [];
46 View Code Duplication
        if (array_key_exists('top_answers', $data) && is_array($data['top_answers'])) {
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...
47
            foreach ($data['top_answers'] as $topAnswer) {
48
                $topAnswers[] = AnemicNetworkPost::fromJson($topAnswer);
49
            }
50
        }
51 View Code Duplication
        if (array_key_exists('top_questions', $data) && is_array($data['top_questions'])) {
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...
52
            foreach ($data['top_questions'] as $topQuestion) {
53
                $topQuestions[] = AnemicNetworkPost::fromJson($topQuestion);
54
            }
55
        }
56
57
        return new self(
58
            array_key_exists('user_id', $data) ? $data['user_id'] : null,
59
            array_key_exists('answer_count', $data) ? $data['answer_count'] : null,
60
            array_key_exists('badge_counts', $data) ? AnemicBadgeCount::fromJson($data['badge_counts']) : null,
61
            array_key_exists('creation_date', $data) ? new \DateTimeImmutable('@' . $data['creation_date']) : null,
62
            array_key_exists('last_access_date', $data) ? new \DateTimeImmutable('@' . $data['last_access_date']) : null,
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
63
            array_key_exists('question_count', $data) ? $data['question_count'] : null,
64
            array_key_exists('reputation', $data) ? $data['reputation'] : null,
65
            array_key_exists('site_name', $data) ? $data['site_name'] : null,
66
            array_key_exists('site_url', $data) ? $data['site_url'] : null,
67
            $topAnswers,
68
            $topQuestions,
69
            array_key_exists('user_type', $data) ? $data['user_type'] : null
70
        );
71
    }
72
73
    public static function fromProperties(
74
        $id,
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
        $answerCount,
0 ignored issues
show
Unused Code introduced by
The parameter $answerCount is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
        BadgeCount $badgeCounts,
0 ignored issues
show
Unused Code introduced by
The parameter $badgeCounts is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
        \DateTimeInterface $creationDate,
0 ignored issues
show
Unused Code introduced by
The parameter $creationDate is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
        \DateTimeInterface $lastAccessDate,
0 ignored issues
show
Unused Code introduced by
The parameter $lastAccessDate is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
        $questionCount,
0 ignored issues
show
Unused Code introduced by
The parameter $questionCount is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
        $reputation,
0 ignored issues
show
Unused Code introduced by
The parameter $reputation is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
        $siteName,
0 ignored issues
show
Unused Code introduced by
The parameter $siteName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
        $siteUrl,
0 ignored issues
show
Unused Code introduced by
The parameter $siteUrl is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
        array $topAnswers,
0 ignored issues
show
Unused Code introduced by
The parameter $topAnswers is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
84
        array $topQuestions,
0 ignored issues
show
Unused Code introduced by
The parameter $topQuestions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
        $userType
0 ignored issues
show
Unused Code introduced by
The parameter $userType is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
86
    ) {
87
    }
88
89
    private function __construct(
90
        $id = null,
91
        $answerCount = null,
92
        BadgeCount $badgeCounts = null,
93
        \DateTimeInterface $creationDate = null,
94
        \DateTimeInterface $lastAccessDate = null,
95
        $questionCount = null,
96
        $reputation = null,
97
        $siteName = null,
98
        $siteUrl = null,
99
        array $topAnswers = [],
100
        array $topQuestions = [],
101
        $userType = null
102
    ) {
103
        $this->id = $id;
104
        $this->answerCount = $answerCount;
105
        $this->badgeCounts = $badgeCounts;
106
        $this->creationDate = $creationDate;
107
        $this->lastAccessDate = $lastAccessDate;
108
        $this->questionCount = $questionCount;
109
        $this->reputation = $reputation;
110
        $this->siteName = $siteName;
111
        $this->siteUrl = $siteUrl;
112
        $this->topAnswers = $topAnswers;
113
        $this->topQuestions = $topQuestions;
114
        $this->userType = $userType;
115
        $this->setUserType($userType);
116
    }
117
118
    public function getId()
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...
119
    {
120
        return $this->id;
121
    }
122
123
    public function setId($id)
124
    {
125
        $this->id = $id;
126
127
        return $this;
128
    }
129
130
    public function getAnswerCount()
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...
131
    {
132
        return $this->answerCount;
133
    }
134
135
    public function setAnswerCount($answerCount)
136
    {
137
        $this->answerCount = $answerCount;
138
139
        return $this;
140
    }
141
142
    public function getBadgeCounts()
143
    {
144
        return $this->badgeCounts;
145
    }
146
147
    public function setBadgeCounts(BadgeCount $badgeCounts)
148
    {
149
        $this->badgeCounts = $badgeCounts;
150
151
        return $this;
152
    }
153
154
    public function getCreationDate()
155
    {
156
        return $this->creationDate;
157
    }
158
159
    public function setCreationDate(\DateTimeInterface $creationDate)
160
    {
161
        $this->creationDate = $creationDate;
162
163
        return $this;
164
    }
165
166
    public function getLastAccessDate()
167
    {
168
        return $this->lastAccessDate;
169
    }
170
171
    public function setLastAccessDate(\DateTimeInterface $lastAccessDate)
172
    {
173
        $this->lastAccessDate = $lastAccessDate;
174
175
        return $this;
176
    }
177
178
    public function getQuestionCount()
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...
179
    {
180
        return $this->questionCount;
181
    }
182
183
    public function setQuestionCount($questionCount)
184
    {
185
        $this->questionCount = $questionCount;
186
187
        return $this;
188
    }
189
190
    public function getReputation()
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...
191
    {
192
        return $this->reputation;
193
    }
194
195
    public function setReputation($reputation)
196
    {
197
        $this->reputation = $reputation;
198
199
        return $this;
200
    }
201
202
    public function getSiteName()
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...
203
    {
204
        return $this->siteName;
205
    }
206
207
    public function setSiteName($siteName)
208
    {
209
        $this->siteName = $siteName;
210
211
        return $this;
212
    }
213
214
    public function getSiteUrl()
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...
215
    {
216
        return $this->siteUrl;
217
    }
218
219
    public function setSiteUrl($siteUrl)
220
    {
221
        $this->siteUrl = $siteUrl;
222
223
        return $this;
224
    }
225
226
    public function getTopAnswers()
227
    {
228
        return $this->topAnswers;
229
    }
230
231
    public function setTopAnswers($topAnswers)
232
    {
233
        $this->topAnswers = $topAnswers;
234
235
        return $this;
236
    }
237
238
    public function getTopQuestions()
239
    {
240
        return $this->topQuestions;
241
    }
242
243
    public function setTopQuestions($topQuestions)
244
    {
245
        $this->topQuestions = $topQuestions;
246
247
        return $this;
248
    }
249
250
    public function getUserType()
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...
251
    {
252
        return $this->userType;
253
    }
254
255 View Code Duplication
    public function setUserType($userType)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
256
    {
257
        if (in_array($userType, [
258
            self::USER_TYPE_DOES_NOT_EXIST,
259
            self::USER_TYPE_MODERATOR,
260
            self::USER_TYPE_REGISTERED,
261
            self::USER_TYPE_UNREGISTERED,
262
        ], true)) {
263
            $this->userType = $userType;
264
        }
265
266
        return $this;
267
    }
268
}
269