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 |
||
| 19 | class EcommercePaymentResponseTest extends \PHPUnit_Framework_TestCase |
||
| 20 | { |
||
| 21 | /** @test */ |
||
| 22 | public function CanBeVerified() |
||
| 29 | |||
| 30 | /** @test */ |
||
| 31 | public function CanBeConvertedToArray() |
||
| 43 | |||
| 44 | |||
| 45 | /** |
||
| 46 | * @test |
||
| 47 | * @expectedException InvalidArgumentException |
||
| 48 | */ |
||
| 49 | public function CannotExistWithoutShaSign() |
||
| 53 | |||
| 54 | /** @test */ |
||
| 55 | View Code Duplication | public function ParametersCanBeRetrieved() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * @test |
||
| 65 | * @expectedException InvalidArgumentException |
||
| 66 | */ |
||
| 67 | public function RequestIsFilteredFromNonOgoneParameters() |
||
| 74 | |||
| 75 | /** @test */ |
||
| 76 | public function ChecksStatus() |
||
| 83 | |||
| 84 | /** @test */ |
||
| 85 | public function AmountIsConvertedToCent() |
||
| 92 | |||
| 93 | public function provideFloats() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @test |
||
| 105 | * @expectedException InvalidArgumentException |
||
| 106 | */ |
||
| 107 | public function InvalidForInvalidCurrency() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @test |
||
| 115 | * @dataProvider provideFloats |
||
| 116 | */ |
||
| 117 | public function CorrectlyConvertsFloatAmountsToInteger($string, $integer) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Helper method to setup a request array |
||
| 125 | */ |
||
| 126 | private function provideRequest() |
||
| 136 | } |
||
| 137 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.