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 |
||
14 | class WC_Order_Item_Shipping extends WC_Order_Item { |
||
15 | |||
16 | /** |
||
17 | * Data properties of this order item object. |
||
18 | * @since 2.7.0 |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $_data = array( |
||
22 | 'order_id' => 0, |
||
23 | 'order_item_id' => 0, |
||
24 | 'method_title' => '', |
||
25 | 'method_id' => '', |
||
26 | 'total' => 0, |
||
27 | 'total_tax' => 0, |
||
28 | 'taxes' => array( |
||
29 | 'total' => array() |
||
30 | ), |
||
31 | ); |
||
32 | |||
33 | /** |
||
34 | * offsetGet for ArrayAccess/Backwards compatibility. |
||
35 | * @deprecated Add deprecation notices in future release. |
||
36 | * @param string $offset |
||
37 | * @return mixed |
||
38 | */ |
||
39 | public function offsetGet( $offset ) { |
||
45 | |||
46 | /** |
||
47 | * offsetSet for ArrayAccess/Backwards compatibility. |
||
48 | * @deprecated Add deprecation notices in future release. |
||
49 | * @param string $offset |
||
50 | * @param mixed $value |
||
51 | */ |
||
52 | public function offsetSet( $offset, $value ) { |
||
58 | |||
59 | /** |
||
60 | * offsetExists for ArrayAccess |
||
61 | * @param string $offset |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function offsetExists( $offset ) { |
||
70 | |||
71 | /** |
||
72 | * Read/populate data properties specific to this order item. |
||
73 | */ |
||
74 | public function read( $id ) { |
||
83 | |||
84 | /** |
||
85 | * Save properties specific to this order item. |
||
86 | * @return int Item ID |
||
87 | */ |
||
88 | public function save() { |
||
99 | |||
100 | /** |
||
101 | * Internal meta keys we don't want exposed as part of meta_data. |
||
102 | * @return array() |
||
|
|||
103 | */ |
||
104 | protected function get_internal_meta_keys() { |
||
107 | |||
108 | /* |
||
109 | |-------------------------------------------------------------------------- |
||
110 | | Setters |
||
111 | |-------------------------------------------------------------------------- |
||
112 | */ |
||
113 | |||
114 | /** |
||
115 | * Set order item name. |
||
116 | * @param string $value |
||
117 | */ |
||
118 | public function set_name( $value ) { |
||
121 | |||
122 | /** |
||
123 | * Set code. |
||
124 | * @param string $value |
||
125 | */ |
||
126 | public function set_method_title( $value ) { |
||
129 | |||
130 | /** |
||
131 | * Set shipping method id. |
||
132 | * @param string $value |
||
133 | */ |
||
134 | public function set_method_id( $value ) { |
||
137 | |||
138 | /** |
||
139 | * Set total. |
||
140 | * @param string $value |
||
141 | */ |
||
142 | public function set_total( $value ) { |
||
145 | |||
146 | /** |
||
147 | * Set total tax. |
||
148 | * @param string $value |
||
149 | */ |
||
150 | public function set_total_tax( $value ) { |
||
153 | |||
154 | /** |
||
155 | * Set taxes. |
||
156 | * |
||
157 | * This is an array of tax ID keys with total amount values. |
||
158 | * @param array $raw_tax_data |
||
159 | */ |
||
160 | View Code Duplication | public function set_taxes( $raw_tax_data ) { |
|
171 | |||
172 | /* |
||
173 | |-------------------------------------------------------------------------- |
||
174 | | Getters |
||
175 | |-------------------------------------------------------------------------- |
||
176 | */ |
||
177 | |||
178 | /** |
||
179 | * Get order item type. |
||
180 | * @return string |
||
181 | */ |
||
182 | public function get_type() { |
||
185 | |||
186 | /** |
||
187 | * Get order item name. |
||
188 | * @return string |
||
189 | */ |
||
190 | public function get_name() { |
||
193 | |||
194 | /** |
||
195 | * Get title. |
||
196 | * @return string |
||
197 | */ |
||
198 | public function get_method_title() { |
||
201 | |||
202 | /** |
||
203 | * Get method ID. |
||
204 | * @return string |
||
205 | */ |
||
206 | public function get_method_id() { |
||
209 | |||
210 | /** |
||
211 | * Get total cost. |
||
212 | * @return string |
||
213 | */ |
||
214 | public function get_total() { |
||
217 | |||
218 | /** |
||
219 | * Get total tax. |
||
220 | * @return string |
||
221 | */ |
||
222 | public function get_total_tax() { |
||
225 | |||
226 | /** |
||
227 | * Get taxes. |
||
228 | * @return array |
||
229 | */ |
||
230 | public function get_taxes() { |
||
233 | } |
||
234 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.