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 |
||
| 23 | class PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueOutsideLoopSniff extends PHPCompatibility_Sniff |
||
|
|
|||
| 24 | { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Token codes of control structure in which usage of break/continue is valid. |
||
| 28 | * |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | protected $validLoopStructures = array( |
||
| 32 | T_FOR => true, |
||
| 33 | T_FOREACH => true, |
||
| 34 | T_WHILE => true, |
||
| 35 | T_DO => true, |
||
| 36 | T_SWITCH => true, |
||
| 37 | ); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Token codes which did not correctly get a condition assigned in older PHPCS versions. |
||
| 41 | * |
||
| 42 | * @var array |
||
| 43 | */ |
||
| 44 | protected $backCompat = array( |
||
| 45 | T_CASE => true, |
||
| 46 | T_DEFAULT => true, |
||
| 47 | ); |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Returns an array of tokens this test wants to listen for. |
||
| 51 | * |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | public function register() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Processes this test, when one of its tokens is encountered. |
||
| 65 | * |
||
| 66 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
| 67 | * @param int $stackPtr The position of the current token in the |
||
| 68 | * stack passed in $tokens. |
||
| 69 | * |
||
| 70 | * @return void |
||
| 71 | */ |
||
| 72 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 110 | |||
| 111 | }//end class |
||
| 112 |
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.