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 |
||
| 21 | abstract class AbstractStage implements PipelineStageInterface |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Event caller |
||
| 25 | * |
||
| 26 | * @var EventCaller |
||
| 27 | */ |
||
| 28 | protected $eventCaller; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Request executor |
||
| 32 | * |
||
| 33 | * @var RequestExecutorInterface |
||
| 34 | */ |
||
| 35 | protected $executor; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Execution context |
||
| 39 | * |
||
| 40 | * @var ExecutionContext |
||
| 41 | */ |
||
| 42 | protected $executionContext; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * AbstractStage constructor. |
||
| 46 | * |
||
| 47 | * @param RequestExecutorInterface $executor Request executor |
||
| 48 | * @param EventCaller $eventCaller Event caller |
||
| 49 | * @param ExecutionContext $executionContext Execution context |
||
| 50 | */ |
||
| 51 | 204 | public function __construct( |
|
| 60 | |||
| 61 | /** |
||
| 62 | * Notify handlers about given event |
||
| 63 | * |
||
| 64 | * @param RequestDescriptor $requestDescriptor Request descriptor |
||
| 65 | * @param Event $event Event object |
||
| 66 | * |
||
| 67 | * @return void |
||
| 68 | * @throws \Exception |
||
| 69 | */ |
||
| 70 | 160 | View Code Duplication | protected function callSocketSubscribers(RequestDescriptor $requestDescriptor, Event $event) |
| 86 | |||
| 87 | /** |
||
| 88 | * Notify handlers about exception |
||
| 89 | * |
||
| 90 | * @param RequestDescriptor $requestDescriptor Socket operation object |
||
| 91 | * @param SocketException $exception Thrown exception |
||
| 92 | * |
||
| 93 | * @return void |
||
| 94 | * @throws \Exception |
||
| 95 | */ |
||
| 96 | 47 | View Code Duplication | protected function callExceptionSubscribers( |
| 114 | |||
| 115 | /** |
||
| 116 | * Create simple event |
||
| 117 | * |
||
| 118 | * @param RequestDescriptor $operation Operation item |
||
| 119 | * @param string $eventName Event name for object |
||
| 120 | * |
||
| 121 | * @return Event |
||
| 122 | */ |
||
| 123 | 150 | protected function createEvent(RequestDescriptor $operation, $eventName) |
|
| 134 | } |
||
| 135 |