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 |
||
14 | final class ResponseBridgeTest extends \PHPUnit_Framework_TestCase |
||
15 | { |
||
16 | /** |
||
17 | * Verify basic behavior of fromOAuth2() |
||
18 | * |
||
19 | * @test |
||
20 | * @covers ::fromOAuth2 |
||
21 | * |
||
22 | * @return void |
||
23 | */ |
||
24 | public function fromOAuth2() |
||
50 | |||
51 | /** |
||
52 | * Verify behavior of fromOAuth2() with empty response body. |
||
53 | * |
||
54 | * @test |
||
55 | * @covers ::fromOAuth2 |
||
56 | * |
||
57 | * @return void |
||
58 | */ |
||
59 | View Code Duplication | public function fromOAuth2EmptyBody() |
|
81 | |||
82 | /** |
||
83 | * Verify response can be written to when empty. |
||
84 | * |
||
85 | * @test |
||
86 | * @covers ::fromOAuth2 |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | View Code Duplication | public function fromOAuth2WritableEmptyBody() |
|
114 | } |
||
115 |
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.