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 Irc extends Plugin |
||
| 15 | { |
||
| 16 | protected $message; |
||
| 17 | protected $server; |
||
| 18 | protected $port; |
||
| 19 | protected $room; |
||
| 20 | protected $nick; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @return string |
||
| 24 | */ |
||
| 25 | public static function pluginName() |
||
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritdoc} |
||
| 32 | */ |
||
| 33 | public function __construct(Builder $builder, Build $build, array $options = []) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Run IRC plugin. |
||
| 52 | * |
||
| 53 | * @return bool |
||
| 54 | */ |
||
| 55 | public function execute() |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @param resource $socket |
||
| 85 | * @param array $commands |
||
| 86 | * @return bool |
||
| 87 | */ |
||
| 88 | private function executeIrcCommands($socket, array $commands) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * |
||
| 112 | * @param resource $socket |
||
| 113 | * @param string $command |
||
| 114 | * @return bool |
||
| 115 | */ |
||
| 116 | private function executeIrcCommand($socket, $command) |
||
| 120 | } |
||
| 121 |
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.