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:
1 | <?php |
||
28 | class UdpTransport extends AbstractTransport |
||
29 | { |
||
30 | const CHUNK_GELF_ID = "\x1e\x0f"; |
||
31 | const CHUNK_MAX_COUNT = 128; // as per GELF spec |
||
32 | const CHUNK_SIZE_LAN = 8154; |
||
33 | const CHUNK_SIZE_WAN = 1420; |
||
34 | |||
35 | const DEFAULT_HOST = "127.0.0.1"; |
||
36 | const DEFAULT_PORT = 12201; |
||
37 | |||
38 | /** |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $chunkSize; |
||
42 | |||
43 | /** |
||
44 | * @var StreamSocketClient |
||
45 | */ |
||
46 | protected $socketClient; |
||
47 | |||
48 | /** |
||
49 | * Class constructor |
||
50 | * |
||
51 | * @param string $host when NULL or empty DEFAULT_HOST is used |
||
52 | * @param int $port when NULL or empty DEFAULT_PORT is used |
||
53 | * @param int $chunkSize defaults to CHUNK_SIZE_WAN, |
||
54 | * 0 disables chunks completely |
||
55 | */ |
||
56 | 5 | View Code Duplication | public function __construct( |
70 | |||
71 | /** |
||
72 | * Sends a Message over this transport |
||
73 | * |
||
74 | * @param Message $message |
||
75 | * |
||
76 | * @return int the number of UDP packets sent |
||
77 | */ |
||
78 | 3 | public function send(Message $message) |
|
94 | |||
95 | /** |
||
96 | * Sends given string in multiple chunks |
||
97 | * |
||
98 | * @param string $rawMessage |
||
99 | * @return int |
||
100 | * |
||
101 | * @throws RuntimeException on too large messages which would exceed the |
||
102 | maximum number of possible chunks |
||
103 | */ |
||
104 | 2 | protected function sendMessageInChunks($rawMessage) |
|
142 | } |
||
143 |