Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Protocol080 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 Protocol080, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class Protocol080 |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @return array |
||
15 | */ |
||
16 | public function connectionStart($version_major = 0, $version_minor = 8, $server_properties, $mechanisms = 'PLAIN', $locales = 'en_US') |
||
26 | |||
27 | |||
28 | |||
29 | /** |
||
30 | * @param AMQPReader $args |
||
31 | * @return array |
||
32 | */ |
||
33 | View Code Duplication | public static function connectionStartOk($args) |
|
42 | |||
43 | |||
44 | |||
45 | /** |
||
46 | * @return array |
||
47 | */ |
||
48 | public function connectionSecure($challenge) |
||
54 | |||
55 | |||
56 | |||
57 | /** |
||
58 | * @param AMQPReader $args |
||
59 | * @return array |
||
60 | */ |
||
61 | public static function connectionSecureOk($args) |
||
67 | |||
68 | |||
69 | |||
70 | /** |
||
71 | * @return array |
||
72 | */ |
||
73 | View Code Duplication | public function connectionTune($channel_max = 0, $frame_max = 0, $heartbeat = 0) |
|
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * @param AMQPReader $args |
||
86 | * @return array |
||
87 | */ |
||
88 | View Code Duplication | public static function connectionTuneOk($args) |
|
96 | |||
97 | |||
98 | |||
99 | /** |
||
100 | * @return array |
||
101 | */ |
||
102 | View Code Duplication | public function connectionOpen($virtual_host = '/', $capabilities = '', $insist = false) |
|
110 | |||
111 | |||
112 | |||
113 | /** |
||
114 | * @param AMQPReader $args |
||
115 | * @return array |
||
116 | */ |
||
117 | public static function connectionOpenOk($args) |
||
123 | |||
124 | |||
125 | |||
126 | /** |
||
127 | * @return array |
||
128 | */ |
||
129 | public function connectionRedirect($host, $known_hosts = '') |
||
136 | |||
137 | |||
138 | |||
139 | /** |
||
140 | * @return array |
||
141 | */ |
||
142 | View Code Duplication | public function connectionClose($reply_code, $reply_text = '', $class_id, $method_id) |
|
151 | |||
152 | |||
153 | |||
154 | /** |
||
155 | * @param AMQPReader $args |
||
156 | * @return array |
||
157 | */ |
||
158 | public static function connectionCloseOk($args) |
||
163 | |||
164 | |||
165 | |||
166 | /** |
||
167 | * @return array |
||
168 | */ |
||
169 | public function channelOpen($out_of_band = '') |
||
175 | |||
176 | |||
177 | |||
178 | /** |
||
179 | * @param AMQPReader $args |
||
180 | * @return array |
||
181 | */ |
||
182 | public static function channelOpenOk($args) |
||
187 | |||
188 | |||
189 | |||
190 | /** |
||
191 | * @return array |
||
192 | */ |
||
193 | public function channelFlow($active) |
||
199 | |||
200 | |||
201 | |||
202 | /** |
||
203 | * @param AMQPReader $args |
||
204 | * @return array |
||
205 | */ |
||
206 | public static function channelFlowOk($args) |
||
212 | |||
213 | |||
214 | |||
215 | /** |
||
216 | * @return array |
||
217 | */ |
||
218 | public function channelAlert($reply_code, $reply_text = '', $details = array()) |
||
226 | |||
227 | |||
228 | |||
229 | /** |
||
230 | * @return array |
||
231 | */ |
||
232 | View Code Duplication | public function channelClose($reply_code, $reply_text = '', $class_id, $method_id) |
|
241 | |||
242 | |||
243 | |||
244 | /** |
||
245 | * @param AMQPReader $args |
||
246 | * @return array |
||
247 | */ |
||
248 | public static function channelCloseOk($args) |
||
253 | |||
254 | |||
255 | |||
256 | /** |
||
257 | * @return array |
||
258 | */ |
||
259 | View Code Duplication | public function accessRequest($realm = '/data', $exclusive = false, $passive = true, $active = true, $write = true, $read = true) |
|
266 | |||
267 | |||
268 | |||
269 | /** |
||
270 | * @param AMQPReader $args |
||
271 | * @return array |
||
272 | */ |
||
273 | public static function accessRequestOk($args) |
||
279 | |||
280 | |||
281 | |||
282 | /** |
||
283 | * @return array |
||
284 | */ |
||
285 | View Code Duplication | public function exchangeDeclare($ticket = 1, $exchange, $type = 'direct', $passive = false, $durable = false, $auto_delete = false, $internal = false, $nowait = false, $arguments = array()) |
|
295 | |||
296 | |||
297 | |||
298 | /** |
||
299 | * @param AMQPReader $args |
||
300 | * @return array |
||
301 | */ |
||
302 | public static function exchangeDeclareOk($args) |
||
307 | |||
308 | |||
309 | |||
310 | /** |
||
311 | * @return array |
||
312 | */ |
||
313 | public function exchangeDelete($ticket = 1, $exchange, $if_unused = false, $nowait = false) |
||
321 | |||
322 | |||
323 | |||
324 | /** |
||
325 | * @param AMQPReader $args |
||
326 | * @return array |
||
327 | */ |
||
328 | public static function exchangeDeleteOk($args) |
||
333 | |||
334 | |||
335 | |||
336 | /** |
||
337 | * @return array |
||
338 | */ |
||
339 | View Code Duplication | public function queueDeclare($ticket = 1, $queue = '', $passive = false, $durable = false, $exclusive = false, $auto_delete = false, $nowait = false, $arguments = array()) |
|
348 | |||
349 | |||
350 | |||
351 | /** |
||
352 | * @param AMQPReader $args |
||
353 | * @return array |
||
354 | */ |
||
355 | View Code Duplication | public static function queueDeclareOk($args) |
|
363 | |||
364 | |||
365 | |||
366 | /** |
||
367 | * @return array |
||
368 | */ |
||
369 | View Code Duplication | public function queueBind($ticket = 1, $queue = '', $exchange, $routing_key = '', $nowait = false, $arguments = array()) |
|
380 | |||
381 | |||
382 | |||
383 | /** |
||
384 | * @param AMQPReader $args |
||
385 | * @return array |
||
386 | */ |
||
387 | public static function queueBindOk($args) |
||
392 | |||
393 | |||
394 | |||
395 | /** |
||
396 | * @return array |
||
397 | */ |
||
398 | View Code Duplication | public function queuePurge($ticket = 1, $queue = '', $nowait = false) |
|
406 | |||
407 | |||
408 | |||
409 | /** |
||
410 | * @param AMQPReader $args |
||
411 | * @return array |
||
412 | */ |
||
413 | public static function queuePurgeOk($args) |
||
419 | |||
420 | |||
421 | |||
422 | /** |
||
423 | * @return array |
||
424 | */ |
||
425 | public function queueDelete($ticket = 1, $queue = '', $if_unused = false, $if_empty = false, $nowait = false) |
||
433 | |||
434 | |||
435 | |||
436 | /** |
||
437 | * @param AMQPReader $args |
||
438 | * @return array |
||
439 | */ |
||
440 | public static function queueDeleteOk($args) |
||
446 | |||
447 | |||
448 | |||
449 | /** |
||
450 | * @return array |
||
451 | */ |
||
452 | View Code Duplication | public function queueUnbind($ticket = 1, $queue = '', $exchange, $routing_key = '', $arguments = array()) |
|
462 | |||
463 | |||
464 | |||
465 | /** |
||
466 | * @param AMQPReader $args |
||
467 | * @return array |
||
468 | */ |
||
469 | public static function queueUnbindOk($args) |
||
474 | |||
475 | |||
476 | |||
477 | /** |
||
478 | * @return array |
||
479 | */ |
||
480 | View Code Duplication | public function basicQos($prefetch_size = 0, $prefetch_count = 0, $global = false) |
|
488 | |||
489 | |||
490 | |||
491 | /** |
||
492 | * @param AMQPReader $args |
||
493 | * @return array |
||
494 | */ |
||
495 | public static function basicQosOk($args) |
||
500 | |||
501 | |||
502 | |||
503 | /** |
||
504 | * @return array |
||
505 | */ |
||
506 | public function basicConsume($ticket = 1, $queue = '', $consumer_tag = '', $no_local = false, $no_ack = false, $exclusive = false, $nowait = false) |
||
515 | |||
516 | |||
517 | |||
518 | /** |
||
519 | * @param AMQPReader $args |
||
520 | * @return array |
||
521 | */ |
||
522 | public static function basicConsumeOk($args) |
||
528 | |||
529 | |||
530 | |||
531 | /** |
||
532 | * @return array |
||
533 | */ |
||
534 | View Code Duplication | public function basicCancel($consumer_tag, $nowait = false) |
|
541 | |||
542 | |||
543 | |||
544 | /** |
||
545 | * @param AMQPReader $args |
||
546 | * @return array |
||
547 | */ |
||
548 | public static function basicCancelOk($args) |
||
554 | |||
555 | |||
556 | |||
557 | /** |
||
558 | * @return array |
||
559 | */ |
||
560 | View Code Duplication | public function basicPublish($ticket = 1, $exchange = '', $routing_key = '', $mandatory = false, $immediate = false) |
|
569 | |||
570 | |||
571 | |||
572 | /** |
||
573 | * @return array |
||
574 | */ |
||
575 | View Code Duplication | public function basicReturn($reply_code, $reply_text = '', $exchange, $routing_key) |
|
584 | |||
585 | |||
586 | |||
587 | /** |
||
588 | * @return array |
||
589 | */ |
||
590 | View Code Duplication | public function basicDeliver($consumer_tag, $delivery_tag, $redelivered = false, $exchange, $routing_key) |
|
600 | |||
601 | |||
602 | |||
603 | /** |
||
604 | * @return array |
||
605 | */ |
||
606 | public function basicGet($ticket = 1, $queue = '', $no_ack = false) |
||
614 | |||
615 | |||
616 | |||
617 | /** |
||
618 | * @param AMQPReader $args |
||
619 | * @return array |
||
620 | */ |
||
621 | View Code Duplication | public static function basicGetOk($args) |
|
631 | |||
632 | |||
633 | |||
634 | /** |
||
635 | * @param AMQPReader $args |
||
636 | * @return array |
||
637 | */ |
||
638 | public static function basicGetEmpty($args) |
||
644 | |||
645 | |||
646 | |||
647 | /** |
||
648 | * @return array |
||
649 | */ |
||
650 | View Code Duplication | public function basicAck($delivery_tag = 0, $multiple = false) |
|
657 | |||
658 | |||
659 | |||
660 | /** |
||
661 | * @return array |
||
662 | */ |
||
663 | View Code Duplication | public function basicReject($delivery_tag, $requeue = true) |
|
670 | |||
671 | |||
672 | |||
673 | /** |
||
674 | * @return array |
||
675 | */ |
||
676 | public function basicRecoverAsync($requeue = false) |
||
682 | |||
683 | |||
684 | |||
685 | /** |
||
686 | * @return array |
||
687 | */ |
||
688 | public function basicRecover($requeue = false) |
||
694 | |||
695 | |||
696 | |||
697 | /** |
||
698 | * @param AMQPReader $args |
||
699 | * @return array |
||
700 | */ |
||
701 | public static function basicRecoverOk($args) |
||
706 | |||
707 | |||
708 | |||
709 | /** |
||
710 | * @return array |
||
711 | */ |
||
712 | View Code Duplication | public function fileQos($prefetch_size = 0, $prefetch_count = 0, $global = false) |
|
720 | |||
721 | |||
722 | |||
723 | /** |
||
724 | * @param AMQPReader $args |
||
725 | * @return array |
||
726 | */ |
||
727 | public static function fileQosOk($args) |
||
732 | |||
733 | |||
734 | |||
735 | /** |
||
736 | * @return array |
||
737 | */ |
||
738 | public function fileConsume($ticket = 1, $queue = '', $consumer_tag = '', $no_local = false, $no_ack = false, $exclusive = false, $nowait = false) |
||
747 | |||
748 | |||
749 | |||
750 | /** |
||
751 | * @param AMQPReader $args |
||
752 | * @return array |
||
753 | */ |
||
754 | public static function fileConsumeOk($args) |
||
760 | |||
761 | |||
762 | |||
763 | /** |
||
764 | * @return array |
||
765 | */ |
||
766 | View Code Duplication | public function fileCancel($consumer_tag, $nowait = false) |
|
773 | |||
774 | |||
775 | |||
776 | /** |
||
777 | * @param AMQPReader $args |
||
778 | * @return array |
||
779 | */ |
||
780 | public static function fileCancelOk($args) |
||
786 | |||
787 | |||
788 | |||
789 | /** |
||
790 | * @return array |
||
791 | */ |
||
792 | public function fileOpen($identifier, $content_size) |
||
799 | |||
800 | |||
801 | |||
802 | /** |
||
803 | * @param AMQPReader $args |
||
804 | * @return array |
||
805 | */ |
||
806 | public static function fileOpenOk($args) |
||
812 | |||
813 | |||
814 | |||
815 | /** |
||
816 | * @return array |
||
817 | */ |
||
818 | public function fileStage() |
||
823 | |||
824 | |||
825 | |||
826 | /** |
||
827 | * @return array |
||
828 | */ |
||
829 | View Code Duplication | public function filePublish($ticket = 1, $exchange = '', $routing_key = '', $mandatory = false, $immediate = false, $identifier) |
|
839 | |||
840 | |||
841 | |||
842 | /** |
||
843 | * @return array |
||
844 | */ |
||
845 | View Code Duplication | public function fileReturn($reply_code = 200, $reply_text = '', $exchange, $routing_key) |
|
854 | |||
855 | |||
856 | |||
857 | /** |
||
858 | * @return array |
||
859 | */ |
||
860 | View Code Duplication | public function fileDeliver($consumer_tag, $delivery_tag, $redelivered = false, $exchange, $routing_key, $identifier) |
|
871 | |||
872 | |||
873 | |||
874 | /** |
||
875 | * @return array |
||
876 | */ |
||
877 | View Code Duplication | public function fileAck($delivery_tag = 0, $multiple = false) |
|
884 | |||
885 | |||
886 | |||
887 | /** |
||
888 | * @return array |
||
889 | */ |
||
890 | View Code Duplication | public function fileReject($delivery_tag, $requeue = true) |
|
897 | |||
898 | |||
899 | |||
900 | /** |
||
901 | * @return array |
||
902 | */ |
||
903 | View Code Duplication | public function streamQos($prefetch_size = 0, $prefetch_count = 0, $consume_rate = 0, $global = false) |
|
912 | |||
913 | |||
914 | |||
915 | /** |
||
916 | * @param AMQPReader $args |
||
917 | * @return array |
||
918 | */ |
||
919 | public static function streamQosOk($args) |
||
924 | |||
925 | |||
926 | |||
927 | /** |
||
928 | * @return array |
||
929 | */ |
||
930 | View Code Duplication | public function streamConsume($ticket = 1, $queue = '', $consumer_tag = '', $no_local = false, $exclusive = false, $nowait = false) |
|
939 | |||
940 | |||
941 | |||
942 | /** |
||
943 | * @param AMQPReader $args |
||
944 | * @return array |
||
945 | */ |
||
946 | public static function streamConsumeOk($args) |
||
952 | |||
953 | |||
954 | |||
955 | /** |
||
956 | * @return array |
||
957 | */ |
||
958 | View Code Duplication | public function streamCancel($consumer_tag, $nowait = false) |
|
965 | |||
966 | |||
967 | |||
968 | /** |
||
969 | * @param AMQPReader $args |
||
970 | * @return array |
||
971 | */ |
||
972 | public static function streamCancelOk($args) |
||
978 | |||
979 | |||
980 | |||
981 | /** |
||
982 | * @return array |
||
983 | */ |
||
984 | View Code Duplication | public function streamPublish($ticket = 1, $exchange = '', $routing_key = '', $mandatory = false, $immediate = false) |
|
993 | |||
994 | |||
995 | |||
996 | /** |
||
997 | * @return array |
||
998 | */ |
||
999 | View Code Duplication | public function streamReturn($reply_code = 200, $reply_text = '', $exchange, $routing_key) |
|
1008 | |||
1009 | |||
1010 | |||
1011 | /** |
||
1012 | * @return array |
||
1013 | */ |
||
1014 | public function streamDeliver($consumer_tag, $delivery_tag, $exchange, $queue) |
||
1023 | |||
1024 | |||
1025 | |||
1026 | /** |
||
1027 | * @return array |
||
1028 | */ |
||
1029 | public function txSelect() |
||
1034 | |||
1035 | |||
1036 | |||
1037 | /** |
||
1038 | * @param AMQPReader $args |
||
1039 | * @return array |
||
1040 | */ |
||
1041 | public static function txSelectOk($args) |
||
1046 | |||
1047 | |||
1048 | |||
1049 | /** |
||
1050 | * @return array |
||
1051 | */ |
||
1052 | public function txCommit() |
||
1057 | |||
1058 | |||
1059 | |||
1060 | /** |
||
1061 | * @param AMQPReader $args |
||
1062 | * @return array |
||
1063 | */ |
||
1064 | public static function txCommitOk($args) |
||
1069 | |||
1070 | |||
1071 | |||
1072 | /** |
||
1073 | * @return array |
||
1074 | */ |
||
1075 | public function txRollback() |
||
1080 | |||
1081 | |||
1082 | |||
1083 | /** |
||
1084 | * @param AMQPReader $args |
||
1085 | * @return array |
||
1086 | */ |
||
1087 | public static function txRollbackOk($args) |
||
1092 | |||
1093 | |||
1094 | |||
1095 | /** |
||
1096 | * @return array |
||
1097 | */ |
||
1098 | public function dtxSelect() |
||
1103 | |||
1104 | |||
1105 | |||
1106 | /** |
||
1107 | * @param AMQPReader $args |
||
1108 | * @return array |
||
1109 | */ |
||
1110 | public static function dtxSelectOk($args) |
||
1115 | |||
1116 | |||
1117 | |||
1118 | /** |
||
1119 | * @return array |
||
1120 | */ |
||
1121 | public function dtxStart($dtx_identifier) |
||
1127 | |||
1128 | |||
1129 | |||
1130 | /** |
||
1131 | * @param AMQPReader $args |
||
1132 | * @return array |
||
1133 | */ |
||
1134 | public static function dtxStartOk($args) |
||
1139 | |||
1140 | |||
1141 | |||
1142 | /** |
||
1143 | * @return array |
||
1144 | */ |
||
1145 | public function tunnelRequest($meta_data) |
||
1151 | |||
1152 | |||
1153 | |||
1154 | /** |
||
1155 | * @return array |
||
1156 | */ |
||
1157 | public function testInteger($integer_1, $integer_2, $integer_3, $integer_4, $operation) |
||
1167 | |||
1168 | |||
1169 | |||
1170 | /** |
||
1171 | * @param AMQPReader $args |
||
1172 | * @return array |
||
1173 | */ |
||
1174 | public static function testIntegerOk($args) |
||
1180 | |||
1181 | |||
1182 | |||
1183 | /** |
||
1184 | * @return array |
||
1185 | */ |
||
1186 | public function testString($string_1, $string_2, $operation) |
||
1194 | |||
1195 | |||
1196 | |||
1197 | /** |
||
1198 | * @param AMQPReader $args |
||
1199 | * @return array |
||
1200 | */ |
||
1201 | public static function testStringOk($args) |
||
1207 | |||
1208 | |||
1209 | |||
1210 | /** |
||
1211 | * @return array |
||
1212 | */ |
||
1213 | public function testTable($table, $integer_op, $string_op) |
||
1221 | |||
1222 | |||
1223 | |||
1224 | /** |
||
1225 | * @param AMQPReader $args |
||
1226 | * @return array |
||
1227 | */ |
||
1228 | public static function testTableOk($args) |
||
1235 | |||
1236 | |||
1237 | |||
1238 | /** |
||
1239 | * @return array |
||
1240 | */ |
||
1241 | public function testContent() |
||
1246 | |||
1247 | |||
1248 | |||
1249 | /** |
||
1250 | * @param AMQPReader $args |
||
1251 | * @return array |
||
1252 | */ |
||
1253 | public static function testContentOk($args) |
||
1259 | |||
1260 | } |
||
1261 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.