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 |
||
| 7 | class DNumber extends Scalar |
||
| 8 | { |
||
| 9 | /** @var float Number value */ |
||
| 10 | public $value; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Constructs a float number scalar node. |
||
| 14 | * |
||
| 15 | * @param float $value Value of the number |
||
| 16 | * @param array $attributes Additional attributes |
||
| 17 | */ |
||
| 18 | public function __construct($value, array $attributes = array()) { |
||
| 22 | |||
| 23 | public function getSubNodeNames() { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @internal |
||
| 29 | * |
||
| 30 | * Parses a DNUMBER token like PHP would. |
||
| 31 | * |
||
| 32 | * @param string $str A string number |
||
| 33 | * |
||
| 34 | * @return float The parsed number |
||
| 35 | */ |
||
| 36 | public static function parse($str) { |
||
| 64 | } |
||
| 65 |
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.