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 EmojiIcon extends SerializeToString implements IconInterface |
|
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $emoji; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * UrlIcon constructor. |
||
| 22 | * |
||
| 23 | * @param string $emoji |
||
| 24 | */ |
||
| 25 | 6 | public function __construct($emoji) |
|
| 29 | |||
| 30 | /** |
||
| 31 | * This will set the emoji if it is valid. |
||
| 32 | * |
||
| 33 | * @param string $emoji |
||
| 34 | * |
||
| 35 | * @throws InvalidEmojiException Thrown when the emoji is not valid |
||
| 36 | * |
||
| 37 | * @return $this |
||
| 38 | */ |
||
| 39 | 6 | private function setEmoji($emoji) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritdoc} |
||
| 62 | */ |
||
| 63 | 3 | public function getIcon() |
|
| 67 | |||
| 68 | /** |
||
| 69 | * {@inheritdoc} |
||
| 70 | */ |
||
| 71 | 2 | public function __toString() |
|
| 75 | |||
| 76 | /** |
||
| 77 | * @inheritDoc |
||
| 78 | */ |
||
| 79 | public function getType() |
||
| 83 | } |
||
| 84 |