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 |
||
12 | class Pipe |
||
13 | { |
||
14 | /** |
||
15 | * @var resource |
||
16 | */ |
||
17 | protected $read; |
||
18 | |||
19 | /** |
||
20 | * @var resource |
||
21 | */ |
||
22 | protected $write; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $filename; |
||
28 | |||
29 | /** |
||
30 | * @var bool |
||
31 | */ |
||
32 | protected $block; |
||
33 | |||
34 | /** |
||
35 | * @param string $filename fifo filename |
||
36 | * @param int $mode |
||
37 | * @param bool $block if blocking |
||
38 | */ |
||
39 | 12 | public function __construct($filename = '/tmp/simple-fork.pipe', $mode = 0666, $block = false) |
|
51 | |||
52 | 6 | public function setBlock($block = true) |
|
70 | |||
71 | /** |
||
72 | * @param int $size |
||
73 | * @return string |
||
74 | */ |
||
75 | 9 | View Code Duplication | public function read($size = 1024) |
92 | |||
93 | /** |
||
94 | * @param $message |
||
95 | * @return int |
||
96 | */ |
||
97 | 6 | View Code Duplication | public function write($message) |
114 | |||
115 | /** |
||
116 | * |
||
117 | */ |
||
118 | 12 | public function close() |
|
127 | |||
128 | /** |
||
129 | * |
||
130 | */ |
||
131 | 12 | public function __destruct() |
|
135 | |||
136 | public function remove() |
||
140 | } |
||
141 |