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 |
||
| 22 | class RenderFileStream implements FileStream |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var SitemapRender |
||
| 26 | */ |
||
| 27 | private $render; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var StreamState |
||
| 31 | */ |
||
| 32 | private $state; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var resource|null |
||
| 36 | */ |
||
| 37 | private $handle; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | private $filename = ''; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var int |
||
| 46 | */ |
||
| 47 | private $counter = 0; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | private $end_string = ''; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var int |
||
| 56 | */ |
||
| 57 | private $used_bytes = 0; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param SitemapRender $render |
||
| 61 | * @param string $filename |
||
| 62 | */ |
||
| 63 | 13 | public function __construct(SitemapRender $render, $filename) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * @return string |
||
| 72 | */ |
||
| 73 | 3 | public function getFilename(): string |
|
| 77 | |||
| 78 | 10 | View Code Duplication | public function open(): void |
| 92 | |||
| 93 | 10 | View Code Duplication | public function close(): void |
| 101 | |||
| 102 | /** |
||
| 103 | * @param Url $url |
||
| 104 | */ |
||
| 105 | 6 | View Code Duplication | public function push(Url $url): void |
| 125 | |||
| 126 | /** |
||
| 127 | * @param string $string |
||
| 128 | */ |
||
| 129 | 9 | private function write(string $string): void |
|
| 134 | } |
||
| 135 |