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 OutputStream implements Stream |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var SitemapRender |
||
| 25 | */ |
||
| 26 | private $render; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var StreamState |
||
| 30 | */ |
||
| 31 | private $state; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var int |
||
| 35 | */ |
||
| 36 | private $counter = 0; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var int |
||
| 40 | */ |
||
| 41 | private $used_bytes = 0; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | private $end_string = ''; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param SitemapRender $render |
||
| 50 | */ |
||
| 51 | 9 | public function __construct(SitemapRender $render) |
|
| 56 | |||
| 57 | 7 | public function open(): void |
|
| 64 | |||
| 65 | 8 | public function close(): void |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @param Url $url |
||
| 75 | */ |
||
| 76 | 5 | View Code Duplication | public function push(Url $url): void |
| 96 | |||
| 97 | /** |
||
| 98 | * @param string $content |
||
| 99 | */ |
||
| 100 | 7 | private function send(string $content): void |
|
| 106 | } |
||
| 107 |