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 |
||
30 | class MultiLineArraySniff implements Sniff |
||
31 | { |
||
32 | /** |
||
33 | * Define all types of arrays. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $arrayTokens = array( |
||
38 | T_ARRAY, |
||
39 | T_OPEN_SHORT_ARRAY, |
||
40 | ); |
||
41 | |||
42 | |||
43 | /** |
||
44 | * Registers the tokens that this sniff wants to listen for. |
||
45 | * |
||
46 | * @return array(int) |
||
|
|||
47 | * @see Tokens.php |
||
48 | */ |
||
49 | public function register() |
||
54 | |||
55 | |||
56 | /** |
||
57 | * Processes this test, when one of its tokens is encountered. |
||
58 | * |
||
59 | * @param File $phpcsFile The file being scanned. |
||
60 | * @param int $stackPtr The position of the current token in |
||
61 | * the stack passed in $tokens. |
||
62 | * |
||
63 | * @return void |
||
64 | */ |
||
65 | public function process(File $phpcsFile, $stackPtr) |
||
119 | |||
120 | |||
121 | }//end class |
||
122 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.