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 |
||
25 | class LineResolution extends MeasuredObject |
||
26 | { |
||
27 | /** |
||
28 | * @inheritDoc |
||
29 | * |
||
30 | * @throws InvalidArgumentException If given argument is not a string |
||
31 | */ |
||
32 | View Code Duplication | public function __construct($value, Unit $unit) |
|
51 | |||
52 | /** |
||
53 | * Creates a new instance from given Resolution object |
||
54 | * |
||
55 | * @param LineResolution $resolution |
||
56 | * |
||
57 | * @return LineResolution |
||
58 | */ |
||
59 | public static function fromLineResolution(LineResolution $resolution) |
||
66 | |||
67 | /** |
||
68 | * Creates a new instance with given value and a |
||
69 | * Unit of "dpi" |
||
70 | * |
||
71 | * @param mixed $value |
||
72 | * |
||
73 | * @return LineResolution |
||
74 | */ |
||
75 | public static function dpi($value) |
||
82 | } |
||
83 |
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.