Complex classes like Peer 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Peer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
29 | class Peer extends EventEmitter |
||
30 | { |
||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $buffer = ''; |
||
35 | |||
36 | /** |
||
37 | * @var LoopInterface |
||
38 | */ |
||
39 | private $loop; |
||
40 | |||
41 | /** |
||
42 | * @var \BitWasp\Bitcoin\Networking\Messages\Factory |
||
43 | */ |
||
44 | private $msgs; |
||
45 | |||
46 | /** |
||
47 | * @var Stream |
||
48 | */ |
||
49 | private $stream; |
||
50 | |||
51 | /** |
||
52 | * @var Version |
||
53 | */ |
||
54 | private $localVersion; |
||
55 | |||
56 | /** |
||
57 | * @var Version |
||
58 | */ |
||
59 | private $remoteVersion; |
||
60 | |||
61 | /** |
||
62 | * @var NetworkAddressInterface |
||
63 | */ |
||
64 | private $peerAddress; |
||
65 | |||
66 | /** |
||
67 | * @var ConnectionParams |
||
68 | */ |
||
69 | private $connectionParams; |
||
70 | |||
71 | /** |
||
72 | * @var bool |
||
73 | */ |
||
74 | private $exchangedVersion = false; |
||
75 | |||
76 | /** |
||
77 | * @var Header |
||
78 | */ |
||
79 | private $incomingMsgHeader; |
||
80 | 12 | ||
81 | /** |
||
82 | 12 | * @param \BitWasp\Bitcoin\Networking\Messages\Factory $msgs |
|
83 | 12 | * @param LoopInterface $loop |
|
84 | 12 | */ |
|
85 | public function __construct(\BitWasp\Bitcoin\Networking\Messages\Factory $msgs, LoopInterface $loop) |
||
90 | |||
91 | 3 | /** |
|
92 | * @return Version |
||
93 | */ |
||
94 | public function getLocalVersion() |
||
98 | |||
99 | 3 | /** |
|
100 | * @return Version |
||
101 | */ |
||
102 | public function getRemoteVersion() |
||
106 | |||
107 | /** |
||
108 | * Reliably returns the remote peers NetAddr when known through |
||
109 | 3 | * the connection process. Often better than the data contained |
|
110 | * in a Version message. |
||
111 | 3 | * |
|
112 | * @return NetworkAddressInterface |
||
113 | */ |
||
114 | public function getRemoteAddress() |
||
118 | |||
119 | 3 | /** |
|
120 | * @return ConnectionParams |
||
121 | */ |
||
122 | public function getConnectionParams() |
||
126 | |||
127 | 12 | /** |
|
128 | 12 | * @param NetworkSerializable $msg |
|
129 | 12 | */ |
|
130 | 12 | public function send(NetworkSerializable $msg) |
|
137 | |||
138 | 12 | /** |
|
139 | 12 | * @param Stream $stream |
|
140 | * @return $this |
||
141 | */ |
||
142 | 12 | public function setupStream(Stream $stream) |
|
191 | 9 | ||
192 | 9 | /** |
|
193 | 9 | * @param Stream $connection |
|
194 | 9 | * @param ConnectionParams $params |
|
195 | 9 | * @return \React\Promise\Promise|\React\Promise\PromiseInterface |
|
196 | */ |
||
197 | public function inboundHandshake(Stream $connection, ConnectionParams $params) |
||
220 | |||
221 | 6 | /** |
|
222 | 6 | * @param NetworkAddressInterface $remotePeer |
|
223 | 6 | * @param ConnectionParams $params |
|
224 | 4 | * @return \React\Promise\Promise|\React\Promise\PromiseInterface |
|
225 | 12 | */ |
|
226 | public function outboundHandshake(NetworkAddressInterface $remotePeer, ConnectionParams $params) |
||
259 | |||
260 | /** |
||
261 | 9 | * |
|
262 | */ |
||
263 | 9 | public function intentionalClose() |
|
268 | |||
269 | /** |
||
270 | * |
||
271 | */ |
||
272 | public function close() |
||
278 | |||
279 | /** |
||
280 | * @param int $protocolVersion |
||
281 | * @param int $services |
||
282 | * @param int $timestamp |
||
283 | * @param NetworkAddressInterface $remoteAddr |
||
284 | * @param NetworkAddressInterface $localAddr |
||
285 | * @param string $userAgent |
||
286 | * @param int $blockHeight |
||
287 | * @param bool $relayToUs |
||
288 | */ |
||
289 | public function version( |
||
310 | |||
311 | /** |
||
312 | * |
||
313 | */ |
||
314 | public function verack() |
||
318 | |||
319 | /** |
||
320 | * |
||
321 | */ |
||
322 | public function sendheaders() |
||
326 | |||
327 | /** |
||
328 | * @param Inventory[] $vInv |
||
329 | */ |
||
330 | public function inv(array $vInv) |
||
334 | |||
335 | /** |
||
336 | * @param Inventory[] $vInv |
||
337 | */ |
||
338 | public function getdata(array $vInv) |
||
342 | |||
343 | /** |
||
344 | * @param array $vInv |
||
345 | */ |
||
346 | public function notfound(array $vInv) |
||
350 | |||
351 | /** |
||
352 | * @param NetworkAddressTimestamp[] $vNetAddr |
||
353 | */ |
||
354 | public function addr(array $vNetAddr) |
||
358 | |||
359 | /** |
||
360 | * |
||
361 | */ |
||
362 | public function getaddr() |
||
366 | |||
367 | /** |
||
368 | * |
||
369 | */ |
||
370 | public function ping() |
||
374 | |||
375 | /** |
||
376 | * @param Ping $ping |
||
377 | */ |
||
378 | public function pong(Ping $ping) |
||
382 | |||
383 | /** |
||
384 | * @param TransactionInterface $tx |
||
385 | */ |
||
386 | public function tx(TransactionInterface $tx) |
||
390 | |||
391 | /** |
||
392 | * @param BlockLocator $locator |
||
393 | */ |
||
394 | public function getblocks(BlockLocator $locator) |
||
401 | |||
402 | /** |
||
403 | * @param BlockLocator $locator |
||
404 | */ |
||
405 | public function getheaders(BlockLocator $locator) |
||
412 | |||
413 | /** |
||
414 | * @param BlockInterface $block |
||
415 | */ |
||
416 | public function block(BlockInterface $block) |
||
420 | |||
421 | /** |
||
422 | * @param array $vHeaders |
||
423 | */ |
||
424 | public function headers(array $vHeaders) |
||
428 | |||
429 | /** |
||
430 | * @param AlertDetail $detail |
||
431 | * @param SignatureInterface $signature |
||
432 | */ |
||
433 | public function alert(AlertDetail $detail, SignatureInterface $signature) |
||
437 | |||
438 | /** |
||
439 | * @param int $feeRate |
||
440 | */ |
||
441 | public function feefilter($feeRate) |
||
445 | |||
446 | /** |
||
447 | * @param BufferInterface $data |
||
448 | */ |
||
449 | public function filteradd(BufferInterface $data) |
||
453 | |||
454 | /** |
||
455 | * @param BloomFilter $filter |
||
456 | */ |
||
457 | public function filterload(BloomFilter $filter) |
||
461 | |||
462 | /** |
||
463 | * |
||
464 | */ |
||
465 | public function filterclear() |
||
469 | |||
470 | /** |
||
471 | * @param FilteredBlock $filtered |
||
472 | */ |
||
473 | public function merkleblock(FilteredBlock $filtered) |
||
477 | |||
478 | /** |
||
479 | * |
||
480 | */ |
||
481 | public function mempool() |
||
485 | |||
486 | /** |
||
487 | * Issue a Reject message, with a required $msg, $code, and $reason |
||
488 | * |
||
489 | * @param BufferInterface $msg |
||
490 | * @param int $code |
||
491 | * @param BufferInterface $reason |
||
492 | * @param BufferInterface $data |
||
493 | */ |
||
494 | public function reject(BufferInterface $msg, $code, BufferInterface $reason, BufferInterface $data = null) |
||
498 | } |
||
499 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.