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 |
||
8 | View Code Duplication | class HttpRequest extends Request implements HttpRequestInterface, NetworkMessageInterface |
|
|
|||
9 | { |
||
10 | /** |
||
11 | * @override |
||
12 | * @inheritDoc |
||
13 | */ |
||
14 | 1 | public function __toString() |
|
18 | |||
19 | /** |
||
20 | * @override |
||
21 | * @inheritDoc |
||
22 | */ |
||
23 | 6 | public function encode() |
|
34 | |||
35 | /** |
||
36 | * @override |
||
37 | * @inheritDoc |
||
38 | */ |
||
39 | 6 | public function getTarget() |
|
43 | |||
44 | /** |
||
45 | * @override |
||
46 | * @inheritDoc |
||
47 | */ |
||
48 | 5 | public function read() |
|
52 | |||
53 | /** |
||
54 | * Encode headers. |
||
55 | * |
||
56 | * @param string[][] $headers |
||
57 | * @return string |
||
58 | */ |
||
59 | 7 | protected function encodeHeaders($headers = []) |
|
80 | |||
81 | /** |
||
82 | * Encode single header. |
||
83 | * |
||
84 | * @param string $header |
||
85 | * @return string |
||
86 | */ |
||
87 | 8 | protected function encodeHeader($header) |
|
97 | } |
||
98 |
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.