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 |
||
27 | class NewListInForeachSniff extends Sniff |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * Returns an array of tokens this test wants to listen for. |
||
32 | * |
||
33 | * @return array |
||
34 | */ |
||
35 | public function register() |
||
39 | |||
40 | /** |
||
41 | * Processes this test, when one of its tokens is encountered. |
||
42 | * |
||
43 | * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
44 | * @param int $stackPtr The position of the current token in the |
||
45 | * stack passed in $tokens. |
||
46 | * |
||
47 | * @return void |
||
48 | */ |
||
49 | public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
80 | } |
||
81 |