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 |
||
14 | class AMQPConnectionException extends AMQPException implements AMQPConnectionExceptionInterface |
||
15 | { |
||
16 | /** |
||
17 | * Create an exception that indicates a failure to establish a connection to |
||
18 | * an AMQP broker. |
||
19 | * |
||
20 | * @param ConnectionOptions $options The options used when establishing the connection. |
||
21 | * @param string $description A description of the problem. |
||
22 | * @param \Exception|null $previous The exception that caused this exception, if any. |
||
23 | * @return AMQPConnectionException |
||
24 | */ |
||
25 | public static function couldNotConnect( |
||
42 | |||
43 | /** |
||
44 | * Create an exception that indicates an attempt to use a connection that has |
||
45 | * already been closed. |
||
46 | * |
||
47 | * @param ConnectionOptions $options The options used when establishing the connection. |
||
48 | * @param \Exception|null $previous The exception that caused this exception, if any. |
||
49 | * @return AMQPConnectionException |
||
50 | */ |
||
51 | View Code Duplication | public static function notOpen( |
|
66 | |||
67 | /** |
||
68 | * Create an exception that indicates that the credentials specified in the |
||
69 | * connection options are incorrect. |
||
70 | * |
||
71 | * @param ConnectionOptions $options The options used when establishing the connection. |
||
72 | * @param \Exception|null $previous The exception that caused this exception, if any. |
||
73 | * @return AMQPConnectionException |
||
74 | */ |
||
75 | View Code Duplication | public static function authenticationFailed( |
|
91 | |||
92 | /** |
||
93 | * Create an exception that indicates a the AMQP handshake failed. |
||
94 | * |
||
95 | * @param ConnectionOptions $options The options used when establishing the connection. |
||
96 | * @param string $description A description of the problem. |
||
97 | * @param \Exception|null $previous The exception that caused this exception, if any. |
||
98 | * @return AMQPConnectionException |
||
99 | */ |
||
100 | public static function handshakeFailed( |
||
117 | |||
118 | /** |
||
119 | * Create an exception that indicates that the credentials specified in the |
||
120 | * connection options do not grant access to the requested AMQP virtual host. |
||
121 | * |
||
122 | * @param ConnectionOptions $options The options used when establishing the connection. |
||
123 | * @param \Exception|null $previous The exception that caused this exception, if any. |
||
124 | * @return AMQPConnectionException |
||
125 | */ |
||
126 | View Code Duplication | public static function authorizationFailed( |
|
143 | |||
144 | /** |
||
145 | * Create an exception that indicates that the broker has failed to send |
||
146 | * any data for a period longer than the heartbeat interval. |
||
147 | * |
||
148 | * @param ConnectionOptions $options The options used when establishing the connection. |
||
149 | * @param int $heartbeatInterval The heartbeat interval negotiated during the AMQP handshake. |
||
150 | * @param \Exception|null $previous The exception that caused this exception, if any. |
||
151 | * @return AMQPConnectionException |
||
152 | */ |
||
153 | View Code Duplication | public static function heartbeatTimedOut( |
|
171 | |||
172 | /** |
||
173 | * Create an exception that indicates an unexpected closure of the |
||
174 | * connection to the AMQP broker. |
||
175 | * |
||
176 | * @param ConnectionOptions $options The options used when establishing the connection. |
||
177 | * @param \Exception|null $previous The exception that caused this exception, if any. |
||
178 | * @return AMQPConnectionException |
||
179 | */ |
||
180 | View Code Duplication | public static function closedUnexpectedly( |
|
195 | } |
||
196 |
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.