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 PredisSubscribeEventQueue implements SubscribeEventQueue |
||
19 | { |
||
20 | /** |
||
21 | * @var RedisPubSubAdapter |
||
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 callable[] |
||
37 | */ |
||
38 | private $handlers = []; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $queue_name = ''; |
||
44 | |||
45 | /** |
||
46 | * @var bool |
||
47 | */ |
||
48 | private $subscribed = false; |
||
49 | |||
50 | /** |
||
51 | * @param RedisPubSubAdapter $client |
||
52 | * @param Serializer $serializer |
||
53 | * @param LoggerInterface $logger |
||
54 | * @param string $queue_name |
||
55 | */ |
||
56 | View Code Duplication | public function __construct( |
|
67 | |||
68 | /** |
||
69 | * Publish event to queue. |
||
70 | * |
||
71 | * @param Event $event |
||
72 | * |
||
73 | * @return bool |
||
74 | */ |
||
75 | public function publish(Event $event) |
||
82 | |||
83 | /** |
||
84 | * Subscribe on event queue. |
||
85 | * |
||
86 | * @param callable $handler |
||
87 | */ |
||
88 | public function subscribe(callable $handler) |
||
100 | |||
101 | /** |
||
102 | * Unsubscribe on event queue. |
||
103 | * |
||
104 | * @param callable $handler |
||
105 | * |
||
106 | * @return bool |
||
107 | */ |
||
108 | View Code Duplication | public function unsubscribe(callable $handler) |
|
120 | |||
121 | /** |
||
122 | * @param mixed $message |
||
123 | */ |
||
124 | View Code Duplication | private function handle($message) |
|
143 | } |
||
144 |