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 WpHydraSetupDomainTest extends WP_UnitTestCase { |
||
| 4 | |||
| 5 | public function setUp() { |
||
| 8 | |||
| 9 | public function tearDown() { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @covers WP_Hydra::setup_domain |
||
| 15 | */ |
||
| 16 | public function testWithWrongURL() { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @covers WP_Hydra::setup_domain |
||
| 26 | */ |
||
| 27 | View Code Duplication | public function testWithNoHost() { |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @covers WP_Hydra::setup_domain |
||
| 42 | */ |
||
| 43 | View Code Duplication | public function testWithTheSameDomain() { |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @covers WP_Hydra::setup_domain |
||
| 58 | */ |
||
| 59 | public function testWithDifferentDomain() { |
||
| 74 | |||
| 75 | } |
||
| 76 | |||
| 81 | } |
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.