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 ResponseTest extends UnitTestCase |
||
19 | { |
||
20 | /** @var mixed */ |
||
21 | private $stream; |
||
22 | |||
23 | public function setUp() |
||
27 | |||
28 | public function testInterface() |
||
33 | |||
34 | public function testGetRpcId() |
||
42 | |||
43 | public function testGetRpcIdIsNull() |
||
49 | |||
50 | View Code Duplication | public function testGetRpcErrorCode() |
|
58 | |||
59 | public function testGetRpcErrorCodeIsNull() |
||
65 | |||
66 | public function testGetRpcErrorMessage() |
||
74 | |||
75 | public function testGetRpcErrorMessageIsNull() |
||
81 | |||
82 | View Code Duplication | public function testGetRpcErrorData() |
|
83 | { |
||
84 | $response = new Response(200, [], json_encode([ |
||
85 | 'error' => ['data' => []] |
||
86 | ])); |
||
87 | |||
88 | $this->assertEquals([], $response->getRpcErrorData()); |
||
89 | } |
||
90 | |||
91 | public function testGetRpcErrorDataIsNull() |
||
97 | |||
98 | public function testGetRpcResult() |
||
106 | |||
107 | public function testGetRpcResultIsNull() |
||
113 | |||
114 | View Code Duplication | public function testGetRpcVersion() |
|
122 | |||
123 | public function testGetRpcVersionIsNull() |
||
129 | } |
||
130 |
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.