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 |
||
8 | class TDataServicesType extends IsOK |
||
9 | { |
||
10 | use IsOKToolboxTrait; |
||
11 | /** |
||
12 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\Schema[] $schema |
||
13 | */ |
||
14 | private $schema = []; |
||
15 | |||
16 | /** |
||
17 | * @property string $maxDataServiceVersion |
||
18 | */ |
||
19 | private $maxDataServiceVersion; |
||
20 | |||
21 | /** |
||
22 | * @property string $dataServiceVersion |
||
23 | */ |
||
24 | private $dataServiceVersion; |
||
25 | |||
26 | public function __construct($maxDataServiceVersion = '3.0', $dataServiceVersion = '3.0') |
||
44 | |||
45 | /** |
||
46 | * Gets as MaxDataServiceVersion |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getMaxDataServiceVersion() |
||
54 | |||
55 | /** |
||
56 | * Sets a new DataServiceVersion |
||
57 | * |
||
58 | * @param string $maxDataServiceVersion |
||
59 | * @return self |
||
60 | */ |
||
61 | public function setMaxDataServiceVersion($maxDataServiceVersion) |
||
71 | |||
72 | /** |
||
73 | * Gets as DataServiceVersion |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getDataServiceVersion() |
||
81 | |||
82 | /** |
||
83 | * Sets a new DataServiceVersion |
||
84 | * |
||
85 | * @param string $dataServiceVersion |
||
86 | * @return self |
||
87 | */ |
||
88 | public function setDataServiceVersion($dataServiceVersion) |
||
98 | /** |
||
99 | * Adds as schema |
||
100 | * |
||
101 | * @return self |
||
102 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\Schema $schema |
||
103 | */ |
||
104 | public function addToSchema(Schema $schema) |
||
113 | |||
114 | /** |
||
115 | * isset schema |
||
116 | * |
||
117 | * @param scalar $index |
||
118 | * @return boolean |
||
119 | */ |
||
120 | public function issetSchema($index) |
||
124 | |||
125 | /** |
||
126 | * unset schema |
||
127 | * |
||
128 | * @param scalar $index |
||
129 | * @return void |
||
130 | */ |
||
131 | public function unsetSchema($index) |
||
135 | |||
136 | /** |
||
137 | * Gets as schema |
||
138 | * |
||
139 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\Schema[] |
||
140 | */ |
||
141 | public function getSchema() |
||
145 | |||
146 | /** |
||
147 | * Sets a new schema |
||
148 | * |
||
149 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\Schema[] $dataServices |
||
150 | * @return self |
||
151 | */ |
||
152 | View Code Duplication | public function setSchema(array $dataServices) |
|
167 | |||
168 | public function isOK(&$msg = null) |
||
181 | } |
||
182 |
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.