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 | class RenderBzip2FileStream implements FileStream |
||
20 | { |
||
21 | /** |
||
22 | * @var SitemapRender |
||
23 | */ |
||
24 | private $render; |
||
25 | |||
26 | /** |
||
27 | * @var StreamState |
||
28 | */ |
||
29 | private $state; |
||
30 | |||
31 | /** |
||
32 | * @var resource|null |
||
33 | */ |
||
34 | private $handle; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private $filename = ''; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $tmp_filename = ''; |
||
45 | |||
46 | /** |
||
47 | * @var int |
||
48 | */ |
||
49 | private $counter = 0; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | private $end_string = ''; |
||
55 | |||
56 | /** |
||
57 | * @param SitemapRender $render |
||
58 | * @param string $filename |
||
59 | */ |
||
60 | 10 | public function __construct(SitemapRender $render, $filename) |
|
66 | |||
67 | /** |
||
68 | * @return string |
||
69 | */ |
||
70 | 1 | public function getFilename() |
|
74 | |||
75 | 7 | public function open() |
|
90 | |||
91 | 10 | View Code Duplication | public function close() |
107 | |||
108 | /** |
||
109 | * @param Url $url |
||
110 | */ |
||
111 | 5 | View Code Duplication | public function push(Url $url) |
126 | |||
127 | /** |
||
128 | * @return int |
||
129 | */ |
||
130 | 2 | public function count() |
|
134 | |||
135 | /** |
||
136 | * @param string $string |
||
137 | */ |
||
138 | 7 | private function write($string) |
|
142 | } |
||
143 |