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 RedisFactory implements FactoryInterface |
||
| 15 | { |
||
| 16 | protected $connections = array(); |
||
| 17 | protected $messageProviders = array(); |
||
| 18 | protected $messagePublishers = array(); |
||
| 19 | |||
| 20 | /** |
||
| 21 | * {@inheritDoc} |
||
| 22 | */ |
||
| 23 | public function addConnection($name, array $connection) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * getMessageProvider. |
||
| 30 | * |
||
| 31 | * @param string $name The name of the queue where the MessageProviderInterface will found messages |
||
| 32 | * @param string $connection The name of the connection to use |
||
| 33 | * |
||
| 34 | * @return MessageProviderInterface |
||
| 35 | */ |
||
| 36 | View Code Duplication | public function getMessageProvider($name, $connection) |
|
| 50 | |||
| 51 | /** |
||
| 52 | * getMessagePublisher. |
||
| 53 | * |
||
| 54 | * @param string $name The name of the exchange where the MessagePublisher will publish |
||
| 55 | * @param string $connection The name of the connection to use |
||
| 56 | * |
||
| 57 | * @return MessagePublisherInterface |
||
| 58 | */ |
||
| 59 | View Code Duplication | public function getMessagePublisher($name, $connection) |
|
| 73 | |||
| 74 | /** |
||
| 75 | * getChannel. |
||
| 76 | * |
||
| 77 | * @param string $connection |
||
| 78 | * |
||
| 79 | * @return \Redis |
||
| 80 | */ |
||
| 81 | protected function getChannel($connection) |
||
| 92 | } |
||
| 93 |
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.