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 |
||
8 | class Queue implements QueueInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var \AMQPQueue |
||
12 | */ |
||
13 | protected $delegate; |
||
14 | |||
15 | /** |
||
16 | * @var ChannelInterface |
||
17 | */ |
||
18 | protected $channel; |
||
19 | |||
20 | /** |
||
21 | * @var array<integer, integer> |
||
22 | */ |
||
23 | protected static $flagMap = [ |
||
24 | self::NOPARAM => AMQP_NOPARAM, |
||
25 | self::DURABLE => AMQP_DURABLE, |
||
26 | self::PASSIVE => AMQP_PASSIVE, |
||
27 | self::EXCLUSIVE => AMQP_EXCLUSIVE, |
||
28 | self::AUTODELETE => AMQP_AUTODELETE, |
||
29 | self::MULTIPLE => AMQP_MULTIPLE, |
||
30 | self::AUTOACK => AMQP_AUTOACK, |
||
31 | self::REQUEUE => AMQP_REQUEUE, |
||
32 | self::IFUNUSED => AMQP_IFUNUSED, |
||
33 | self::IFEMPTY => AMQP_IFEMPTY, |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * @param \AMQPQueue $delegate |
||
38 | * @param ChannelInterface $channel |
||
39 | */ |
||
40 | 3 | public function __construct(\AMQPQueue $delegate, ChannelInterface $channel) |
|
41 | { |
||
42 | 3 | $this->delegate = $delegate; |
|
43 | 3 | $this->channel = $channel; |
|
44 | 3 | } |
|
45 | |||
46 | /** |
||
47 | * @inheritdoc |
||
48 | */ |
||
49 | 1 | public function getChannel() |
|
53 | |||
54 | /** |
||
55 | * @inheritdoc |
||
56 | */ |
||
57 | 1 | public function getConnection() |
|
61 | |||
62 | /** |
||
63 | * @inheritdoc |
||
64 | */ |
||
65 | 1 | public function setName($name) |
|
69 | |||
70 | /** |
||
71 | * @inheritdoc |
||
72 | */ |
||
73 | 2 | public function getName() |
|
77 | |||
78 | /** |
||
79 | * @inheritdoc |
||
80 | */ |
||
81 | 1 | public function setArgument($key, $value) |
|
82 | { |
||
83 | 1 | return $this->delegate->setArgument($key, $value); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | 1 | public function setArguments(array $arguments) |
|
90 | { |
||
91 | 1 | return $this->delegate->setArguments($arguments); |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * @inheritdoc |
||
96 | */ |
||
97 | 2 | public function getArgument($key) |
|
101 | |||
102 | /** |
||
103 | * @inheritdoc |
||
104 | */ |
||
105 | 2 | public function getArguments() |
|
109 | |||
110 | /** |
||
111 | * @inheritdoc |
||
112 | */ |
||
113 | 1 | public function hasArgument($key) |
|
117 | |||
118 | /** |
||
119 | * @inheritDoc |
||
120 | */ |
||
121 | 1 | public function setFlags($flags) |
|
122 | { |
||
123 | 1 | return $this->delegate->setFlags(self::convertToDelegateFlags($flags)); |
|
124 | } |
||
125 | |||
126 | /** |
||
127 | * @inheritdoc |
||
128 | */ |
||
129 | 2 | public function getFlags() |
|
133 | |||
134 | /** |
||
135 | * @inheritdoc |
||
136 | */ |
||
137 | public function getConsumerTag() |
||
141 | |||
142 | /** |
||
143 | * @inheritdoc |
||
144 | */ |
||
145 | public function declareQueue() |
||
149 | |||
150 | /** |
||
151 | * @inheritdoc |
||
152 | */ |
||
153 | 1 | public function bind($exchangeName, $routingKey, array $arguments = []) |
|
157 | |||
158 | /** |
||
159 | * @inheritdoc |
||
160 | */ |
||
161 | public function unbind($exchangeName, $routingKey = null, array $arguments = []) |
||
165 | |||
166 | /** |
||
167 | * @inheritdoc |
||
168 | */ |
||
169 | 1 | public function get($flags = null) |
|
170 | { |
||
171 | 1 | if (false !== $envelope = $this->delegate->get(self::convertToDelegateFlags($flags))) { |
|
172 | 1 | $envelope = new Envelope($envelope); |
|
173 | } |
||
174 | |||
175 | 1 | return $envelope; |
|
176 | } |
||
177 | |||
178 | /** |
||
179 | * @inheritdoc |
||
180 | */ |
||
181 | public function consume(callable $callback, $flags = null, $consumerTag = null) |
||
185 | |||
186 | /** |
||
187 | * @inheritdoc |
||
188 | */ |
||
189 | public function ack($deliveryTag, $flags = null) |
||
193 | |||
194 | /** |
||
195 | * @inheritdoc |
||
196 | */ |
||
197 | public function nack($deliveryTag, $flags = AMQP_NOPARAM) |
||
201 | |||
202 | /** |
||
203 | * @inheritdoc |
||
204 | */ |
||
205 | public function reject($deliveryTag, $flags = AMQP_NOPARAM) |
||
209 | |||
210 | /** |
||
211 | * @inheritdoc |
||
212 | */ |
||
213 | public function cancel($consumerTag = '') |
||
217 | |||
218 | /** |
||
219 | * @inheritdoc |
||
220 | */ |
||
221 | 3 | public function delete($flags = null) |
|
225 | |||
226 | /** |
||
227 | * @inheritdoc |
||
228 | */ |
||
229 | public function purge() |
||
233 | |||
234 | /** |
||
235 | * @inheritdoc |
||
236 | * |
||
237 | * @return \AMQPQueue |
||
238 | */ |
||
239 | public function getDelegate() |
||
243 | |||
244 | /** |
||
245 | * @param int|null $flags |
||
246 | * |
||
247 | * @return int |
||
248 | */ |
||
249 | 4 | View Code Duplication | public static function convertToDelegateFlags($flags = null) |
265 | |||
266 | /** |
||
267 | * @param int|null $flags |
||
268 | * |
||
269 | * @return int |
||
270 | */ |
||
271 | 3 | View Code Duplication | public static function convertFromDelegateFlags($flags = null) |
287 | } |
||
288 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.