| Conditions | 7 |
| Paths | 12 |
| Total Lines | 54 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 50 | protected function set_common_props( &$object ) { |
||
| 51 | $props = [ |
||
| 52 | 'status', |
||
| 53 | 'sku', |
||
| 54 | 'virtual', |
||
| 55 | 'downloadable', |
||
| 56 | 'download_limit', |
||
| 57 | 'download_expiry', |
||
| 58 | 'manage_stock', |
||
| 59 | 'stock_status', |
||
| 60 | 'backorders', |
||
| 61 | 'regular_price', |
||
| 62 | 'sale_price', |
||
| 63 | 'date_on_sale_from', |
||
| 64 | 'date_on_sale_from_gmt', |
||
| 65 | 'date_on_sale_to', |
||
| 66 | 'date_on_sale_to_gmt', |
||
| 67 | 'tax_class', |
||
| 68 | 'description', |
||
| 69 | 'menu_order', |
||
| 70 | 'stock_quantity', |
||
| 71 | 'image', |
||
| 72 | 'downloads', |
||
| 73 | 'attributes', |
||
| 74 | 'weight', |
||
| 75 | 'dimensions', |
||
| 76 | 'shipping_class', |
||
| 77 | ]; |
||
| 78 | |||
| 79 | $request_props = array_intersect_key( $this->request, array_flip( $props ) ); |
||
| 80 | $prop_values = []; |
||
| 81 | |||
| 82 | foreach ( $request_props as $prop => $value ) { |
||
| 83 | switch ( $prop ) { |
||
| 84 | case 'image': |
||
| 85 | $prop_values['image_id'] = $this->parse_image_field( $value, $object ); |
||
| 86 | break; |
||
| 87 | case 'attributes': |
||
| 88 | $prop_values['attributes'] = $this->parse_attributes_field( $value, $object ); |
||
| 89 | break; |
||
| 90 | case 'dimensions': |
||
| 91 | $dimensions = $this->parse_dimensions_fields( $value ); |
||
| 92 | $prop_values = array_merge( $prop_values, $dimensions ); |
||
| 93 | break; |
||
| 94 | case 'shipping_class': |
||
| 95 | $prop_values['shipping_class_id'] = $this->parse_shipping_class( $value, $object ); |
||
| 96 | break; |
||
| 97 | default: |
||
| 98 | $prop_values[ $prop ] = $value; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | foreach ( $prop_values as $prop => $value ) { |
||
| 103 | $object->{"set_$prop"}( $value ); |
||
| 104 | } |
||
| 189 |