Tag::fromProperties()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 20
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 tag model class.
26
 *
27
 * @author Beñat Espiña <[email protected]>
28
 */
29
class Tag implements Model
30
{
31
    protected $count;
32
    protected $hasSynonyms;
33
    protected $isModeratorOnly;
34
    protected $isRequired;
35
    protected $lastActivityDate;
36
    protected $name;
37
    protected $synonyms;
38
    protected $userId;
39
40
    public static function fromJson(array $data)
41
    {
42
        $instance = new self();
43
        $instance
44
            ->setCount(array_key_exists('count', $data) ? $data['count'] : null)
45
            ->setHasSynonyms(array_key_exists('has_synonyms', $data) ? $data['has_synonyms'] : null)
46
            ->setIsModeratorOnly(array_key_exists('is_moderator_only', $data) ? $data['is_moderator_only'] : null)
47
            ->setIsRequired(array_key_exists('is_required', $data) ? $data['is_required'] : null)
48
            ->setLastActivityDate(
49
                array_key_exists('last_activity_date', $data)
50
                    ? new \DateTimeImmutable('@' . $data['last_activity_date'])
51
                    : null
52
            )
53
            ->setName(array_key_exists('name', $data) ? $data['name'] : null)
54
            ->setSynonyms(array_key_exists('synonyms', $data) ? $data['synonyms'] : null)
55
            ->setUserId(array_key_exists('user_id', $data) ? $data['user_id'] : null);
56
57
        return $instance;
58
    }
59
60
    public static function fromProperties(
61
        $count,
62
        $hasSynonyms,
63
        $isModeratorOnly,
64
        $isRequired,
65
        $name,
66
        $synonyms,
67
        \DateTimeInterface $lastActivityDate = null,
68
        $userId = null
69
    ) {
70
        $instance = new self();
71
        $instance
72
            ->setCount($count)
73
            ->setHasSynonyms($hasSynonyms)
74
            ->setIsModeratorOnly($isModeratorOnly)
75
            ->setIsRequired($isRequired)
76
            ->setLastActivityDate($lastActivityDate)
77
            ->setName($name)
78
            ->setSynonyms($synonyms)
79
            ->setUserId($userId);
80
81
        return $instance;
82
    }
83
84
    public function getCount()
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->count;
87
    }
88
89
    public function setCount($count)
90
    {
91
        $this->count = $count;
92
93
        return $this;
94
    }
95
96
    public function getHasSynonyms()
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->hasSynonyms;
99
    }
100
101
    public function setHasSynonyms($hasSynonyms)
102
    {
103
        $this->hasSynonyms = $hasSynonyms;
104
105
        return $this;
106
    }
107
108
    public function getIsModeratorOnly()
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->isModeratorOnly;
111
    }
112
113
    public function setIsModeratorOnly($isModeratorOnly)
114
    {
115
        $this->isModeratorOnly = $isModeratorOnly;
116
117
        return $this;
118
    }
119
120
    public function getIsRequired()
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->isRequired;
123
    }
124
125
    public function setIsRequired($isRequired)
126
    {
127
        $this->isRequired = $isRequired;
128
129
        return $this;
130
    }
131
132
    public function getLastActivityDate()
133
    {
134
        return $this->lastActivityDate;
135
    }
136
137
    public function setLastActivityDate(\DateTimeInterface $lastActivityDate = null)
138
    {
139
        $this->lastActivityDate = $lastActivityDate;
140
141
        return $this;
142
    }
143
144
    public function getName()
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->name;
147
    }
148
149
    public function setName($name)
150
    {
151
        $this->name = $name;
152
153
        return $this;
154
    }
155
156
    public function getSynonyms()
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->synonyms;
159
    }
160
161
    public function setSynonyms($synonyms)
162
    {
163
        $this->synonyms = $synonyms;
164
165
        return $this;
166
    }
167
168
    public function getUserId()
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->userId;
171
    }
172
173
    public function setUserId($userId)
174
    {
175
        $this->userId = $userId;
176
177
        return $this;
178
    }
179
}
180