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 |
||
21 | View Code Duplication | class ConnectionAlreadyEstablished extends \LogicException implements Exception |
|
22 | { |
||
23 | use AccessorTrait; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $id; |
||
29 | |||
30 | /** |
||
31 | * @return string |
||
32 | */ |
||
33 | protected function get_id() |
||
37 | |||
38 | /** |
||
39 | * @param string $id |
||
40 | * @param int $code |
||
41 | * @param \Exception|null $previous |
||
42 | */ |
||
43 | public function __construct($id, $code = 500, \Exception $previous = null) |
||
49 | |||
50 | /** |
||
51 | * Formats exception message. |
||
52 | * |
||
53 | * @param string $id |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | protected function format_message($id) |
||
65 | } |
||
66 |