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 |
||
7 | class Oci8Iterator extends GenericIterator |
||
8 | { |
||
9 | |||
10 | const RECORD_BUFFER = 50; |
||
11 | |||
12 | private $rowBuffer; |
||
13 | protected $currentRow = 0; |
||
14 | protected $moveNextRow = 0; |
||
15 | |||
16 | /** |
||
17 | * @var resource Cursor |
||
18 | */ |
||
19 | private $cursor; |
||
20 | |||
21 | /** |
||
22 | * |
||
23 | * @param resource $cursor |
||
24 | */ |
||
25 | public function __construct($cursor) |
||
30 | |||
31 | /** |
||
32 | * @access public |
||
33 | * @return int |
||
34 | */ |
||
35 | public function count() |
||
39 | |||
40 | /** |
||
41 | * @access public |
||
42 | * @return bool |
||
43 | */ |
||
44 | public function hasNext() |
||
74 | |||
75 | public function __destruct() |
||
82 | |||
83 | /** |
||
84 | * @return mixed |
||
85 | * @throws IteratorException |
||
86 | */ |
||
87 | View Code Duplication | public function moveNext() |
|
97 | |||
98 | public function key() |
||
102 | } |
||
103 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.