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

AnemicTag::fromProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 18
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
 * 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\Tag;
15
16
/**
17
 * The anemic implementation of tag domain class.
18
 *
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
class AnemicTag implements Tag
22
{
23
    private $count;
24
    private $hasSynonyms;
25
    private $isModeratorOnly;
26
    private $isRequired;
27
    private $lastActivityDate;
28
    private $name;
29
    private $synonyms;
30
    private $userId;
31
32
    public static function fromJson($data)
33
    {
34
        return new self(
35
            array_key_exists('count', $data) ? $data['count'] : null,
36
            array_key_exists('has_synonyms', $data) ? $data['has_synonyms'] : null,
37
            array_key_exists('is_moderator_only', $data) ? $data['is_moderator_only'] : null,
38
            array_key_exists('is_required', $data) ? $data['is_required'] : null,
39
            array_key_exists('last_activity_date', $data) ? new \DateTimeImmutable('@' . $data['last_activity_date']) : null,
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 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...
40
            array_key_exists('name', $data) ? $data['name'] : null,
41
            array_key_exists('synonyms', $data) ? $data['synonyms'] : null,
42
            array_key_exists('user_id', $data) ? $data['user_id'] : null
43
        );
44
    }
45
46
    public static function fromProperties(
47
        $count,
48
        $hasSynonyms,
49
        $isModeratorOnly,
50
        $isRequired,
51
        $name,
52
        $synonyms,
53
        \DateTimeInterface $lastActivityDate = null,
54
        $userId = null
55
    ) {
56
        return new self(
57
            $count,
58
            $hasSynonyms,
59
            $isModeratorOnly,
60
            $isRequired,
61
            $lastActivityDate,
62
            $name,
63
            $synonyms,
64
            $userId
65
        );
66
    }
67
68
    private function __construct(
69
        $count = null,
70
        $hasSynonyms = null,
71
        $isModeratorOnly = null,
72
        $isRequired = null,
73
        \DateTimeInterface $lastActivityDate = null,
74
        $name = null,
75
        $synonyms = null,
76
        $userId = null
77
    ) {
78
        $this->count = $count;
79
        $this->hasSynonyms = $hasSynonyms;
80
        $this->isModeratorOnly = $isModeratorOnly;
81
        $this->isRequired = $isRequired;
82
        $this->lastActivityDate = $lastActivityDate;
83
        $this->name = $name;
84
        $this->synonyms = $synonyms;
85
        $this->userId = $userId;
86
    }
87
88
    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...
89
    {
90
        return $this->count;
91
    }
92
93
    public function setCount($count)
94
    {
95
        $this->count = $count;
96
97
        return $this;
98
    }
99
100
    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...
101
    {
102
        return $this->hasSynonyms;
103
    }
104
105
    public function setHasSynonyms($hasSynonyms)
106
    {
107
        $this->hasSynonyms = $hasSynonyms;
108
109
        return $this;
110
    }
111
112
    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...
113
    {
114
        return $this->isModeratorOnly;
115
    }
116
117
    public function setIsModeratorOnly($isModeratorOnly)
118
    {
119
        $this->isModeratorOnly = $isModeratorOnly;
120
121
        return $this;
122
    }
123
124
    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...
125
    {
126
        return $this->isRequired;
127
    }
128
129
    public function setIsRequired($isRequired)
130
    {
131
        $this->isRequired = $isRequired;
132
133
        return $this;
134
    }
135
136
    public function getLastActivityDate()
137
    {
138
        return $this->lastActivityDate;
139
    }
140
141
    public function setLastActivityDate(\DateTimeInterface $lastActivityDate)
142
    {
143
        $this->lastActivityDate = $lastActivityDate;
144
145
        return $this;
146
    }
147
148
    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...
149
    {
150
        return $this->name;
151
    }
152
153
    public function setName($name)
154
    {
155
        $this->name = $name;
156
157
        return $this;
158
    }
159
160
    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...
161
    {
162
        return $this->synonyms;
163
    }
164
165
    public function setSynonyms($synonyms)
166
    {
167
        $this->synonyms = $synonyms;
168
169
        return $this;
170
    }
171
172
    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...
173
    {
174
        return $this->userId;
175
    }
176
177
    public function setUserId($userId)
178
    {
179
        $this->userId = $userId;
180
181
        return $this;
182
    }
183
}
184