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 |
||
| 3 | class WpHydraSetupContentTest extends WP_UnitTestCase { |
||
| 4 | |||
| 5 | public function setUp() { |
||
| 16 | |||
| 17 | public function tearDown() { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @covers WP_Hydra::setup_content |
||
| 24 | */ |
||
| 25 | View Code Duplication | public function testOccurencesInTheBeginning() { |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @covers WP_Hydra::setup_content |
||
| 36 | */ |
||
| 37 | View Code Duplication | public function testOccurencesInTheMiddle() { |
|
| 45 | |||
| 46 | /** |
||
| 47 | * @covers WP_Hydra::setup_content |
||
| 48 | */ |
||
| 49 | View Code Duplication | public function testOccurencesInTheEnd() { |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @covers WP_Hydra::setup_content |
||
| 60 | */ |
||
| 61 | public function testMultipleOccurences() { |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @covers WP_Hydra::setup_content |
||
| 72 | */ |
||
| 73 | View Code Duplication | public function testOccurencesInAnImage() { |
|
| 81 | |||
| 82 | /** |
||
| 83 | * @covers WP_Hydra::setup_content |
||
| 84 | */ |
||
| 85 | View Code Duplication | public function testOccurencesInALink() { |
|
| 93 | |||
| 94 | } |
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.