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 |
||
| 17 | View Code Duplication | class PredisUniqueEventQueue implements EventQueueInterface |
|
| 18 | { |
||
| 19 | const LIST_KEY = 'unique_events'; |
||
| 20 | const FORMAT = 'predis'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var Client |
||
| 24 | */ |
||
| 25 | private $client; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var Serializer |
||
| 29 | */ |
||
| 30 | private $serializer; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var LoggerInterface |
||
| 34 | */ |
||
| 35 | private $logger; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param Client $client |
||
| 39 | * @param Serializer $serializer |
||
| 40 | * @param LoggerInterface $logger |
||
| 41 | */ |
||
| 42 | 4 | public function __construct(Client $client, Serializer $serializer, LoggerInterface $logger) |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Push event to queue. |
||
| 51 | * |
||
| 52 | * @param EventInterface $event |
||
| 53 | * |
||
| 54 | * @return bool |
||
| 55 | */ |
||
| 56 | 1 | public function push(EventInterface $event) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Pop event from queue. Return NULL if queue is empty. |
||
| 68 | * |
||
| 69 | * @return EventInterface|null |
||
| 70 | */ |
||
| 71 | 3 | public function pop() |
|
| 92 | } |
||
| 93 |