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 |
||
| 12 | View Code Duplication | class Dice extends BaseType implements TypeInterface |
|
| 13 | { |
||
| 14 | /** |
||
| 15 | * {@inheritdoc} |
||
| 16 | * |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | static protected $requiredParams = ['emoji', 'value']; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * {@inheritdoc} |
||
| 23 | * |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | static protected $map = [ |
||
| 27 | 'emoji' => true, |
||
| 28 | 'value' => true |
||
| 29 | ]; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Emoji on which the dice throw animation is based |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | protected $emoji; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Value of the dice, 1-6 for “🎲” and “🎯” base emoji, 1-5 for “🏀” and “⚽” base emoji, 1-64 for “🎰” base emoji |
||
| 40 | * |
||
| 41 | * @var int |
||
| 42 | */ |
||
| 43 | protected $value; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | public function getEmoji() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param string $emoji |
||
| 55 | */ |
||
| 56 | public function setEmoji($emoji) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return int |
||
| 63 | */ |
||
| 64 | public function getValue() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param int $value |
||
| 71 | */ |
||
| 72 | public function setValue($value) |
||
| 76 | } |
||
| 77 |