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 |
||
| 20 | class ForbiddenBreakContinueVariableArgumentsSniffTest extends BaseSniffTest |
||
|
|
|||
| 21 | { |
||
| 22 | const TEST_FILE = 'sniff-examples/forbidden_break_continue_variable_argument.php'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Sniffed file |
||
| 26 | * |
||
| 27 | * @var PHP_CodeSniffer_File |
||
| 28 | */ |
||
| 29 | protected $_sniffFile; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * setUp |
||
| 33 | * |
||
| 34 | * @return void |
||
| 35 | */ |
||
| 36 | public function setUp() |
||
| 42 | |||
| 43 | |||
| 44 | /** |
||
| 45 | * testAllowedBreakAndContinueVariableArgument |
||
| 46 | * |
||
| 47 | * In PHP 5.3, none of the statements should give an error. |
||
| 48 | * |
||
| 49 | * @group forbiddenBreakContinue |
||
| 50 | * |
||
| 51 | * @return void |
||
| 52 | */ |
||
| 53 | public function testAllowedBreakAndContinueVariableArgument() |
||
| 58 | |||
| 59 | |||
| 60 | /** |
||
| 61 | * testBreakAndContinueVariableArgument |
||
| 62 | * |
||
| 63 | * @group forbiddenBreakContinue |
||
| 64 | * |
||
| 65 | * @dataProvider dataBreakAndContinueVariableArgument |
||
| 66 | * |
||
| 67 | * @param int $line The line number. |
||
| 68 | * |
||
| 69 | * @return void |
||
| 70 | */ |
||
| 71 | public function testBreakAndContinueVariableArgument($line) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Data provider. |
||
| 78 | * |
||
| 79 | * @see testBreakAndContinueVariableArgument() |
||
| 80 | * |
||
| 81 | * @return array |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function dataBreakAndContinueVariableArgument() |
|
| 100 | |||
| 101 | |||
| 102 | /** |
||
| 103 | * testNoViolation |
||
| 104 | * |
||
| 105 | * @group forbiddenBreakContinue |
||
| 106 | * |
||
| 107 | * @dataProvider dataNoViolation |
||
| 108 | * |
||
| 109 | * @param int $line The line number. |
||
| 110 | * |
||
| 111 | * @return void |
||
| 112 | */ |
||
| 113 | public function testNoViolation($line) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Data provider. |
||
| 120 | * |
||
| 121 | * @see testNoViolation() |
||
| 122 | * |
||
| 123 | * @return array |
||
| 124 | */ |
||
| 125 | View Code Duplication | public function dataNoViolation() |
|
| 140 | } |
||
| 141 | |||
| 142 |
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.