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 | * 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 | 6 | public function __construct(Endpoint $endpoint, $clientHandle = null) { |
|
| 41 | |||
| 42 | /** |
||
| 43 | * Connect to remote endpoint |
||
| 44 | * |
||
| 45 | * @throws SocketException |
||
| 46 | */ |
||
| 47 | 5 | View Code Duplication | public function connect() { |
| 54 | |||
| 55 | /** |
||
| 56 | * Disconnects the socket |
||
| 57 | * |
||
| 58 | * @throws SocketException |
||
| 59 | */ |
||
| 60 | 3 | public function disconnect() { |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Whether the client is connected |
||
| 66 | * |
||
| 67 | * @return boolean |
||
| 68 | */ |
||
| 69 | 4 | public function isConnected() { |
|
| 72 | |||
| 73 | /** |
||
| 74 | * |
||
| 75 | * @see \Generics\Socket\ClientSocket::disconnect() |
||
| 76 | */ |
||
| 77 | 6 | public function close() { |
|
| 85 | |||
| 86 | /** |
||
| 87 | * |
||
| 88 | * {@inheritdoc} |
||
| 89 | * @see \Generics\Socket\Socket::isWriteable() |
||
| 90 | */ |
||
| 91 | 1 | public function isWriteable() { |
|
| 98 | } |
||
| 99 |