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 |
||
| 19 | class AMQPSubscribeEventQueue implements SubscribeEventQueue |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var AMQPChannel |
||
| 23 | */ |
||
| 24 | private $channel; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var Serializer |
||
| 28 | */ |
||
| 29 | private $serializer; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var LoggerInterface |
||
| 33 | */ |
||
| 34 | private $logger; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var callable[] |
||
| 38 | */ |
||
| 39 | private $handlers = []; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $queue_name = ''; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var bool |
||
| 48 | */ |
||
| 49 | private $subscribed = false; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var bool |
||
| 53 | */ |
||
| 54 | private $declared = false; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param AMQPChannel $channel |
||
| 58 | * @param Serializer $serializer |
||
| 59 | * @param LoggerInterface $logger |
||
| 60 | * @param string $queue_name |
||
| 61 | */ |
||
| 62 | 5 | public function __construct(AMQPChannel $channel, Serializer $serializer, LoggerInterface $logger, $queue_name) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * Publish event to queue. |
||
| 72 | * |
||
| 73 | * @param Event $event |
||
| 74 | * |
||
| 75 | * @return bool |
||
| 76 | */ |
||
| 77 | 1 | public function publish(Event $event) |
|
| 85 | |||
| 86 | /** |
||
| 87 | * Subscribe on event queue. |
||
| 88 | * |
||
| 89 | * @throws \ErrorException |
||
| 90 | * |
||
| 91 | * @param callable $handler |
||
| 92 | */ |
||
| 93 | 4 | public function subscribe(callable $handler) |
|
| 119 | |||
| 120 | /** |
||
| 121 | * Unsubscribe on event queue. |
||
| 122 | * |
||
| 123 | * @param callable $handler |
||
| 124 | * |
||
| 125 | * @return bool |
||
| 126 | */ |
||
| 127 | 1 | View Code Duplication | public function unsubscribe(callable $handler) |
| 139 | |||
| 140 | 5 | private function declareQueue() |
|
| 148 | |||
| 149 | /** |
||
| 150 | * @param string $message |
||
| 151 | */ |
||
| 152 | 3 | View Code Duplication | private function handle($message) |
| 172 | } |
||
| 173 |