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 |
||
18 | View Code Duplication | class FrameException extends NetworkSocketException |
|
1 ignored issue
–
show
|
|||
19 | { |
||
20 | /** |
||
21 | * Failed FramePicker |
||
22 | * |
||
23 | * @var FramePickerInterface |
||
24 | */ |
||
25 | private $picker; |
||
26 | |||
27 | /** |
||
28 | * Construct the exception. |
||
29 | * |
||
30 | * @param FramePickerInterface $picker Corrupted framePicker |
||
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 | 7 | public function __construct( |
|
46 | |||
47 | /** |
||
48 | * Return corrupted framePicker |
||
49 | * |
||
50 | * @return FramePickerInterface |
||
51 | */ |
||
52 | 1 | public function getFramePicker() |
|
56 | } |
||
57 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.