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 |
||
| 16 | View Code Duplication | class StringValue implements ValueInterface |
|
|
|
|||
| 17 | { |
||
| 18 | /** |
||
| 19 | * The value. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $value; |
||
| 24 | |||
| 25 | 15 | public function __construct($value) |
|
| 29 | |||
| 30 | /** |
||
| 31 | * Return the value of the Property as an escaped string. |
||
| 32 | * |
||
| 33 | * Escape values as per RFC 2445. See http://www.kanzaki.com/docs/ical/text.html |
||
| 34 | * |
||
| 35 | * @return string |
||
| 36 | */ |
||
| 37 | 13 | public function getEscapedValue() |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @param string $value |
||
| 44 | * |
||
| 45 | * @return $this |
||
| 46 | */ |
||
| 47 | public function setValue($value) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | 1 | public function getValue() |
|
| 61 | } |
||
| 62 |
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.