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 |
||
| 10 | class ResponseWaitter |
||
| 11 | { |
||
| 12 | /** @var Client */ |
||
| 13 | private $httpClient; |
||
| 14 | /** @var ProgressBar */ |
||
| 15 | private $progressBar; |
||
| 16 | private $timeout = 30000000; |
||
| 17 | private $waitInterval = 25000; // 0.025 seconds |
||
| 18 | |||
| 19 | public function __construct(Client $httpClient, $timeoutSeconds = 30000000, $waitInterval = 25000) |
||
| 25 | |||
| 26 | public function getTimeout() |
||
| 30 | |||
| 31 | public function setTimeout($timeoutSeconds) |
||
| 35 | |||
| 36 | public function setProgressBar(ProgressBar $progressBar) |
||
| 40 | |||
| 41 | private function progressBarStart() |
||
| 45 | |||
| 46 | private function progressBarSetProgress() |
||
| 50 | |||
| 51 | private function progressBarFinish() |
||
| 55 | |||
| 56 | private function updateTimeleft() |
||
| 65 | |||
| 66 | public function isAvailable($url, $requestOptions) |
||
| 76 | |||
| 77 | View Code Duplication | public function waitUntilAvailable($url, $requestOptions) |
|
| 89 | |||
| 90 | View Code Duplication | public function waitUntilNotAvailable($url, $requestOptions) |
|
| 102 | } |
||
| 103 |