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 |
||
8 | class ApiTest extends AbstractTestCase |
||
9 | { |
||
10 | public function setup200Response() |
||
16 | |||
17 | View Code Duplication | public function testGet() |
|
26 | |||
27 | View Code Duplication | public function testPost() |
|
36 | |||
37 | View Code Duplication | public function testPostRaw() |
|
46 | |||
47 | View Code Duplication | public function testPut() |
|
56 | |||
57 | View Code Duplication | public function testPatch() |
|
66 | |||
67 | View Code Duplication | public function testDelete() |
|
76 | |||
77 | /** |
||
78 | * @expectedException \IBM\Watson\Common\Exception\Domain\InsufficientPrivilegesException |
||
79 | * @expectedExceptionMessage Not Authorized |
||
80 | */ |
||
81 | public function testUnauthorizedExceptionIsThrown() |
||
88 | |||
89 | /** |
||
90 | * @expectedException \IBM\Watson\Common\Exception\Domain\NotFoundException |
||
91 | * @expectedExceptionMessage Not Found |
||
92 | */ |
||
93 | public function testNotFoundExceptionIsThrown() |
||
100 | |||
101 | /** |
||
102 | * @expectedException \IBM\Watson\Common\Exception\Domain\UnknownErrorException |
||
103 | * @expectedExceptionMessage The service encountered an internal error |
||
104 | */ |
||
105 | public function testWatsonUnknownErrorIsThrown() |
||
112 | |||
113 | /** |
||
114 | * @expectedException \IBM\Watson\Common\Exception\Domain\UnknownErrorException |
||
115 | * @expectedExceptionMessage The service encountered an internal error |
||
116 | */ |
||
117 | public function testDefaultUnknownErrorIsThrown() |
||
126 | } |
||
127 |
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.