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

AnemicShallowUser::fromJson()   B

Complexity

Conditions 9
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 7.756
cc 9
eloc 10
nc 1
nop 1
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\ShallowUser;
16
17
/**
18
 * The anemic implementation of shallow user domain class.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
class AnemicShallowUser implements ShallowUser
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 $acceptRate;
31
    private $badgeCounts;
32
    private $displayName;
33
    private $link;
34
    private $profileImage;
35
    private $reputation;
36
    private $userType;
37
38
    public static function fromJson($data)
39
    {
40
        return new self(
41
            array_key_exists('user_id', $data) ? $data['user_id'] : null,
42
            array_key_exists('badge_counts', $data) ? AnemicBadgeCount::fromJson($data['badge_counts']) : null,
43
            array_key_exists('accept_rate', $data) ? $data['accept_rate'] : null,
44
            array_key_exists('display_name', $data) ? $data['display_name'] : null,
45
            array_key_exists('link', $data) ? $data['link'] : null,
46
            array_key_exists('profile_image', $data) ? $data['profile_image'] : null,
47
            array_key_exists('reputation', $data) ? $data['reputation'] : null,
48
            array_key_exists('user_type', $data) ? $data['user_type'] : null
49
        );
50
    }
51
52
    public static function fromProperties(
53
        $id,
54
        BadgeCount $badgeCounts,
55
        $userType,
56
        $acceptRate = null,
57
        $displayName = null,
58
        $link = null,
59
        $profileImage = null,
60
        $reputation = null
61
    ) {
62
        return new self(
63
            $id,
64
            $acceptRate,
65
            $badgeCounts,
66
            $displayName,
67
            $link,
68
            $profileImage,
69
            $reputation,
70
            $userType
71
        );
72
    }
73
74
    private function __construct(
75
        $id = null,
76
        BadgeCount $badgeCounts = null,
77
        $acceptRate = null,
78
        $displayName = null,
79
        $link = null,
80
        $profileImage = null,
81
        $reputation = null,
82
        $userType = null
83
    ) {
84
        $this->id = $id;
85
        $this->acceptRate = $acceptRate;
86
        $this->badgeCounts = $badgeCounts;
87
        $this->displayName = $displayName;
88
        $this->link = $link;
89
        $this->profileImage = $profileImage;
90
        $this->reputation = $reputation;
91
        $this->setUserType($userType);
92
    }
93
94
    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...
95
    {
96
        return $this->id;
97
    }
98
99
    public function setId($id)
100
    {
101
        $this->id = $id;
102
103
        return $this;
104
    }
105
106
    public function getAcceptRate()
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...
107
    {
108
        return $this->acceptRate;
109
    }
110
111
    public function setAcceptRate($acceptRate)
112
    {
113
        $this->acceptRate = $acceptRate;
114
115
        return $this;
116
    }
117
118
    public function getBadgeCounts()
119
    {
120
        return $this->badgeCounts;
121
    }
122
123
    public function setBadgeCounts($badgeCounts)
124
    {
125
        $this->badgeCounts = $badgeCounts;
126
127
        return $this;
128
    }
129
130
    public function getDisplayName()
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->displayName;
133
    }
134
135
    public function setDisplayName($displayName)
136
    {
137
        $this->displayName = $displayName;
138
139
        return $this;
140
    }
141
142
    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...
143
    {
144
        return $this->link;
145
    }
146
147
    public function setLink($link)
148
    {
149
        $this->link = $link;
150
151
        return $this;
152
    }
153
154
    public function getProfileImage()
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...
155
    {
156
        return $this->profileImage;
157
    }
158
159
    public function setProfileImage($profileImage)
160
    {
161
        $this->profileImage = $profileImage;
162
163
        return $this;
164
    }
165
166
    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...
167
    {
168
        return $this->reputation;
169
    }
170
171
    public function setReputation($reputation)
172
    {
173
        $this->reputation = $reputation;
174
175
        return $this;
176
    }
177
178
    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...
179
    {
180
        return $this->userType;
181
    }
182
183 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...
184
    {
185
        if (in_array($userType, [
186
            self::USER_TYPE_DOES_NOT_EXIST,
187
            self::USER_TYPE_MODERATOR,
188
            self::USER_TYPE_REGISTERED,
189
            self::USER_TYPE_UNREGISTERED,
190
        ], true)) {
191
            $this->userType = $userType;
192
        }
193
194
        return $this;
195
    }
196
}
197