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 ClientTest extends PHPUnit_Framework_TestCase |
||
19 | { |
||
20 | const ACCESS_TOKEN = '2ec09aeccaf634d982eec793037e37fe'; |
||
21 | const REFRESH_TOKEN = '0c59f7e609b0cc467067e39d523116ce'; |
||
22 | |||
23 | public function testSetApiDetails() |
||
45 | |||
46 | /** |
||
47 | * @dataProvider getTestSoapExceptionData |
||
48 | * |
||
49 | * @param int $code |
||
50 | * @param string $exceptionClassName |
||
51 | */ |
||
52 | public function testSoapExceptions($code, $exceptionClassName) |
||
57 | |||
58 | /** |
||
59 | * @dataProvider getTestSoapExceptionData |
||
60 | * |
||
61 | * @param int $code |
||
62 | * @param string $exceptionClassName |
||
63 | */ |
||
64 | public function testSoapOperationErrorExceptions($code, $exceptionClassName) |
||
69 | |||
70 | /** |
||
71 | * @dataProvider getTestSoapExceptionData |
||
72 | * |
||
73 | * @param int $code |
||
74 | * @param string $exceptionClassName |
||
75 | */ |
||
76 | public function testSoapBatchErrorExceptions($code, $exceptionClassName) |
||
77 | { |
||
78 | $this->expectException($exceptionClassName); |
||
79 | $this->runClientSoapException($code, 'BatchErrors'); |
||
80 | } |
||
81 | |||
82 | public function getTestSoapExceptionData() |
||
111 | |||
112 | /** |
||
113 | * @param int $code |
||
114 | * @param null|string $type |
||
115 | * |
||
116 | * @return MockInterface |
||
|
|||
117 | */ |
||
118 | private function runClientSoapException($code, $type = null) |
||
135 | |||
136 | /** |
||
137 | * @return Mockery\MockInterface |
||
138 | */ |
||
139 | View Code Duplication | private function getOauthTokenServiceMock() |
|
150 | |||
151 | private function getTimeHelperMock() |
||
158 | |||
159 | /** |
||
160 | * @param OauthTokenService $oauthTokenService |
||
161 | * @param ClientProxy $clientProxy |
||
162 | * @param Helper\File $fileHelper |
||
163 | * @param Helper\Csv $csvHelper |
||
164 | * @param Helper\Time $timeHelper |
||
165 | * |
||
166 | * @return Client |
||
167 | */ |
||
168 | View Code Duplication | private function getApiClient(OauthTokenService $oauthTokenService, ApiDetails $apiDetails, ClientProxy $clientProxy, Helper\File $fileHelper, Helper\Csv $csvHelper, Helper\Time $timeHelper) |
|
175 | |||
176 | /** |
||
177 | * @param int $code |
||
178 | * @param null|string $type |
||
179 | * |
||
180 | * @return \SoapFault |
||
181 | */ |
||
182 | private function generateSoapFault($code, $type = null) |
||
206 | |||
207 | private function getClientProxyMock() |
||
219 | } |
||
220 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.