Total Complexity | 42 |
Total Lines | 547 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like GossipMessage often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GossipMessage, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class GossipMessage extends \Google\Protobuf\Internal\Message |
||
17 | { |
||
18 | /** |
||
19 | * used mainly for testing, but will might be used in the future |
||
20 | * for ensuring message delivery by acking |
||
21 | * |
||
22 | * Generated from protobuf field <code>uint64 nonce = 1;</code> |
||
23 | */ |
||
24 | private $nonce = 0; |
||
25 | /** |
||
26 | * The channel of the message. |
||
27 | * Some GossipMessages may set this to nil, because |
||
28 | * they are cross-channels but some may not |
||
29 | * |
||
30 | * Generated from protobuf field <code>bytes channel = 2;</code> |
||
31 | */ |
||
32 | private $channel = ''; |
||
33 | /** |
||
34 | * determines to which peers it is allowed |
||
35 | * to forward the message |
||
36 | * |
||
37 | * Generated from protobuf field <code>.gossip.GossipMessage.Tag tag = 3;</code> |
||
38 | */ |
||
39 | private $tag = 0; |
||
40 | protected $content; |
||
41 | |||
42 | public function __construct() { |
||
43 | \GPBMetadata\Gossip\Message::initOnce(); |
||
44 | parent::__construct(); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * used mainly for testing, but will might be used in the future |
||
49 | * for ensuring message delivery by acking |
||
50 | * |
||
51 | * Generated from protobuf field <code>uint64 nonce = 1;</code> |
||
52 | * @return int|string |
||
53 | */ |
||
54 | public function getNonce() |
||
55 | { |
||
56 | return $this->nonce; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * used mainly for testing, but will might be used in the future |
||
61 | * for ensuring message delivery by acking |
||
62 | * |
||
63 | * Generated from protobuf field <code>uint64 nonce = 1;</code> |
||
64 | * @param int|string $var |
||
65 | * @return $this |
||
66 | */ |
||
67 | public function setNonce($var) |
||
68 | { |
||
69 | GPBUtil::checkUint64($var); |
||
70 | $this->nonce = $var; |
||
71 | |||
72 | return $this; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * The channel of the message. |
||
77 | * Some GossipMessages may set this to nil, because |
||
78 | * they are cross-channels but some may not |
||
79 | * |
||
80 | * Generated from protobuf field <code>bytes channel = 2;</code> |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getChannel() |
||
84 | { |
||
85 | return $this->channel; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * The channel of the message. |
||
90 | * Some GossipMessages may set this to nil, because |
||
91 | * they are cross-channels but some may not |
||
92 | * |
||
93 | * Generated from protobuf field <code>bytes channel = 2;</code> |
||
94 | * @param string $var |
||
95 | * @return $this |
||
96 | */ |
||
97 | public function setChannel($var) |
||
98 | { |
||
99 | GPBUtil::checkString($var, False); |
||
100 | $this->channel = $var; |
||
101 | |||
102 | return $this; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * determines to which peers it is allowed |
||
107 | * to forward the message |
||
108 | * |
||
109 | * Generated from protobuf field <code>.gossip.GossipMessage.Tag tag = 3;</code> |
||
110 | * @return int |
||
111 | */ |
||
112 | public function getTag() |
||
113 | { |
||
114 | return $this->tag; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * determines to which peers it is allowed |
||
119 | * to forward the message |
||
120 | * |
||
121 | * Generated from protobuf field <code>.gossip.GossipMessage.Tag tag = 3;</code> |
||
122 | * @param int $var |
||
123 | * @return $this |
||
124 | */ |
||
125 | public function setTag($var) |
||
126 | { |
||
127 | GPBUtil::checkEnum($var, \Hyperledger\Fabric\Protos\Gossip\GossipMessage_Tag::class); |
||
128 | $this->tag = $var; |
||
129 | |||
130 | return $this; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * Membership |
||
135 | * |
||
136 | * Generated from protobuf field <code>.gossip.AliveMessage alive_msg = 5;</code> |
||
137 | * @return \Hyperledger\Fabric\Protos\Gossip\AliveMessage |
||
138 | */ |
||
139 | public function getAliveMsg() |
||
140 | { |
||
141 | return $this->readOneof(5); |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Membership |
||
146 | * |
||
147 | * Generated from protobuf field <code>.gossip.AliveMessage alive_msg = 5;</code> |
||
148 | * @param \Hyperledger\Fabric\Protos\Gossip\AliveMessage $var |
||
149 | * @return $this |
||
150 | */ |
||
151 | public function setAliveMsg($var) |
||
152 | { |
||
153 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\AliveMessage::class); |
||
154 | $this->writeOneof(5, $var); |
||
155 | |||
156 | return $this; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Generated from protobuf field <code>.gossip.MembershipRequest mem_req = 6;</code> |
||
161 | * @return \Hyperledger\Fabric\Protos\Gossip\MembershipRequest |
||
162 | */ |
||
163 | public function getMemReq() |
||
164 | { |
||
165 | return $this->readOneof(6); |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Generated from protobuf field <code>.gossip.MembershipRequest mem_req = 6;</code> |
||
170 | * @param \Hyperledger\Fabric\Protos\Gossip\MembershipRequest $var |
||
171 | * @return $this |
||
172 | */ |
||
173 | public function setMemReq($var) |
||
174 | { |
||
175 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\MembershipRequest::class); |
||
176 | $this->writeOneof(6, $var); |
||
177 | |||
178 | return $this; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Generated from protobuf field <code>.gossip.MembershipResponse mem_res = 7;</code> |
||
183 | * @return \Hyperledger\Fabric\Protos\Gossip\MembershipResponse |
||
184 | */ |
||
185 | public function getMemRes() |
||
186 | { |
||
187 | return $this->readOneof(7); |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * Generated from protobuf field <code>.gossip.MembershipResponse mem_res = 7;</code> |
||
192 | * @param \Hyperledger\Fabric\Protos\Gossip\MembershipResponse $var |
||
193 | * @return $this |
||
194 | */ |
||
195 | public function setMemRes($var) |
||
196 | { |
||
197 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\MembershipResponse::class); |
||
198 | $this->writeOneof(7, $var); |
||
199 | |||
200 | return $this; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Contains a ledger block |
||
205 | * |
||
206 | * Generated from protobuf field <code>.gossip.DataMessage data_msg = 8;</code> |
||
207 | * @return \Hyperledger\Fabric\Protos\Gossip\DataMessage |
||
208 | */ |
||
209 | public function getDataMsg() |
||
210 | { |
||
211 | return $this->readOneof(8); |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * Contains a ledger block |
||
216 | * |
||
217 | * Generated from protobuf field <code>.gossip.DataMessage data_msg = 8;</code> |
||
218 | * @param \Hyperledger\Fabric\Protos\Gossip\DataMessage $var |
||
219 | * @return $this |
||
220 | */ |
||
221 | public function setDataMsg($var) |
||
222 | { |
||
223 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\DataMessage::class); |
||
224 | $this->writeOneof(8, $var); |
||
225 | |||
226 | return $this; |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * Used for push&pull |
||
231 | * |
||
232 | * Generated from protobuf field <code>.gossip.GossipHello hello = 9;</code> |
||
233 | * @return \Hyperledger\Fabric\Protos\Gossip\GossipHello |
||
234 | */ |
||
235 | public function getHello() |
||
236 | { |
||
237 | return $this->readOneof(9); |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Used for push&pull |
||
242 | * |
||
243 | * Generated from protobuf field <code>.gossip.GossipHello hello = 9;</code> |
||
244 | * @param \Hyperledger\Fabric\Protos\Gossip\GossipHello $var |
||
245 | * @return $this |
||
246 | */ |
||
247 | public function setHello($var) |
||
248 | { |
||
249 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\GossipHello::class); |
||
250 | $this->writeOneof(9, $var); |
||
251 | |||
252 | return $this; |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * Generated from protobuf field <code>.gossip.DataDigest data_dig = 10;</code> |
||
257 | * @return \Hyperledger\Fabric\Protos\Gossip\DataDigest |
||
258 | */ |
||
259 | public function getDataDig() |
||
260 | { |
||
261 | return $this->readOneof(10); |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * Generated from protobuf field <code>.gossip.DataDigest data_dig = 10;</code> |
||
266 | * @param \Hyperledger\Fabric\Protos\Gossip\DataDigest $var |
||
267 | * @return $this |
||
268 | */ |
||
269 | public function setDataDig($var) |
||
270 | { |
||
271 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\DataDigest::class); |
||
272 | $this->writeOneof(10, $var); |
||
273 | |||
274 | return $this; |
||
275 | } |
||
276 | |||
277 | /** |
||
278 | * Generated from protobuf field <code>.gossip.DataRequest data_req = 11;</code> |
||
279 | * @return \Hyperledger\Fabric\Protos\Gossip\DataRequest |
||
280 | */ |
||
281 | public function getDataReq() |
||
282 | { |
||
283 | return $this->readOneof(11); |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * Generated from protobuf field <code>.gossip.DataRequest data_req = 11;</code> |
||
288 | * @param \Hyperledger\Fabric\Protos\Gossip\DataRequest $var |
||
289 | * @return $this |
||
290 | */ |
||
291 | public function setDataReq($var) |
||
292 | { |
||
293 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\DataRequest::class); |
||
294 | $this->writeOneof(11, $var); |
||
295 | |||
296 | return $this; |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * Generated from protobuf field <code>.gossip.DataUpdate data_update = 12;</code> |
||
301 | * @return \Hyperledger\Fabric\Protos\Gossip\DataUpdate |
||
302 | */ |
||
303 | public function getDataUpdate() |
||
304 | { |
||
305 | return $this->readOneof(12); |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * Generated from protobuf field <code>.gossip.DataUpdate data_update = 12;</code> |
||
310 | * @param \Hyperledger\Fabric\Protos\Gossip\DataUpdate $var |
||
311 | * @return $this |
||
312 | */ |
||
313 | public function setDataUpdate($var) |
||
314 | { |
||
315 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\DataUpdate::class); |
||
316 | $this->writeOneof(12, $var); |
||
317 | |||
318 | return $this; |
||
319 | } |
||
320 | |||
321 | /** |
||
322 | * Empty message, used for pinging |
||
323 | * |
||
324 | * Generated from protobuf field <code>.gossip.Empty empty = 13;</code> |
||
325 | * @return \Hyperledger\Fabric\Protos\Gossip\PBEmpty |
||
326 | */ |
||
327 | public function getEmpty() |
||
328 | { |
||
329 | return $this->readOneof(13); |
||
330 | } |
||
331 | |||
332 | /** |
||
333 | * Empty message, used for pinging |
||
334 | * |
||
335 | * Generated from protobuf field <code>.gossip.Empty empty = 13;</code> |
||
336 | * @param \Hyperledger\Fabric\Protos\Gossip\PBEmpty $var |
||
337 | * @return $this |
||
338 | */ |
||
339 | public function setEmpty($var) |
||
340 | { |
||
341 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\PBEmpty::class); |
||
342 | $this->writeOneof(13, $var); |
||
343 | |||
344 | return $this; |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * ConnEstablish, used for establishing a connection |
||
349 | * |
||
350 | * Generated from protobuf field <code>.gossip.ConnEstablish conn = 14;</code> |
||
351 | * @return \Hyperledger\Fabric\Protos\Gossip\ConnEstablish |
||
352 | */ |
||
353 | public function getConn() |
||
354 | { |
||
355 | return $this->readOneof(14); |
||
356 | } |
||
357 | |||
358 | /** |
||
359 | * ConnEstablish, used for establishing a connection |
||
360 | * |
||
361 | * Generated from protobuf field <code>.gossip.ConnEstablish conn = 14;</code> |
||
362 | * @param \Hyperledger\Fabric\Protos\Gossip\ConnEstablish $var |
||
363 | * @return $this |
||
364 | */ |
||
365 | public function setConn($var) |
||
366 | { |
||
367 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\ConnEstablish::class); |
||
368 | $this->writeOneof(14, $var); |
||
369 | |||
370 | return $this; |
||
371 | } |
||
372 | |||
373 | /** |
||
374 | * Used for relaying information |
||
375 | * about state |
||
376 | * |
||
377 | * Generated from protobuf field <code>.gossip.StateInfo state_info = 15;</code> |
||
378 | * @return \Hyperledger\Fabric\Protos\Gossip\StateInfo |
||
379 | */ |
||
380 | public function getStateInfo() |
||
381 | { |
||
382 | return $this->readOneof(15); |
||
383 | } |
||
384 | |||
385 | /** |
||
386 | * Used for relaying information |
||
387 | * about state |
||
388 | * |
||
389 | * Generated from protobuf field <code>.gossip.StateInfo state_info = 15;</code> |
||
390 | * @param \Hyperledger\Fabric\Protos\Gossip\StateInfo $var |
||
391 | * @return $this |
||
392 | */ |
||
393 | public function setStateInfo($var) |
||
394 | { |
||
395 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\StateInfo::class); |
||
396 | $this->writeOneof(15, $var); |
||
397 | |||
398 | return $this; |
||
399 | } |
||
400 | |||
401 | /** |
||
402 | * Used for sending sets of StateInfo messages |
||
403 | * |
||
404 | * Generated from protobuf field <code>.gossip.StateInfoSnapshot state_snapshot = 16;</code> |
||
405 | * @return \Hyperledger\Fabric\Protos\Gossip\StateInfoSnapshot |
||
406 | */ |
||
407 | public function getStateSnapshot() |
||
408 | { |
||
409 | return $this->readOneof(16); |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * Used for sending sets of StateInfo messages |
||
414 | * |
||
415 | * Generated from protobuf field <code>.gossip.StateInfoSnapshot state_snapshot = 16;</code> |
||
416 | * @param \Hyperledger\Fabric\Protos\Gossip\StateInfoSnapshot $var |
||
417 | * @return $this |
||
418 | */ |
||
419 | public function setStateSnapshot($var) |
||
420 | { |
||
421 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\StateInfoSnapshot::class); |
||
422 | $this->writeOneof(16, $var); |
||
423 | |||
424 | return $this; |
||
425 | } |
||
426 | |||
427 | /** |
||
428 | * Used for asking for StateInfoSnapshots |
||
429 | * |
||
430 | * Generated from protobuf field <code>.gossip.StateInfoPullRequest state_info_pull_req = 17;</code> |
||
431 | * @return \Hyperledger\Fabric\Protos\Gossip\StateInfoPullRequest |
||
432 | */ |
||
433 | public function getStateInfoPullReq() |
||
434 | { |
||
435 | return $this->readOneof(17); |
||
436 | } |
||
437 | |||
438 | /** |
||
439 | * Used for asking for StateInfoSnapshots |
||
440 | * |
||
441 | * Generated from protobuf field <code>.gossip.StateInfoPullRequest state_info_pull_req = 17;</code> |
||
442 | * @param \Hyperledger\Fabric\Protos\Gossip\StateInfoPullRequest $var |
||
443 | * @return $this |
||
444 | */ |
||
445 | public function setStateInfoPullReq($var) |
||
446 | { |
||
447 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\StateInfoPullRequest::class); |
||
448 | $this->writeOneof(17, $var); |
||
449 | |||
450 | return $this; |
||
451 | } |
||
452 | |||
453 | /** |
||
454 | * Used to ask from a remote peer a set of blocks |
||
455 | * |
||
456 | * Generated from protobuf field <code>.gossip.RemoteStateRequest state_request = 18;</code> |
||
457 | * @return \Hyperledger\Fabric\Protos\Gossip\RemoteStateRequest |
||
458 | */ |
||
459 | public function getStateRequest() |
||
460 | { |
||
461 | return $this->readOneof(18); |
||
462 | } |
||
463 | |||
464 | /** |
||
465 | * Used to ask from a remote peer a set of blocks |
||
466 | * |
||
467 | * Generated from protobuf field <code>.gossip.RemoteStateRequest state_request = 18;</code> |
||
468 | * @param \Hyperledger\Fabric\Protos\Gossip\RemoteStateRequest $var |
||
469 | * @return $this |
||
470 | */ |
||
471 | public function setStateRequest($var) |
||
472 | { |
||
473 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\RemoteStateRequest::class); |
||
474 | $this->writeOneof(18, $var); |
||
475 | |||
476 | return $this; |
||
477 | } |
||
478 | |||
479 | /** |
||
480 | * Used to send a set of blocks to a remote peer |
||
481 | * |
||
482 | * Generated from protobuf field <code>.gossip.RemoteStateResponse state_response = 19;</code> |
||
483 | * @return \Hyperledger\Fabric\Protos\Gossip\RemoteStateResponse |
||
484 | */ |
||
485 | public function getStateResponse() |
||
486 | { |
||
487 | return $this->readOneof(19); |
||
488 | } |
||
489 | |||
490 | /** |
||
491 | * Used to send a set of blocks to a remote peer |
||
492 | * |
||
493 | * Generated from protobuf field <code>.gossip.RemoteStateResponse state_response = 19;</code> |
||
494 | * @param \Hyperledger\Fabric\Protos\Gossip\RemoteStateResponse $var |
||
495 | * @return $this |
||
496 | */ |
||
497 | public function setStateResponse($var) |
||
498 | { |
||
499 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\RemoteStateResponse::class); |
||
500 | $this->writeOneof(19, $var); |
||
501 | |||
502 | return $this; |
||
503 | } |
||
504 | |||
505 | /** |
||
506 | * Used to indicate intent of peer to become leader |
||
507 | * |
||
508 | * Generated from protobuf field <code>.gossip.LeadershipMessage leadership_msg = 20;</code> |
||
509 | * @return \Hyperledger\Fabric\Protos\Gossip\LeadershipMessage |
||
510 | */ |
||
511 | public function getLeadershipMsg() |
||
512 | { |
||
513 | return $this->readOneof(20); |
||
514 | } |
||
515 | |||
516 | /** |
||
517 | * Used to indicate intent of peer to become leader |
||
518 | * |
||
519 | * Generated from protobuf field <code>.gossip.LeadershipMessage leadership_msg = 20;</code> |
||
520 | * @param \Hyperledger\Fabric\Protos\Gossip\LeadershipMessage $var |
||
521 | * @return $this |
||
522 | */ |
||
523 | public function setLeadershipMsg($var) |
||
524 | { |
||
525 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\LeadershipMessage::class); |
||
526 | $this->writeOneof(20, $var); |
||
527 | |||
528 | return $this; |
||
529 | } |
||
530 | |||
531 | /** |
||
532 | * Used to learn of a peer's certificate |
||
533 | * |
||
534 | * Generated from protobuf field <code>.gossip.PeerIdentity peer_identity = 21;</code> |
||
535 | * @return \Hyperledger\Fabric\Protos\Gossip\PeerIdentity |
||
536 | */ |
||
537 | public function getPeerIdentity() |
||
538 | { |
||
539 | return $this->readOneof(21); |
||
540 | } |
||
541 | |||
542 | /** |
||
543 | * Used to learn of a peer's certificate |
||
544 | * |
||
545 | * Generated from protobuf field <code>.gossip.PeerIdentity peer_identity = 21;</code> |
||
546 | * @param \Hyperledger\Fabric\Protos\Gossip\PeerIdentity $var |
||
547 | * @return $this |
||
548 | */ |
||
549 | public function setPeerIdentity($var) |
||
550 | { |
||
551 | GPBUtil::checkMessage($var, \Hyperledger\Fabric\Protos\Gossip\PeerIdentity::class); |
||
552 | $this->writeOneof(21, $var); |
||
553 | |||
554 | return $this; |
||
555 | } |
||
556 | |||
557 | /** |
||
558 | * @return string |
||
559 | */ |
||
560 | public function getContent() |
||
561 | { |
||
562 | return $this->whichOneof("content"); |
||
563 | } |
||
567 |