Code Duplication    Length = 37-41 lines in 2 locations

includes/class-wpinv-invoice.php 2 locations

@@ 2312-2348 (lines=37) @@
2309
        return $status_label;
2310
    }
2311
    
2312
    public function get_subscription_period( $full = false ) {
2313
        $period = $this->get_meta( '_wpinv_subscr_period', true );
2314
        
2315
        // Fix period for old invoices
2316
        if ( $period == 'day' ) {
2317
            $period = 'D';
2318
        } else if ( $period == 'week' ) {
2319
            $period = 'W';
2320
        } else if ( $period == 'month' ) {
2321
            $period = 'M';
2322
        } else if ( $period == 'year' ) {
2323
            $period = 'Y';
2324
        }
2325
        
2326
        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2327
            $period = 'D';
2328
        }
2329
        
2330
        if ( $full ) {
2331
            switch( $period ) {
2332
                case 'D':
2333
                    $period = 'day';
2334
                break;
2335
                case 'W':
2336
                    $period = 'week';
2337
                break;
2338
                case 'M':
2339
                    $period = 'month';
2340
                break;
2341
                case 'Y':
2342
                    $period = 'year';
2343
                break;
2344
            }
2345
        }
2346
        
2347
        return $period;
2348
    }
2349
    
2350
    public function get_subscription_interval() {
2351
        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
@@ 2360-2400 (lines=41) @@
2357
        return $interval;
2358
    }
2359
    
2360
    public function get_subscription_trial_period( $full = false ) {
2361
        if ( !$this->is_free_trial() ) {
2362
            return '';
2363
        }
2364
        
2365
        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2366
        
2367
        // Fix period for old invoices
2368
        if ( $period == 'day' ) {
2369
            $period = 'D';
2370
        } else if ( $period == 'week' ) {
2371
            $period = 'W';
2372
        } else if ( $period == 'month' ) {
2373
            $period = 'M';
2374
        } else if ( $period == 'year' ) {
2375
            $period = 'Y';
2376
        }
2377
        
2378
        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2379
            $period = 'D';
2380
        }
2381
        
2382
        if ( $full ) {
2383
            switch( $period ) {
2384
                case 'D':
2385
                    $period = 'day';
2386
                break;
2387
                case 'W':
2388
                    $period = 'week';
2389
                break;
2390
                case 'M':
2391
                    $period = 'month';
2392
                break;
2393
                case 'Y':
2394
                    $period = 'year';
2395
                break;
2396
            }
2397
        }
2398
        
2399
        return $period;
2400
    }
2401
    
2402
    public function get_subscription_trial_interval() {
2403
        if ( !$this->is_free_trial() ) {