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 |
||
| 15 | class ExecutingSubscribeEventQueue implements SubscribeEventQueue |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var callable[] |
||
| 19 | */ |
||
| 20 | private $handlers = []; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Publish event to queue. |
||
| 24 | * |
||
| 25 | * @param Event $event |
||
| 26 | * |
||
| 27 | * @return bool |
||
| 28 | */ |
||
| 29 | 1 | public function publish(Event $event) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * Subscribe on event queue. |
||
| 41 | * |
||
| 42 | * @param callable $handler |
||
| 43 | */ |
||
| 44 | 1 | public function subscribe(callable $handler) |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Unsubscribe on event queue. |
||
| 51 | * |
||
| 52 | * @param callable $handler |
||
| 53 | * |
||
| 54 | * @return bool |
||
| 55 | */ |
||
| 56 | 1 | View Code Duplication | public function unsubscribe(callable $handler) |
| 68 | } |
||
| 69 |