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 CallbackStream implements Stream |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var SitemapRender |
||
| 24 | */ |
||
| 25 | private $render; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var callable |
||
| 29 | */ |
||
| 30 | private $callback; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var StreamState |
||
| 34 | */ |
||
| 35 | private $state; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var int |
||
| 39 | */ |
||
| 40 | private $counter = 0; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var int |
||
| 44 | */ |
||
| 45 | private $used_bytes = 0; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | private $end_string = ''; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param SitemapRender $render |
||
| 54 | * @param callable $callback |
||
| 55 | */ |
||
| 56 | 9 | public function __construct(SitemapRender $render, callable $callback) |
|
| 62 | |||
| 63 | 7 | public function open(): void |
|
| 70 | |||
| 71 | 8 | public function close(): void |
|
| 78 | |||
| 79 | /** |
||
| 80 | * @param Url $url |
||
| 81 | */ |
||
| 82 | 5 | View Code Duplication | public function push(Url $url): void |
| 102 | |||
| 103 | /** |
||
| 104 | * @param string $content |
||
| 105 | */ |
||
| 106 | 7 | private function send(string $content): void |
|
| 111 | } |
||
| 112 |