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 |
||
| 34 | View Code Duplication | class VariableInDoubleQuotedStringUnitTest extends AbstractSniffUnitTest |
|
|
|
|||
| 35 | { |
||
| 36 | |||
| 37 | |||
| 38 | /** |
||
| 39 | * Returns the lines where errors should occur. |
||
| 40 | * |
||
| 41 | * The key of the array should represent the line number and the value |
||
| 42 | * should represent the number of errors that should occur on that line. |
||
| 43 | * |
||
| 44 | * @param string $testFile test file |
||
| 45 | * |
||
| 46 | * @return array<int, int> |
||
| 47 | * @throws RuntimeException |
||
| 48 | */ |
||
| 49 | protected function getErrorList($testFile='') |
||
| 71 | |||
| 72 | |||
| 73 | /** |
||
| 74 | * Returns the lines where warnings should occur. |
||
| 75 | * |
||
| 76 | * The key of the array should represent the line number and the value |
||
| 77 | * should represent the number of warnings that should occur on that line. |
||
| 78 | * |
||
| 79 | * @return array<int, int> |
||
| 80 | */ |
||
| 81 | protected function getWarningList() |
||
| 86 | |||
| 87 | |||
| 88 | }//end class |
||
| 89 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.