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 |
||
19 | class PHPCompatibility_Sniffs_PHP_NewNowdocSniff extends PHPCompatibility_Sniff |
||
|
|||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Returns an array of tokens this test wants to listen for. |
||
24 | * |
||
25 | * @return array |
||
26 | */ |
||
27 | public function register() |
||
43 | |||
44 | |||
45 | /** |
||
46 | * Processes this test, when one of its tokens is encountered. |
||
47 | * |
||
48 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
49 | * @param int $stackPtr The position of the current token in |
||
50 | * the stack passed in $tokens. |
||
51 | * |
||
52 | * @return int|void On older PHP versions passes a pointer to the nowdoc closer |
||
53 | * to skip passed anything in between in regards to processing |
||
54 | * the file for this sniff. |
||
55 | */ |
||
56 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
97 | |||
98 | }//end class |
||
99 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.