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 |
||
11 | class WC_Order_Item_Shipping extends WC_Order_Item { |
||
12 | |||
13 | /** |
||
14 | * Data properties of this order item object. |
||
15 | * @since 2.6.0 |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $_data = array( |
||
19 | 'order_id' => 0, |
||
20 | 'order_item_id' => 0, |
||
21 | 'name' => '', |
||
22 | 'method_id' => '', |
||
23 | 'total' => 0, |
||
24 | 'total_tax' => 0, |
||
25 | 'taxes' => array( |
||
26 | 'total' => array() |
||
27 | ) |
||
28 | ); |
||
29 | |||
30 | /** |
||
31 | * offsetGet for ArrayAccess/Backwards compatibility. |
||
32 | * @todo Add deprecation notices in future release. |
||
33 | * @param string $offset |
||
34 | * @return mixed |
||
35 | */ |
||
36 | public function offsetGet( $offset ) { |
||
42 | |||
43 | /** |
||
44 | * offsetExists for ArrayAccess |
||
45 | * @param string $offset |
||
46 | * @return bool |
||
47 | */ |
||
48 | public function offsetExists( $offset ) { |
||
54 | |||
55 | /** |
||
56 | * Read/populate data properties specific to this order item. |
||
57 | */ |
||
58 | public function read( $id ) { |
||
67 | |||
68 | /** |
||
69 | * Save properties specific to this order item. |
||
70 | */ |
||
71 | public function save() { |
||
80 | |||
81 | /** |
||
82 | * Internal meta keys we don't want exposed as part of meta_data. |
||
83 | * @return array() |
||
|
|||
84 | */ |
||
85 | protected function get_internal_meta_keys() { |
||
88 | |||
89 | /* |
||
90 | |-------------------------------------------------------------------------- |
||
91 | | Setters |
||
92 | |-------------------------------------------------------------------------- |
||
93 | */ |
||
94 | |||
95 | /** |
||
96 | * Set shipping method id. |
||
97 | * @param string $value |
||
98 | */ |
||
99 | public function set_method_id( $value ) { |
||
102 | |||
103 | /** |
||
104 | * Set total. |
||
105 | * @param string $value |
||
106 | */ |
||
107 | public function set_total( $value ) { |
||
110 | |||
111 | /** |
||
112 | * Set total tax. |
||
113 | * @param string $value |
||
114 | */ |
||
115 | public function set_total_tax( $value ) { |
||
118 | |||
119 | /** |
||
120 | * Set taxes. |
||
121 | * |
||
122 | * This is an array of tax ID keys with total amount values. |
||
123 | * @param array $raw_tax_data |
||
124 | */ |
||
125 | View Code Duplication | public function set_taxes( $raw_tax_data ) { |
|
136 | |||
137 | /* |
||
138 | |-------------------------------------------------------------------------- |
||
139 | | Getters |
||
140 | |-------------------------------------------------------------------------- |
||
141 | */ |
||
142 | |||
143 | /** |
||
144 | * Get order item type. |
||
145 | * @return string |
||
146 | */ |
||
147 | public function get_type() { |
||
150 | |||
151 | /** |
||
152 | * Get method ID. |
||
153 | * @return string |
||
154 | */ |
||
155 | public function get_method_id() { |
||
158 | |||
159 | /** |
||
160 | * Get total cost. |
||
161 | * @return string |
||
162 | */ |
||
163 | public function get_total() { |
||
166 | |||
167 | /** |
||
168 | * Get total tax. |
||
169 | * @return string |
||
170 | */ |
||
171 | public function get_total_tax() { |
||
174 | |||
175 | /** |
||
176 | * Get taxes. |
||
177 | * @return array |
||
178 | */ |
||
179 | public function get_taxes() { |
||
182 | } |
||
183 |
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.