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 |
||
35 | View Code Duplication | class Input extends Column implements InputInterface |
|
|
|||
36 | { |
||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $max; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $range; |
||
46 | |||
47 | /** |
||
48 | * @var int |
||
49 | */ |
||
50 | protected $size; |
||
51 | |||
52 | /** |
||
53 | * Input constructor. |
||
54 | * |
||
55 | * @param string $columnName |
||
56 | * @param $configuration |
||
57 | */ |
||
58 | public function __construct($columnName, $configuration) |
||
65 | |||
66 | /** |
||
67 | * @return int |
||
68 | */ |
||
69 | public function getMax() |
||
73 | |||
74 | /** |
||
75 | * @return array |
||
76 | */ |
||
77 | public function getRange() |
||
81 | |||
82 | /** |
||
83 | * @return int |
||
84 | */ |
||
85 | public function getSize() |
||
89 | } |
||
90 |
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.