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 |
||
15 | class ClientSocket extends Socket |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Whether the socket is connected |
||
20 | * |
||
21 | * @var boolean |
||
22 | */ |
||
23 | private $conntected; |
||
24 | |||
25 | /** |
||
26 | * Create a new client socket |
||
27 | * |
||
28 | * @param Endpoint $endpoint |
||
29 | * The endpoint to use |
||
30 | * @param resource $clientHandle |
||
31 | * optional existing client handle |
||
32 | */ |
||
33 | 14 | View Code Duplication | public function __construct(Endpoint $endpoint, $clientHandle = null) |
43 | |||
44 | /** |
||
45 | * Connect to remote endpoint |
||
46 | * |
||
47 | * @throws SocketException |
||
48 | */ |
||
49 | 13 | public function connect() |
|
60 | |||
61 | /** |
||
62 | * Disconnects the socket |
||
63 | * |
||
64 | * @throws SocketException |
||
65 | */ |
||
66 | 5 | public function disconnect() |
|
74 | |||
75 | /** |
||
76 | * Whether the client is connected |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | 12 | public function isConnected():bool |
|
84 | |||
85 | /** |
||
86 | * |
||
87 | * @see \Generics\Socket\ClientSocket::disconnect() |
||
88 | */ |
||
89 | 14 | public function close() |
|
94 | |||
95 | /** |
||
96 | * |
||
97 | * {@inheritdoc} |
||
98 | * @see \Generics\Socket\Socket::isWriteable() |
||
99 | */ |
||
100 | 1 | public function isWriteable():bool |
|
108 | } |
||
109 |