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 | class PredisPullEventQueue implements PullEventQueue |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var ClientInterface |
||
| 22 | */ |
||
| 23 | private $client; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var Serializer |
||
| 27 | */ |
||
| 28 | private $serializer; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var LoggerInterface |
||
| 32 | */ |
||
| 33 | private $logger; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $queue_name = ''; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param ClientInterface $client |
||
| 42 | * @param Serializer $serializer |
||
| 43 | * @param LoggerInterface $logger |
||
| 44 | * @param string $queue_name |
||
| 45 | */ |
||
| 46 | 3 | View Code Duplication | public function __construct(ClientInterface $client, Serializer $serializer, LoggerInterface $logger, $queue_name) |
| 53 | |||
| 54 | /** |
||
| 55 | * Publish event to queue. |
||
| 56 | * |
||
| 57 | * @param Event $event |
||
| 58 | * |
||
| 59 | * @return bool |
||
| 60 | */ |
||
| 61 | 1 | public function publish(Event $event) |
|
| 67 | |||
| 68 | /** |
||
| 69 | * Pop event from queue. Return NULL if queue is empty. |
||
| 70 | * |
||
| 71 | * @return Event|null |
||
| 72 | */ |
||
| 73 | 2 | public function pull() |
|
| 94 | } |
||
| 95 |