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() |
||
87 | |||
88 | public function __destruct() |
||
95 | |||
96 | /** |
||
97 | * @return Row |
||
98 | * @throws IteratorException |
||
99 | */ |
||
100 | View Code Duplication | public function moveNext() |
|
110 | |||
111 | public function key() |
||
115 | } |
||
116 |
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.