| Conditions | 14 |
| Paths | 50 |
| Total Lines | 98 |
| Code Lines | 47 |
| Lines | 36 |
| Ratio | 36.73 % |
| 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; |
||
| 187 | public function insert_barcode( $post_ID, $post, $update ) { |
||
| 188 | if ( wp_is_post_revision( $post_ID ) ) |
||
| 189 | return; |
||
| 190 | |||
| 191 | global $wpdb; |
||
| 192 | |||
| 193 | $types_with_barcode = array( |
||
| 194 | WPSHOP_IDENTIFIER_PRODUCT, |
||
| 195 | WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
||
| 196 | WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
||
| 197 | WPSHOP_NEWTYPE_IDENTIFIER_COUPON, |
||
| 198 | WPSHOP_NEWTYPE_IDENTIFIER_ORDER, |
||
| 199 | ); |
||
| 200 | |||
| 201 | /** Si c'est un type qui est dans le tableau $types_with_barcode */ |
||
| 202 | if ( !empty( $post->post_type ) && in_array( $post->post_type, |
||
| 203 | $types_with_barcode ) ) { |
||
| 204 | |||
| 205 | $conf = get_option('wps_barcode'); |
||
| 206 | $ref = ''; |
||
| 207 | |||
| 208 | View Code Duplication | if ( strlen($post_ID) < 5 ) { |
|
| 209 | $length = 5-strlen($post_ID); |
||
| 210 | for ($i = 0; $i < $length; $i++) { |
||
| 211 | $ref .= '0'; |
||
| 212 | } |
||
| 213 | } |
||
| 214 | |||
| 215 | $ref .= strval($post_ID); |
||
| 216 | |||
| 217 | View Code Duplication | if ( $conf['type'] === 'normal' ) { |
|
| 218 | $array['normal'] = array( |
||
| 219 | 'country' => $conf['normal_country_code'], |
||
| 220 | 'enterprise' => $conf['normal_enterprise_code'], |
||
| 221 | 'ID' => $ref, |
||
| 222 | ); |
||
| 223 | } |
||
| 224 | else if ( $conf['type'] === 'internal' ) { |
||
| 225 | $pDate = new DateTime($post->post_date); |
||
| 226 | $date = $pDate->format('my'); |
||
| 227 | |||
| 228 | if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT || $post->post_type === WPSHOP_IDENTIFIER_PRODUCT) { |
||
| 229 | $type = $conf['internal_product']; |
||
| 230 | } |
||
| 231 | else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_ORDER) { |
||
| 232 | $type = $conf['internal_invoice_client']; |
||
| 233 | } |
||
| 234 | else if ($post->post_type === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) { |
||
| 235 | $type = $conf['internal_coupons']; |
||
| 236 | } |
||
| 237 | else { |
||
| 238 | $type = '000'; |
||
| 239 | } |
||
| 240 | |||
| 241 | $array['internal'] = array( |
||
| 242 | 'type' => $type, |
||
| 243 | 'date' => $date, |
||
| 244 | 'ID' => $ref |
||
| 245 | ); |
||
| 246 | } |
||
| 247 | |||
| 248 | //$barcode = $this->wps_generate_barcode($array); |
||
| 249 | /** For add a product */ |
||
| 250 | $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] = !empty( $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] ) ? sanitize_text_field( $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] ) : null; |
||
| 251 | if( !isset($_REQUEST['wpshop_product_attribute']['varchar']['barcode']) ) { |
||
| 252 | wpeologs_ctr::log_datas_in_files( 'wps_barcode', |
||
| 253 | array( |
||
| 254 | 'object_id' => $post_ID, |
||
| 255 | 'message' => sprintf( __('Adding barcode: %s for %s object ID', 'wps_barcode'), '<b>'.$_REQUEST['wpshop_product_attribute']['varchar']['barcode'].'</b>', '<b>'.$post_ID.'</b>') ), |
||
| 256 | 0); |
||
| 257 | $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] = $this->wps_generate_barcode($array); |
||
| 258 | } |
||
| 259 | /*if ( isset($barcode) ) { |
||
| 260 | if ($barcode !== '') { |
||
| 261 | wpeologs_ctr::log_datas_in_files( 'wps_barcode', |
||
| 262 | array( |
||
| 263 | 'object_id' => $post_ID, |
||
| 264 | 'message' => sprintf( __('Change barcode: %s replacing %s for %s object ID', 'wps_barcode'), '<b>'.sanitize_text_field( $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] ).'</b>', '<b>'.$barcode.'</b>', '<b>'.$post_ID.'</b>') ), 0); |
||
| 265 | |||
| 266 | $barcode = sanitize_text_field( $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] ); |
||
| 267 | } |
||
| 268 | else { |
||
| 269 | wpeologs_ctr::log_datas_in_files( 'wps_barcode', |
||
| 270 | array( |
||
| 271 | 'object_id' => $post_ID, |
||
| 272 | 'message' => sprintf( __('Adding barcode: %s for %s object ID', 'wps_barcode'), '<b>'.$barcode.'</b>', '<b>'.$post_ID.'</b>') ), |
||
| 273 | 0); |
||
| 274 | |||
| 275 | // $_REQUEST['wpshop_product_attribute']['varchar']['barcode'] = $barcode; |
||
| 276 | } |
||
| 277 | } |
||
| 278 | else { |
||
| 279 | /** On met à jour l'attribut barcode *//* |
||
| 280 | $products = new wps_product_ctr(); |
||
| 281 | $products->update_the_attribute_for_product($post_ID, 'varchar', 'barcode', $barcode); |
||
| 282 | }*/ |
||
| 283 | } |
||
| 284 | } |
||
| 285 | |||
| 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.