Complex classes like WC_Order_Item_Product often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WC_Order_Item_Product, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 11 | class WC_Order_Item_Product 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 | 'product_id' => 0,  | 
            ||
| 23 | 'variation_id' => 0,  | 
            ||
| 24 | 'qty' => 0,  | 
            ||
| 25 | 'tax_class' => '',  | 
            ||
| 26 | 'subtotal' => 0,  | 
            ||
| 27 | 'subtotal_tax' => 0,  | 
            ||
| 28 | 'total' => 0,  | 
            ||
| 29 | 'total_tax' => 0,  | 
            ||
| 30 | 'taxes' => array(  | 
            ||
| 31 | 'subtotal' => array(),  | 
            ||
| 32 | 'total' => array()  | 
            ||
| 33 | ),  | 
            ||
| 34 | 'meta_data' => array(),  | 
            ||
| 35 | );  | 
            ||
| 36 | |||
| 37 | /**  | 
            ||
| 38 | * offsetGet for ArrayAccess/Backwards compatibility.  | 
            ||
| 39 | * @todo Add deprecation notices in future release.  | 
            ||
| 40 | * @param string $offset  | 
            ||
| 41 | * @return mixed  | 
            ||
| 42 | */  | 
            ||
| 43 |     public function offsetGet( $offset ) { | 
            ||
| 61 | |||
| 62 | /**  | 
            ||
| 63 | * offsetExists for ArrayAccess  | 
            ||
| 64 | * @param string $offset  | 
            ||
| 65 | * @return bool  | 
            ||
| 66 | */  | 
            ||
| 67 |     public function offsetExists( $offset ) { | 
            ||
| 73 | |||
| 74 | /**  | 
            ||
| 75 | * Read/populate data properties specific to this order item.  | 
            ||
| 76 | */  | 
            ||
| 77 |     protected function read( $id ) { | 
            ||
| 91 | |||
| 92 | /**  | 
            ||
| 93 | * Save properties specific to this order item.  | 
            ||
| 94 | */  | 
            ||
| 95 |     protected function save() { | 
            ||
| 109 | |||
| 110 | /**  | 
            ||
| 111 | * Internal meta keys we don't want exposed as part of meta_data.  | 
            ||
| 112 | * @return array()  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 113 | */  | 
            ||
| 114 |     protected function get_internal_meta_keys() { | 
            ||
| 117 | |||
| 118 | /**  | 
            ||
| 119 | * Get the associated product.  | 
            ||
| 120 | * @return WC_Product|bool  | 
            ||
| 121 | */  | 
            ||
| 122 |     public function get_product() { | 
            ||
| 129 | |||
| 130 | /**  | 
            ||
| 131 | * Get tax status.  | 
            ||
| 132 | * @return string  | 
            ||
| 133 | */  | 
            ||
| 134 |     public function get_tax_status() { | 
            ||
| 138 | |||
| 139 | /*  | 
            ||
| 140 | |--------------------------------------------------------------------------  | 
            ||
| 141 | | Setters  | 
            ||
| 142 | |--------------------------------------------------------------------------  | 
            ||
| 143 | */  | 
            ||
| 144 | |||
| 145 | /**  | 
            ||
| 146 | * Set qty.  | 
            ||
| 147 | * @param int $value  | 
            ||
| 148 | */  | 
            ||
| 149 |     public function set_qty( $value ) { | 
            ||
| 152 | |||
| 153 | /**  | 
            ||
| 154 | * Set tax class.  | 
            ||
| 155 | * @param string $value  | 
            ||
| 156 | */  | 
            ||
| 157 |     public function set_tax_class( $value ) { | 
            ||
| 160 | |||
| 161 | /**  | 
            ||
| 162 | * Set Product ID  | 
            ||
| 163 | * @param int $value  | 
            ||
| 164 | */  | 
            ||
| 165 |     public function set_product_id( $value ) { | 
            ||
| 168 | |||
| 169 | /**  | 
            ||
| 170 | * Set variation ID.  | 
            ||
| 171 | * @param int $value  | 
            ||
| 172 | */  | 
            ||
| 173 |     public function set_variation_id( $value ) { | 
            ||
| 176 | |||
| 177 | /**  | 
            ||
| 178 | * Line subtotal (before discounts).  | 
            ||
| 179 | * @param string $value  | 
            ||
| 180 | */  | 
            ||
| 181 |     public function set_subtotal( $value ) { | 
            ||
| 184 | |||
| 185 | /**  | 
            ||
| 186 | * Line total (after discounts).  | 
            ||
| 187 | * @param string $value  | 
            ||
| 188 | */  | 
            ||
| 189 |     public function set_total( $value ) { | 
            ||
| 192 | |||
| 193 | /**  | 
            ||
| 194 | * Line subtotal tax (before discounts).  | 
            ||
| 195 | * @param string $value  | 
            ||
| 196 | */  | 
            ||
| 197 |     public function set_subtotal_tax( $value ) { | 
            ||
| 200 | |||
| 201 | /**  | 
            ||
| 202 | * Line total tax (after discounts).  | 
            ||
| 203 | * @param string $value  | 
            ||
| 204 | */  | 
            ||
| 205 |     public function set_total_tax( $value ) { | 
            ||
| 208 | |||
| 209 | /**  | 
            ||
| 210 | * Set line taxes.  | 
            ||
| 211 | * @param array $raw_tax_data  | 
            ||
| 212 | */  | 
            ||
| 213 |     public function set_taxes( $raw_tax_data ) { | 
            ||
| 225 | |||
| 226 | /**  | 
            ||
| 227 | * Set variation data (stored as meta data - write only).  | 
            ||
| 228 | * @param array $data Key/Value pairs  | 
            ||
| 229 | */  | 
            ||
| 230 |     public function set_variations( $data ) { | 
            ||
| 235 | |||
| 236 | /*  | 
            ||
| 237 | |--------------------------------------------------------------------------  | 
            ||
| 238 | | Getters  | 
            ||
| 239 | |--------------------------------------------------------------------------  | 
            ||
| 240 | */  | 
            ||
| 241 | |||
| 242 | /**  | 
            ||
| 243 | * Get order item type.  | 
            ||
| 244 | * @return string  | 
            ||
| 245 | */  | 
            ||
| 246 |     public function get_type() { | 
            ||
| 249 | |||
| 250 | /**  | 
            ||
| 251 | * Get product ID.  | 
            ||
| 252 | * @return int  | 
            ||
| 253 | */  | 
            ||
| 254 |     public function get_product_id() { | 
            ||
| 257 | |||
| 258 | /**  | 
            ||
| 259 | * Get variation ID.  | 
            ||
| 260 | * @return int  | 
            ||
| 261 | */  | 
            ||
| 262 |     public function get_variation_id() { | 
            ||
| 265 | |||
| 266 | /**  | 
            ||
| 267 | * Get qty.  | 
            ||
| 268 | * @return int  | 
            ||
| 269 | */  | 
            ||
| 270 |     public function get_qty() { | 
            ||
| 273 | |||
| 274 | /**  | 
            ||
| 275 | * Get tax class.  | 
            ||
| 276 | * @return string  | 
            ||
| 277 | */  | 
            ||
| 278 |     public function get_tax_class() { | 
            ||
| 281 | |||
| 282 | /**  | 
            ||
| 283 | * Get subtotal.  | 
            ||
| 284 | * @return string  | 
            ||
| 285 | */  | 
            ||
| 286 |     public function get_subtotal() { | 
            ||
| 289 | |||
| 290 | /**  | 
            ||
| 291 | * Get subtotal tax.  | 
            ||
| 292 | * @return string  | 
            ||
| 293 | */  | 
            ||
| 294 |     public function get_subtotal_tax() { | 
            ||
| 297 | |||
| 298 | /**  | 
            ||
| 299 | * Get total.  | 
            ||
| 300 | * @return string  | 
            ||
| 301 | */  | 
            ||
| 302 |     public function get_total() { | 
            ||
| 305 | |||
| 306 | /**  | 
            ||
| 307 | * Get total tax.  | 
            ||
| 308 | * @return string  | 
            ||
| 309 | */  | 
            ||
| 310 |     public function get_total_tax() { | 
            ||
| 313 | |||
| 314 | /**  | 
            ||
| 315 | * Get fee taxes.  | 
            ||
| 316 | * @return array  | 
            ||
| 317 | */  | 
            ||
| 318 |     public function get_taxes() { | 
            ||
| 321 | |||
| 322 | /**  | 
            ||
| 323 | * Get meta data.  | 
            ||
| 324 | * @return array of key/value pairs  | 
            ||
| 325 | */  | 
            ||
| 326 |     public function get_meta_data() { | 
            ||
| 329 | }  | 
            ||
| 330 | 
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.