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 |
||
19 | View Code Duplication | class NetworkSocketException extends SocketException |
|
20 | { |
||
21 | /** |
||
22 | * Socket with this exception |
||
23 | * |
||
24 | * @var SocketInterface |
||
25 | */ |
||
26 | private $socket; |
||
27 | |||
28 | /** |
||
29 | * Construct the exception. |
||
30 | * |
||
31 | * @param SocketInterface $socket Socket object |
||
32 | * @param string $message The Exception message to throw. |
||
33 | * @param int $code The Exception code. |
||
34 | * @param \Exception $previous The previous exception used for the exception chaining. |
||
35 | */ |
||
36 | 115 | public function __construct(SocketInterface $socket, $message = '', $code = 0, \Exception $previous = null) |
|
37 | { |
||
38 | 115 | parent::__construct($message, $code, $previous); |
|
39 | 115 | $this->socket = $socket; |
|
40 | 115 | } |
|
41 | |||
42 | /** |
||
43 | * Return socket with this exception |
||
44 | * |
||
45 | * @return SocketInterface |
||
46 | */ |
||
47 | 14 | public function getSocket() |
|
51 | } |
||
52 |