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 |
||
11 | class Exchange implements ExchangeInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var \AMQPExchange |
||
15 | */ |
||
16 | protected $delegate; |
||
17 | |||
18 | /** |
||
19 | * @var ChannelInterface |
||
20 | */ |
||
21 | protected $channel; |
||
22 | |||
23 | /** |
||
24 | * @var array<integer, integer> |
||
25 | */ |
||
26 | protected static $flagMap = [ |
||
27 | self::NOPARAM => AMQP_NOPARAM, |
||
28 | self::DURABLE => AMQP_DURABLE, |
||
29 | self::PASSIVE => AMQP_PASSIVE, |
||
30 | self::AUTODELETE => AMQP_AUTODELETE, |
||
31 | self::INTERNAL => AMQP_INTERNAL, |
||
32 | self::IFUNUSED => AMQP_IFUNUSED, |
||
33 | self::MANDATORY => AMQP_MANDATORY, |
||
34 | self::IMMEDIATE => AMQP_IMMEDIATE, |
||
35 | self::NOWAIT => AMQP_NOWAIT, |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * @param \AMQPExchange $delegate |
||
40 | * @param ChannelInterface $channel |
||
41 | */ |
||
42 | 11 | public function __construct(\AMQPExchange $delegate, ChannelInterface &$channel) |
|
47 | |||
48 | /** |
||
49 | * @inheritdoc |
||
50 | */ |
||
51 | 1 | public function getChannel() |
|
55 | |||
56 | /** |
||
57 | * @inheritdoc |
||
58 | */ |
||
59 | 1 | public function getConnection() |
|
63 | |||
64 | /** |
||
65 | * @inheritdoc |
||
66 | */ |
||
67 | 5 | public function getName() |
|
71 | |||
72 | /** |
||
73 | * @inheritdoc |
||
74 | */ |
||
75 | 2 | public function getType() |
|
79 | |||
80 | /** |
||
81 | * @inheritdoc |
||
82 | */ |
||
83 | 1 | public function getFlags() |
|
87 | |||
88 | /** |
||
89 | * @inheritdoc |
||
90 | */ |
||
91 | 1 | public function getArgument($key) |
|
95 | |||
96 | /** |
||
97 | * @inheritdoc |
||
98 | */ |
||
99 | 1 | public function getArguments() |
|
103 | |||
104 | /** |
||
105 | * @inheritdoc |
||
106 | */ |
||
107 | 4 | View Code Duplication | public function bind($exchangeName, $routingKey, array $arguments = []) |
119 | |||
120 | /** |
||
121 | * @inheritdoc |
||
122 | */ |
||
123 | 2 | View Code Duplication | public function unbind($exchangeName, $routingKey, array $arguments = []) |
135 | |||
136 | /** |
||
137 | * @inheritdoc |
||
138 | */ |
||
139 | 6 | public function declareExchange() |
|
151 | |||
152 | /** |
||
153 | * @inheritdoc |
||
154 | */ |
||
155 | 10 | View Code Duplication | public function delete($exchangeName = null, $flags = null) |
167 | |||
168 | /** |
||
169 | * @inheritdoc |
||
170 | */ |
||
171 | 2 | View Code Duplication | public function publish($message, $routingKey = null, $flags = null, array $attributes = []) |
183 | |||
184 | /** |
||
185 | * @inheritdoc |
||
186 | * |
||
187 | * @return \AMQPExchange |
||
188 | */ |
||
189 | public function getDelegate() |
||
193 | |||
194 | /** |
||
195 | * @param int|null $flags |
||
196 | * |
||
197 | * @return int |
||
198 | */ |
||
199 | 12 | View Code Duplication | public static function convertToDelegateFlags($flags = null) |
215 | |||
216 | /** |
||
217 | * @param int|null $flags |
||
218 | * |
||
219 | * @return int |
||
220 | */ |
||
221 | 2 | View Code Duplication | public static function convertFromDelegateFlags($flags = null) |
237 | } |
||
238 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.