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 | abstract class AbstractTimeAwareStage extends AbstractStage |
||
19 | { |
||
20 | /** |
||
21 | * Return true, if connect time settings should be used for time operations, false otherwise |
||
22 | * |
||
23 | * @param RequestDescriptor $operation Operation object |
||
24 | * |
||
25 | * @return bool |
||
26 | */ |
||
27 | 76 | protected function hasConnected(RequestDescriptor $operation) |
|
32 | |||
33 | /** |
||
34 | * Return timeout for current socket state |
||
35 | * |
||
36 | * @param RequestDescriptor $operation Operation object |
||
37 | * |
||
38 | * @return double |
||
39 | */ |
||
40 | 76 | View Code Duplication | protected function timeoutSetting(RequestDescriptor $operation) |
47 | |||
48 | /** |
||
49 | * Return time since last I/O for current socket state |
||
50 | * |
||
51 | * @param RequestDescriptor $operation Operation object |
||
52 | * |
||
53 | * @return double|null |
||
54 | */ |
||
55 | 76 | View Code Duplication | protected function timeSinceLastIo(RequestDescriptor $operation) |
62 | |||
63 | /** |
||
64 | * Set start or finish time in metadata of the socket |
||
65 | * |
||
66 | * @param RequestDescriptor $requestDescriptor Socket meta data |
||
67 | * @param string $key Metadata key to set |
||
68 | * |
||
69 | * @return void |
||
70 | * @throws \InvalidArgumentException |
||
71 | */ |
||
72 | 160 | protected function setSocketOperationTime(RequestDescriptor $requestDescriptor, $key) |
|
90 | } |
||
91 |