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 |
||
20 | class RenderGzipFileStream implements FileStream |
||
21 | { |
||
22 | /** |
||
23 | * @var SitemapRender |
||
24 | */ |
||
25 | private $render; |
||
26 | |||
27 | /** |
||
28 | * @var StreamState |
||
29 | */ |
||
30 | private $state; |
||
31 | |||
32 | /** |
||
33 | * @var resource|null |
||
34 | */ |
||
35 | private $handle; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $filename = ''; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $tmp_filename = ''; |
||
46 | |||
47 | /** |
||
48 | * @var int |
||
49 | */ |
||
50 | private $compression_level = 9; |
||
51 | |||
52 | /** |
||
53 | * @var int |
||
54 | */ |
||
55 | private $counter = 0; |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | private $end_string = ''; |
||
61 | |||
62 | /** |
||
63 | * @param SitemapRender $render |
||
64 | * @param string $filename |
||
65 | * @param int $compression_level |
||
66 | */ |
||
67 | 14 | public function __construct(SitemapRender $render, $filename, $compression_level = 9) |
|
78 | |||
79 | /** |
||
80 | * @return string |
||
81 | */ |
||
82 | 1 | public function getFilename() |
|
86 | |||
87 | 7 | View Code Duplication | public function open() |
101 | |||
102 | 14 | View Code Duplication | public function close() |
118 | |||
119 | /** |
||
120 | * @param Url $url |
||
121 | */ |
||
122 | 5 | View Code Duplication | public function push(Url $url) |
137 | |||
138 | /** |
||
139 | * @return int |
||
140 | */ |
||
141 | 2 | public function count() |
|
145 | |||
146 | /** |
||
147 | * @param string $string |
||
148 | */ |
||
149 | 7 | private function write($string) |
|
153 | } |
||
154 |