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 |
||
13 | class Text_Diff_Renderer_inline extends Text_Diff_Renderer |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * Number of leading context "lines" to preserve. |
||
18 | */ |
||
19 | public $_leading_context_lines = 10000; |
||
20 | |||
21 | /** |
||
22 | * Number of trailing context "lines" to preserve. |
||
23 | */ |
||
24 | public $_trailing_context_lines = 10000; |
||
25 | |||
26 | /** |
||
27 | * Prefix for inserted text. |
||
28 | */ |
||
29 | public $_ins_prefix = '<ins>'; |
||
30 | |||
31 | /** |
||
32 | * Suffix for inserted text. |
||
33 | */ |
||
34 | public $_ins_suffix = '</ins>'; |
||
35 | |||
36 | /** |
||
37 | * Prefix for deleted text. |
||
38 | */ |
||
39 | public $_del_prefix = '<del>'; |
||
40 | |||
41 | /** |
||
42 | * Suffix for deleted text. |
||
43 | */ |
||
44 | public $_del_suffix = '</del>'; |
||
45 | |||
46 | /** |
||
47 | * Header for each change block. |
||
48 | */ |
||
49 | public $_block_header = ''; |
||
50 | |||
51 | /** |
||
52 | * What are we currently splitting on? Used to recurse to show word-level |
||
53 | * changes. |
||
54 | */ |
||
55 | public $_split_level = 'lines'; |
||
56 | |||
57 | /** |
||
58 | * @param $xbeg |
||
59 | * @param $xlen |
||
60 | * @param $ybeg |
||
61 | * @param $ylen |
||
62 | * @return string |
||
63 | */ |
||
64 | public function _blockHeader($xbeg, $xlen, $ybeg, $ylen) |
||
68 | |||
69 | /** |
||
70 | * @param $header |
||
71 | * @return mixed |
||
72 | */ |
||
73 | public function _startBlock($header) |
||
77 | |||
78 | /** |
||
79 | * @param $lines |
||
80 | * @param string $prefix |
||
81 | * @param bool $encode |
||
82 | * @return string |
||
83 | */ |
||
84 | public function _lines($lines, $prefix = ' ', $encode = true) |
||
96 | |||
97 | /** |
||
98 | * @param $lines |
||
99 | * @return string |
||
100 | */ |
||
101 | View Code Duplication | public function _added($lines) |
|
109 | |||
110 | /** |
||
111 | * @param $lines |
||
112 | * @param bool $words |
||
113 | * @return string |
||
114 | */ |
||
115 | View Code Duplication | public function _deleted($lines, $words = false) |
|
123 | |||
124 | /** |
||
125 | * @param $orig |
||
126 | * @param $final |
||
127 | * @return string |
||
128 | */ |
||
129 | public function _changed($orig, $final) |
||
162 | |||
163 | /** |
||
164 | * @param $string |
||
165 | * @param string $newlineEscape |
||
166 | * @return array |
||
167 | */ |
||
168 | public function _splitOnWords($string, $newlineEscape = "\n") |
||
184 | |||
185 | /** |
||
186 | * @param $string |
||
187 | */ |
||
188 | public function _encode(&$string) |
||
192 | } |
||
193 |
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.