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 namespace rtens\domin\delivery\web\fields; |
||
9 | View Code Duplication | class TextField implements WebField { |
|
|
|||
10 | |||
11 | /** |
||
12 | * @param Parameter $parameter |
||
13 | * @return bool |
||
14 | */ |
||
15 | public function handles(Parameter $parameter) { |
||
18 | |||
19 | /** |
||
20 | * @param Parameter $parameter |
||
21 | * @param string $serialized |
||
22 | * @return mixed |
||
23 | */ |
||
24 | public function inflate(Parameter $parameter, $serialized) { |
||
27 | |||
28 | /** |
||
29 | * @param Parameter $parameter |
||
30 | * @param Text $value |
||
31 | * @return string |
||
32 | */ |
||
33 | public function render(Parameter $parameter, $value) { |
||
43 | |||
44 | /** |
||
45 | * @param Parameter $parameter |
||
46 | * @return array|\rtens\domin\delivery\web\Element[] |
||
47 | */ |
||
48 | public function headElements(Parameter $parameter) { |
||
51 | } |
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.