Tweet::create()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 17
cts 17
cp 1
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 35
nc 1
nop 18
crap 1

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
namespace Twitter\Object;
4
5
use Twitter\TwitterEventTarget;
6
use Twitter\TwitterMessage;
7
use Twitter\TwitterMessageId;
8
9
class Tweet extends AbstractMessage implements TwitterEventTarget, TwitterMessage
10
{
11
    /**
12
     * @var string
13
     */
14
    private $lang;
15
16
    /**
17
     * @var TwitterCoordinates
18
     */
19
    private $coordinates;
20
21
    /**
22
     * @var TwitterPlace
23
     */
24
    private $place;
25
26
    /**
27
     * @var bool
28
     */
29
    private $retweeted;
30
31
    /**
32
     * @var int
33
     */
34
    private $inReplyToStatusId;
35
36
    /**
37
     * @var int
38
     */
39
    private $inReplyToUserId;
40
41
    /**
42
     * @var string
43
     */
44
    private $inReplyToScreenName;
45
46
    /**
47
     * @var int
48
     */
49
    private $retweetCount;
50
51
    /**
52
     * @var int
53
     */
54
    private $favoriteCount;
55
56
    /**
57
     * @var string
58
     */
59
    private $source;
60
61
    /**
62
     * @var bool
63
     */
64
    private $favorited;
65
66
    /**
67
     * @var boolean
68
     */
69
    private $truncated;
70
71
    /**
72
     * @var Tweet
73
     */
74
    private $retweetedStatus;
75
76
    /**
77
     * Constructor.
78
     */
79 15
    public function __construct()
80
    {
81 15
    }
82
83
    /**
84
     * @return TwitterCoordinates
85
     */
86 12
    public function getCoordinates()
87
    {
88 12
        return $this->coordinates;
89
    }
90
91
    /**
92
     * @return int
93
     */
94 12
    public function getFavoriteCount()
95
    {
96 12
        return $this->favoriteCount;
97
    }
98
99
    /**
100
     * @return boolean
101
     */
102 12
    public function isFavorited()
103
    {
104 12
        return $this->favorited;
105
    }
106
107
    /**
108
     * @return string
109
     */
110 12
    public function getInReplyToScreenName()
111
    {
112 12
        return $this->inReplyToScreenName;
113
    }
114
115
    /**
116
     * @return int
117
     */
118 12
    public function getInReplyToStatusId()
119
    {
120 12
        return $this->inReplyToStatusId;
121
    }
122
123
    /**
124
     * @return int
125
     */
126 12
    public function getInReplyToUserId()
127
    {
128 12
        return $this->inReplyToUserId;
129
    }
130
131
    /**
132
     * @return string
133
     */
134 12
    public function getLang()
135
    {
136 12
        return $this->lang;
137
    }
138
139
    /**
140
     * @return TwitterPlace
141
     */
142 12
    public function getPlace()
143
    {
144 12
        return $this->place;
145
    }
146
147
    /**
148
     * @return int
149
     */
150 12
    public function getRetweetCount()
151
    {
152 12
        return $this->retweetCount;
153
    }
154
155
    /**
156
     * @return boolean
157
     */
158 12
    public function isRetweeted()
159
    {
160 12
        return $this->retweeted;
161
    }
162
163
    /**
164
     * @return string
165
     */
166 12
    public function getSource()
167
    {
168 12
        return $this->source;
169
    }
170
171
    /**
172
     * @return boolean
173
     */
174 12
    public function isTruncated()
175
    {
176 12
        return $this->truncated;
177
    }
178
179
    /**
180
     * @return Tweet
181
     */
182 12
    public function getRetweetedStatus()
183
    {
184 12
        return $this->retweetedStatus;
185
    }
186
187
    /**
188
     * @return string
189
     */
190 3
    public function __toString()
191
    {
192 3
        return 'Tweet [' . $this->id . ']';
193
    }
194
195
    /**
196
     * Static constructor.
197
     *
198
     * @param TwitterMessageId   $id
199
     * @param TwitterUser        $sender
200
     * @param string             $text
201
     * @param string             $lang
202
     * @param \DateTimeInterface $createdAt
203
     * @param TwitterEntities    $entities
204
     * @param TwitterCoordinates $coordinates
205
     * @param TwitterPlace       $place
206
     * @param int                $inReplyToStatusId
207
     * @param int                $inReplyToUserId
208
     * @param string             $inReplyToScreenName
209
     * @param bool               $retweeted
210
     * @param int                $retweetCount
211
     * @param bool               $favorited
212
     * @param int                $favoriteCount
213
     * @param bool               $truncated
214
     * @param null               $source
215
     * @param Tweet              $retweetedStatus
216
     *
217
     * @return Tweet
218
     */
219 15
    public static function create(
220
        TwitterMessageId $id,
221
        TwitterUser $sender,
222
        $text,
223
        $lang,
224
        \DateTimeInterface $createdAt,
225
        TwitterEntities $entities,
226
        TwitterCoordinates $coordinates = null,
227
        TwitterPlace $place = null,
228
        $inReplyToStatusId = null,
229
        $inReplyToUserId = null,
230
        $inReplyToScreenName = null,
231
        $retweeted = false,
232
        $retweetCount = 0,
233
        $favorited = false,
234
        $favoriteCount = 0,
235
        $truncated = false,
236
        $source = null,
237
        Tweet $retweetedStatus = null
238
    ) {
239 15
        $obj = new self();
240
241 15
        $obj->init($id, $sender, $text, $entities, $createdAt);
242
243 15
        $obj->lang = $lang;
244 15
        $obj->coordinates = $coordinates;
245 15
        $obj->place = $place;
246 15
        $obj->inReplyToStatusId = $inReplyToStatusId;
247 15
        $obj->inReplyToUserId = $inReplyToUserId;
248 15
        $obj->inReplyToScreenName = $inReplyToScreenName;
249 15
        $obj->retweeted = $retweeted;
250 15
        $obj->retweetCount = $retweetCount;
251 15
        $obj->favorited = $favorited;
252 15
        $obj->favoriteCount = $favoriteCount;
253 15
        $obj->truncated = $truncated;
254 15
        $obj->source = $source;
255 15
        $obj->retweetedStatus = $retweetedStatus;
256
257 15
        return $obj;
258
    }
259
}
260