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 |
||
17 | class ClientTest extends PHPUnit_Framework_TestCase |
||
18 | { |
||
19 | const ACCESS_TOKEN = '2ec09aeccaf634d982eec793037e37fe'; |
||
20 | const REFRESH_TOKEN = '0c59f7e609b0cc467067e39d523116ce'; |
||
21 | |||
22 | /** |
||
23 | * @dataProvider getTestSoapExceptionData |
||
24 | * |
||
25 | * @param int $code |
||
26 | * @param string $exceptionClassName |
||
27 | */ |
||
28 | public function testSoapExceptions($code, $exceptionClassName) |
||
33 | |||
34 | public function getTestSoapExceptionData() |
||
63 | |||
64 | /** |
||
65 | * @return MockInterface |
||
66 | */ |
||
67 | private function runClientSoapException($code) |
||
89 | |||
90 | /** |
||
91 | * @return Mockery\MockInterface |
||
92 | */ |
||
93 | View Code Duplication | private function getOauthTokenServiceMock() |
|
104 | |||
105 | private function getTimeHelperMock() |
||
112 | |||
113 | /** |
||
114 | * @param OauthTokenService $oauthTokenService |
||
115 | * @param ClientProxy $clientProxy |
||
116 | * @param Helper\File $fileHelper |
||
117 | * @param Helper\Csv $csvHelper |
||
118 | * @param Helper\Time $timeHelper |
||
119 | * |
||
120 | * @return Client |
||
121 | */ |
||
122 | View Code Duplication | private function getApiClient(OauthTokenService $oauthTokenService, ApiDetails $apiDetails, ClientProxy $clientProxy, Helper\File $fileHelper, Helper\Csv $csvHelper, Helper\Time $timeHelper) |
|
123 | { |
||
124 | $apiClient = new Client($oauthTokenService, $apiDetails, $clientProxy, $fileHelper, $csvHelper, $timeHelper); |
||
125 | $apiClient->setConfig(['cache_dir' => '/tmp']); |
||
126 | |||
127 | return $apiClient; |
||
128 | } |
||
129 | |||
130 | View Code Duplication | private function generateSoapFault($code) |
|
144 | } |
||
145 |
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.