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 SQLRelayIterator 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 |
||
18 | */ |
||
19 | private $_cursor; |
||
20 | |||
21 | /** |
||
22 | * |
||
23 | * @param resource $cursor |
||
24 | */ |
||
25 | public function __construct($cursor) |
||
30 | |||
31 | /** |
||
32 | * @return int |
||
33 | */ |
||
34 | public function count() |
||
38 | |||
39 | /** |
||
40 | * @return bool |
||
41 | */ |
||
42 | public function hasNext() |
||
83 | |||
84 | public function __destruct() |
||
91 | |||
92 | /** |
||
93 | * @return SingleRow |
||
94 | * @throws IteratorException |
||
95 | */ |
||
96 | View Code Duplication | public function moveNext() |
|
106 | |||
107 | function key() |
||
111 | } |
||
112 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.