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 |
||
4 | class SecureClientSocket extends SecureSocket |
||
5 | { |
||
6 | /** |
||
7 | * Whether the socket is connected |
||
8 | * |
||
9 | * @var boolean |
||
10 | */ |
||
11 | private $conntected; |
||
12 | |||
13 | /** |
||
14 | * Create a new client socket |
||
15 | * |
||
16 | * @param Endpoint $endpoint |
||
17 | * The endpoint to use |
||
18 | * @param resource $clientHandle |
||
19 | * optional existing client handle |
||
20 | */ |
||
21 | 11 | View Code Duplication | public function __construct(Endpoint $endpoint, $clientHandle = null) |
31 | |||
32 | /** |
||
33 | * Connect to remote endpoint |
||
34 | * |
||
35 | * @throws SocketException |
||
36 | */ |
||
37 | 11 | public function connect() |
|
41 | |||
42 | /** |
||
43 | * Disconnects the socket |
||
44 | * |
||
45 | * @throws SocketException |
||
46 | */ |
||
47 | 5 | public function disconnect() |
|
55 | |||
56 | /** |
||
57 | * Whether the client is connected |
||
58 | * |
||
59 | * @return bool |
||
60 | */ |
||
61 | 11 | public function isConnected():bool |
|
65 | |||
66 | /** |
||
67 | * |
||
68 | * @see \Generics\Socket\ClientSocket::disconnect() |
||
69 | */ |
||
70 | 6 | public function close() |
|
75 | |||
76 | /** |
||
77 | * |
||
78 | * {@inheritdoc} |
||
79 | * @see \Generics\Socket\Socket::isWriteable() |
||
80 | */ |
||
81 | 11 | public function isWriteable():bool |
|
89 | } |