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 |
||
| 21 | class RenderGzipFileStream implements FileStream |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var SitemapRender |
||
| 25 | */ |
||
| 26 | private $render; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var StreamState |
||
| 30 | */ |
||
| 31 | private $state; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var resource|null |
||
| 35 | */ |
||
| 36 | private $handle; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private $filename = ''; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | private $tmp_filename = ''; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var int |
||
| 50 | */ |
||
| 51 | private $compression_level = 9; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var int |
||
| 55 | */ |
||
| 56 | private $counter = 0; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | private $end_string = ''; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var int |
||
| 65 | */ |
||
| 66 | private $used_bytes = 0; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param SitemapRender $render |
||
| 70 | * @param string $filename |
||
| 71 | * @param int $compression_level |
||
| 72 | */ |
||
| 73 | 15 | public function __construct(SitemapRender $render, $filename, $compression_level = 9) |
|
| 84 | |||
| 85 | /** |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | 1 | public function getFilename() |
|
| 92 | |||
| 93 | 8 | View Code Duplication | public function open() |
| 116 | |||
| 117 | 15 | View Code Duplication | public function close() |
| 134 | |||
| 135 | /** |
||
| 136 | * @param Url $url |
||
| 137 | */ |
||
| 138 | 6 | View Code Duplication | public function push(Url $url) |
| 158 | |||
| 159 | /** |
||
| 160 | * @return int |
||
| 161 | */ |
||
| 162 | 2 | public function count() |
|
| 166 | |||
| 167 | /** |
||
| 168 | * @param string $string |
||
| 169 | */ |
||
| 170 | 8 | private function write($string) |
|
| 175 | } |
||
| 176 |