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 |
||
| 8 | View Code Duplication | class BotCommand extends BaseType implements TypeInterface |
|
| 9 | { |
||
| 10 | /** |
||
| 11 | * {@inheritdoc} |
||
| 12 | * |
||
| 13 | * @var array |
||
| 14 | */ |
||
| 15 | static protected $requiredParams = ['command', 'description']; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * {@inheritdoc} |
||
| 19 | * |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | static protected $map = [ |
||
| 23 | 'command' => true, |
||
| 24 | 'description' => true, |
||
| 25 | ]; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Text of the command, 1-32 characters. Can contain only lowercase English letters, digits and underscores. |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $command; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Description of the command, 3-256 characters. |
||
| 36 | * |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $description; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return string |
||
| 43 | */ |
||
| 44 | 2 | public function getCommand() |
|
| 48 | |||
| 49 | /** |
||
| 50 | * @param string $command |
||
| 51 | */ |
||
| 52 | 3 | public function setCommand($command) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | 2 | public function getDescription() |
|
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $description |
||
| 67 | */ |
||
| 68 | 3 | public function setDescription($description) |
|
| 72 | } |
||
| 73 |