ShallowUser::setProfileImage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 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
 * The shallow user model class.
26
 *
27
 * @author Beñat Espiña <[email protected]>
28
 */
29
class ShallowUser implements Model
30
{
31
    const USER_TYPES = ['does_not_exist', 'moderator', 'registered', 'unregistered'];
32
33
    protected $id;
34
    protected $acceptRate;
35
    protected $badgeCounts;
36
    protected $displayName;
37
    protected $link;
38
    protected $profileImage;
39
    protected $reputation;
40
    protected $userType;
41
42 View Code Duplication
    public static function fromJson(array $data)
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...
43
    {
44
        $instance = new self();
45
        $instance
46
            ->setId(array_key_exists('user_id', $data) ? $data['user_id'] : null)
47
            ->setBadgeCounts(
48
                array_key_exists('badge_counts', $data)
49
                    ? BadgeCount::fromJson($data['badge_counts'])
50
                    : null
51
            )
52
            ->setAcceptRate(array_key_exists('accept_rate', $data) ? $data['accept_rate'] : null)
53
            ->setDisplayName(array_key_exists('display_name', $data) ? $data['display_name'] : null)
54
            ->setLink(array_key_exists('link', $data) ? $data['link'] : null)
55
            ->setProfileImage(array_key_exists('profile_image', $data) ? $data['profile_image'] : null)
56
            ->setReputation(array_key_exists('reputation', $data) ? $data['reputation'] : null)
57
            ->setReputation(array_key_exists('user_type', $data) ? $data['user_type'] : null);
58
59
        return $instance;
60
    }
61
62
    public static function fromProperties(
63
        $id,
64
        BadgeCount $badgeCounts,
65
        $userType,
66
        $acceptRate = null,
67
        $displayName = null,
68
        $link = null,
69
        $profileImage = null,
70
        $reputation = null
71
    ) {
72
        return new self(
73
            $id,
74
            $acceptRate,
75
            $badgeCounts,
76
            $displayName,
77
            $link,
78
            $profileImage,
79
            $reputation,
80
            $userType
81
        );
82
    }
83
84
    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...
85
    {
86
        return $this->id;
87
    }
88
89
    public function setId($id)
90
    {
91
        $this->id = $id;
92
93
        return $this;
94
    }
95
96
    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...
97
    {
98
        return $this->acceptRate;
99
    }
100
101
    public function setAcceptRate($acceptRate)
102
    {
103
        $this->acceptRate = $acceptRate;
104
105
        return $this;
106
    }
107
108
    public function getBadgeCounts()
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->badgeCounts;
111
    }
112
113
    public function setBadgeCounts($badgeCounts)
114
    {
115
        $this->badgeCounts = $badgeCounts;
116
117
        return $this;
118
    }
119
120
    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...
121
    {
122
        return $this->displayName;
123
    }
124
125
    public function setDisplayName($displayName)
126
    {
127
        $this->displayName = $displayName;
128
129
        return $this;
130
    }
131
132
    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...
133
    {
134
        return $this->link;
135
    }
136
137
    public function setLink($link)
138
    {
139
        $this->link = $link;
140
141
        return $this;
142
    }
143
144
    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...
145
    {
146
        return $this->profileImage;
147
    }
148
149
    public function setProfileImage($profileImage)
150
    {
151
        $this->profileImage = $profileImage;
152
153
        return $this;
154
    }
155
156
    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...
157
    {
158
        return $this->reputation;
159
    }
160
161
    public function setReputation($reputation)
162
    {
163
        $this->reputation = $reputation;
164
165
        return $this;
166
    }
167
168
    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...
169
    {
170
        return $this->userType;
171
    }
172
173
    public function setUserType($userType)
174
    {
175
        if (in_array($userType, self::USER_TYPES, true)) {
176
            $this->userType = $userType;
177
        }
178
179
        return $this;
180
    }
181
}
182