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 |
||
| 18 | class DirectLinkPaymentRequestTest extends \PHPUnit_Framework_TestCase |
||
| 19 | { |
||
| 20 | |||
| 21 | /** @test */ |
||
| 22 | public function IsValidWhenRequiredFieldsAreFilledIn() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @test |
||
| 30 | * @expectedException \RuntimeException |
||
| 31 | */ |
||
| 32 | public function IsInvalidWhenFieldsAreMissing() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @test |
||
| 40 | * @expectedException \InvalidArgumentException |
||
| 41 | */ |
||
| 42 | public function isInvalidWithNonOgoneUrl() |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @test |
||
| 51 | */ |
||
| 52 | public function isValidWithOgoneUrl() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @test |
||
| 61 | */ |
||
| 62 | public function isValidWhenAliasSet() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @test |
||
| 73 | * @expectedException \InvalidArgumentException |
||
| 74 | */ |
||
| 75 | View Code Duplication | public function IsInvalidWithTooLongAlias() |
|
| 83 | |||
| 84 | /** |
||
| 85 | * @test |
||
| 86 | */ |
||
| 87 | public function isValidWhenOperationIsSet() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @test |
||
| 96 | * @dataProvider provideBadParameters |
||
| 97 | * @expectedException \InvalidArgumentException |
||
| 98 | */ |
||
| 99 | public function BadParametersCauseExceptions($method, $value) |
||
| 104 | |||
| 105 | public function provideBadParameters() |
||
| 113 | |||
| 114 | /** @return DirectLinkPaymentRequest */ |
||
| 115 | private function provideMinimalDirectLinkPaymentRequest() |
||
| 127 | } |
||
| 128 |
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.