Completed
Push — v2 ( e6c7b3...40717e )
by Beñat
06:35
created

ShallowUser::setId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 6
rs 9.4285
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
 * 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
 * The shallow user model class.
16
 *
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
class ShallowUser implements Model
20
{
21
    const USER_TYPES = ['does_not_exist', 'moderator', 'registered', 'unregistered'];
22
23
    protected $id;
24
    protected $acceptRate;
25
    protected $badgeCounts;
26
    protected $displayName;
27
    protected $link;
28
    protected $profileImage;
29
    protected $reputation;
30
    protected $userType;
31
32 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...
33
    {
34
        $instance = new self();
35
        $instance
36
            ->setId(array_key_exists('user_id', $data) ? $data['user_id'] : null)
37
            ->setBadgeCounts(
38
                array_key_exists('badge_counts', $data)
39
                    ? BadgeCount::fromJson($data['badge_counts'])
40
                    : null
41
            )
42
            ->setAcceptRate(array_key_exists('accept_rate', $data) ? $data['accept_rate'] : null)
43
            ->setDisplayName(array_key_exists('display_name', $data) ? $data['display_name'] : null)
44
            ->setLink(array_key_exists('link', $data) ? $data['link'] : null)
45
            ->setProfileImage(array_key_exists('profile_image', $data) ? $data['profile_image'] : null)
46
            ->setReputation(array_key_exists('reputation', $data) ? $data['reputation'] : null)
47
            ->setReputation(array_key_exists('user_type', $data) ? $data['user_type'] : null);
48
49
        return $instance;
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,
0 ignored issues
show
Unused Code introduced by
The call to ShallowUser::__construct() has too many arguments starting with $id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
64
            $acceptRate,
65
            $badgeCounts,
66
            $displayName,
67
            $link,
68
            $profileImage,
69
            $reputation,
70
            $userType
71
        );
72
    }
73
74
    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...
75
    {
76
        return $this->id;
77
    }
78
79
    public function setId($id)
80
    {
81
        $this->id = $id;
82
83
        return $this;
84
    }
85
86
    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...
87
    {
88
        return $this->acceptRate;
89
    }
90
91
    public function setAcceptRate($acceptRate)
92
    {
93
        $this->acceptRate = $acceptRate;
94
95
        return $this;
96
    }
97
98
    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...
99
    {
100
        return $this->badgeCounts;
101
    }
102
103
    public function setBadgeCounts($badgeCounts)
104
    {
105
        $this->badgeCounts = $badgeCounts;
106
107
        return $this;
108
    }
109
110
    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...
111
    {
112
        return $this->displayName;
113
    }
114
115
    public function setDisplayName($displayName)
116
    {
117
        $this->displayName = $displayName;
118
119
        return $this;
120
    }
121
122
    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...
123
    {
124
        return $this->link;
125
    }
126
127
    public function setLink($link)
128
    {
129
        $this->link = $link;
130
131
        return $this;
132
    }
133
134
    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...
135
    {
136
        return $this->profileImage;
137
    }
138
139
    public function setProfileImage($profileImage)
140
    {
141
        $this->profileImage = $profileImage;
142
143
        return $this;
144
    }
145
146
    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...
147
    {
148
        return $this->reputation;
149
    }
150
151
    public function setReputation($reputation)
152
    {
153
        $this->reputation = $reputation;
154
155
        return $this;
156
    }
157
158
    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...
159
    {
160
        return $this->userType;
161
    }
162
163
    public function setUserType($userType)
164
    {
165
        if (in_array($userType, self::USER_TYPES, true)) {
166
            $this->userType = $userType;
167
        }
168
169
        return $this;
170
    }
171
}
172