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 |
||
| 13 | View Code Duplication | class ContinueOnExceptionHandler implements QueueHandler, LoggerAwareInterface |
|
|
|
|||
| 14 | { |
||
| 15 | use LoggerAwareTrait; |
||
| 16 | |||
| 17 | /** @var QueueHandler */ |
||
| 18 | private $handler; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * AckHandler constructor. |
||
| 22 | * |
||
| 23 | * @param QueueHandler $handler |
||
| 24 | */ |
||
| 25 | public function __construct(QueueHandler $handler) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Handle a message. |
||
| 34 | * |
||
| 35 | * @param Message $message |
||
| 36 | * |
||
| 37 | * @return bool |
||
| 38 | */ |
||
| 39 | public function handle(Message $message) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Modify and return the options for consumption. |
||
| 57 | * |
||
| 58 | * @param ConsumeOptions $options |
||
| 59 | * |
||
| 60 | * @return ConsumeOptions |
||
| 61 | */ |
||
| 62 | public function options(ConsumeOptions $options) |
||
| 66 | } |
||
| 67 |
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.