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 |
||
19 | class OutputStream implements Stream |
||
20 | { |
||
21 | /** |
||
22 | * @var SitemapRender |
||
23 | */ |
||
24 | private $render; |
||
25 | |||
26 | /** |
||
27 | * @var StreamState |
||
28 | */ |
||
29 | private $state; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | private $counter = 0; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | private $used_bytes = 0; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $end_string = ''; |
||
45 | |||
46 | /** |
||
47 | * @param SitemapRender $render |
||
48 | */ |
||
49 | 10 | public function __construct(SitemapRender $render) |
|
54 | |||
55 | 8 | public function open() |
|
62 | |||
63 | 9 | public function close() |
|
70 | |||
71 | /** |
||
72 | * @param Url $url |
||
73 | */ |
||
74 | 6 | View Code Duplication | public function push(Url $url) |
94 | |||
95 | /** |
||
96 | * @return int |
||
97 | */ |
||
98 | 2 | public function count() |
|
102 | |||
103 | /** |
||
104 | * @param string $string |
||
105 | */ |
||
106 | 8 | private function send($string) |
|
112 | } |
||
113 |