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 |
||
12 | View Code Duplication | class ParametersAnonymousType extends IsOK |
|
|
|||
13 | { |
||
14 | use IsOKToolboxTrait; |
||
15 | /** |
||
16 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionParameterType[] $parameter |
||
17 | */ |
||
18 | private $parameter = []; |
||
19 | |||
20 | /** |
||
21 | * Adds as parameter |
||
22 | * |
||
23 | * @return self |
||
24 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionParameterType $parameter |
||
25 | */ |
||
26 | public function addToParameter(TFunctionParameterType $parameter) |
||
31 | |||
32 | /** |
||
33 | * isset parameter |
||
34 | * |
||
35 | * @param scalar $index |
||
36 | * @return boolean |
||
37 | */ |
||
38 | public function issetParameter($index) |
||
42 | |||
43 | /** |
||
44 | * unset parameter |
||
45 | * |
||
46 | * @param scalar $index |
||
47 | * @return void |
||
48 | */ |
||
49 | public function unsetParameter($index) |
||
53 | |||
54 | /** |
||
55 | * Gets as parameter |
||
56 | * |
||
57 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionParameterType[] |
||
58 | */ |
||
59 | public function getParameter() |
||
63 | |||
64 | /** |
||
65 | * Sets a new parameter |
||
66 | * |
||
67 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionParameterType[] $parameter |
||
68 | * @return self |
||
69 | */ |
||
70 | public function setParameter(array $parameter) |
||
75 | |||
76 | public function isOK(&$msg = null) |
||
84 | } |
||
85 |
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.