| Conditions | 28 |
| Paths | 345 |
| Total Lines | 169 |
| Code Lines | 111 |
| Lines | 40 |
| Ratio | 23.67 % |
| 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 if ( !defined( 'ABSPATH' ) ) exit; |
||
| 13 | public function install() { |
||
| 14 | global $table_prefix, $wpdb; |
||
| 15 | |||
| 16 | /*Create config informations*/ |
||
| 17 | $conf = get_option('wps_barcode'); |
||
| 18 | |||
| 19 | if ( empty($conf) ) { |
||
| 20 | $conf['generate_barcode'] = false; |
||
| 21 | $conf['type'] = 'internal'; |
||
| 22 | $conf['internal_client'] = '040'; |
||
| 23 | $conf['internal_provider'] = '041'; |
||
| 24 | $conf['internal_invoice_client'] = '042'; |
||
| 25 | $conf['internal_do_client'] = '043'; |
||
| 26 | $conf['internal_product'] = '044'; |
||
| 27 | $conf['internal_assets_client'] = '050'; |
||
| 28 | $conf['internal_coupons'] = '051'; |
||
| 29 | $conf['internal_invoice_provider'] = '045'; |
||
| 30 | $conf['internal_do_provider'] = '046'; |
||
| 31 | |||
| 32 | $conf['normal_country_code'] = '320'; |
||
| 33 | $conf['normal_enterprise_code'] = '0001'; |
||
| 34 | |||
| 35 | add_option('wps_barcode', $conf); |
||
| 36 | |||
| 37 | /*Adding barcode for existing products*/ |
||
| 38 | $posts = get_posts( array('posts_per_page' => -1 ,'post_type' => 'wpshop_product')); |
||
|
|
|||
| 39 | foreach ( $posts as $post ) { |
||
| 40 | $meta = get_post_meta($post->ID); |
||
| 41 | |||
| 42 | $attr = wpshop_attributes_set::getAttributeSetDetails($meta['_wpshop_product_attribute_set_id']); |
||
| 43 | $output_order = array(); |
||
| 44 | |||
| 45 | if ( count($attr) > 0 ) { |
||
| 46 | if (!empty($attr) ) { |
||
| 47 | foreach ( $attr as $product_attr_group_id => |
||
| 48 | $product_attr_group_detail) { |
||
| 49 | foreach ( $product_attr_group_detail['attribut'] |
||
| 50 | as $position => $attribute_def) { |
||
| 51 | if ( !empty($attribute_def->code) |
||
| 52 | AND $attribute_def->code === 'barcode') { |
||
| 53 | |||
| 54 | $types_with_barcode = array( |
||
| 55 | WPSHOP_IDENTIFIER_PRODUCT, |
||
| 56 | WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
||
| 57 | WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
||
| 58 | WPSHOP_NEWTYPE_IDENTIFIER_COUPON, |
||
| 59 | WPSHOP_NEWTYPE_IDENTIFIER_ORDER, |
||
| 60 | ); |
||
| 61 | |||
| 62 | if ( !empty( $post->post_type ) && |
||
| 63 | in_array( $post->post_type, |
||
| 64 | $types_with_barcode ) ) { |
||
| 65 | |||
| 66 | $ref = ''; |
||
| 67 | |||
| 68 | View Code Duplication | if ( strlen($post->ID) < 5 ) { |
|
| 69 | $length = 5-strlen($post->ID); |
||
| 70 | for ($i = 0; $i < $length; $i++) { |
||
| 71 | $ref .= '0'; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | $ref .= strval($post->ID); |
||
| 76 | |||
| 77 | View Code Duplication | if ( $conf['type'] === 'normal' ) { |
|
| 78 | $array['normal'] = array('country' => |
||
| 79 | $conf['normal_country_code'], |
||
| 80 | 'enterprise' => |
||
| 81 | $conf['normal_enterprise_code'],'ID' => $ref); |
||
| 82 | } |
||
| 83 | else if ( $conf['type'] === 'internal' ) { |
||
| 84 | $pDate = new DateTime($post->post_date); |
||
| 85 | $date = $pDate->format('my'); |
||
| 86 | |||
| 87 | if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT || |
||
| 88 | $post->post_type === WPSHOP_IDENTIFIER_PRODUCT) { |
||
| 89 | $type = $conf['internal_product']; |
||
| 90 | } |
||
| 91 | else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_ORDER) { |
||
| 92 | $type = $conf['internal_invoice_client']; |
||
| 93 | } |
||
| 94 | else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) { |
||
| 95 | $type = $conf['internal_coupons']; |
||
| 96 | } |
||
| 97 | else { |
||
| 98 | $type = '000'; |
||
| 99 | } |
||
| 100 | |||
| 101 | $array['internal'] = array('type' => $type, |
||
| 102 | 'date' => $date, |
||
| 103 | 'ID' => $ref); |
||
| 104 | } |
||
| 105 | |||
| 106 | $barcode = $this->wps_generate_barcode($array); |
||
| 107 | $data = array('entity_type_id' => 4, |
||
| 108 | 'attribute_id' => '12', |
||
| 109 | 'entity_id' => $post->ID, |
||
| 110 | 'user_id' => $post->post_author, |
||
| 111 | 'value' => $barcode, |
||
| 112 | 'creation_date_value' => date( 'Y-m-d H:i:s' )); |
||
| 113 | |||
| 114 | |||
| 115 | $query = $wpdb->prepare( " |
||
| 116 | SELECT * |
||
| 117 | FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . " |
||
| 118 | WHERE entity_id = %d |
||
| 119 | AND attribute_id = ( |
||
| 120 | SELECT id |
||
| 121 | FROM " . WPSHOP_DBT_ATTRIBUTE . " |
||
| 122 | WHERE code = %s |
||
| 123 | )" , $post->ID, 'barcode' ); |
||
| 124 | $result = $wpdb->get_results( $query, ARRAY_A ); |
||
| 125 | |||
| 126 | if ( empty($result) ) { |
||
| 127 | $wpdb->insert($table_prefix. |
||
| 128 | 'wpshop__attribute_value_varchar', $data); |
||
| 129 | } elseif( empty( $result[0]['value'] ) ) { |
||
| 130 | $wpdb->update($table_prefix. |
||
| 131 | 'wpshop__attribute_value_varchar', $data, array( 'value_id' => $result[0]['value_id'] ) ); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | /*Adding barcode for existing coupon*/ |
||
| 142 | $posts = get_posts( array('posts_per_page' => -1 ,'post_type' => 'wpshop_shop_coupon') ); |
||
| 143 | foreach ( $posts as $post ) { |
||
| 144 | $meta = get_post_meta($post->ID); |
||
| 145 | if ( empty($meta['wpshop_coupon_barcode']) ) { |
||
| 146 | if ( $conf['type'] === 'normal' ) { |
||
| 147 | $array['normal'] = array('country' => |
||
| 148 | $conf['normal_country_code'], |
||
| 149 | 'enterprise' => |
||
| 150 | $conf['normal_enterprise_code'],'ID' => $ref); |
||
| 151 | } |
||
| 152 | else if ( $conf['type'] === 'internal' ) { |
||
| 153 | $pDate = new DateTime($post->post_date); |
||
| 154 | $date = $pDate->format('my'); |
||
| 155 | |||
| 156 | if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) { |
||
| 157 | $type = $conf['internal_coupons']; |
||
| 158 | } |
||
| 159 | else { |
||
| 160 | $type = '000'; |
||
| 161 | } |
||
| 162 | |||
| 163 | $ref = ''; |
||
| 164 | View Code Duplication | if ( strlen($post->ID) < 5 ) { |
|
| 165 | $length = 5-strlen($post->ID); |
||
| 166 | for ($i = 0; $i < $length; $i++) { |
||
| 167 | $ref .= '0'; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | $ref .= strval($post->ID); |
||
| 172 | $array['internal'] = array('type' => $type, |
||
| 173 | 'date' => $date, |
||
| 174 | 'ID' => $ref); |
||
| 175 | } |
||
| 176 | $barcode = $this->wps_generate_barcode($array); |
||
| 177 | update_post_meta($post->ID, 'wpshop_coupon_barcode', $barcode); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 335 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.