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 |
||
14 | class SecureClientSocket extends SecureSocket |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Whether the socket is connected |
||
19 | * |
||
20 | * @var boolean |
||
21 | */ |
||
22 | private $conntected; |
||
23 | |||
24 | /** |
||
25 | * Create a new client socket |
||
26 | * |
||
27 | * @param Endpoint $endpoint |
||
28 | * The endpoint to use |
||
29 | * @param resource $clientHandle |
||
30 | * optional existing client handle |
||
31 | */ |
||
32 | 12 | View Code Duplication | public function __construct(Endpoint $endpoint, $clientHandle = null) |
42 | |||
43 | /** |
||
44 | * Connect to remote endpoint |
||
45 | * |
||
46 | * @throws SocketException |
||
47 | */ |
||
48 | 11 | public function connect() |
|
52 | |||
53 | /** |
||
54 | * Disconnects the socket |
||
55 | * |
||
56 | * @throws SocketException |
||
57 | */ |
||
58 | 5 | public function disconnect() |
|
66 | |||
67 | /** |
||
68 | * Whether the client is connected |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | 11 | public function isConnected(): bool |
|
76 | |||
77 | /** |
||
78 | * |
||
79 | * @see \Generics\Socket\ClientSocket::disconnect() |
||
80 | */ |
||
81 | 6 | public function close() |
|
86 | |||
87 | /** |
||
88 | * |
||
89 | * {@inheritdoc} |
||
90 | * @see \Generics\Socket\Socket::isWriteable() |
||
91 | */ |
||
92 | 11 | public function isWriteable(): bool |
|
100 | } |
||
101 |