Code Duplication    Length = 28-28 lines in 3 locations

src/Payant.php 3 locations

@@ 315-342 (lines=28) @@
312
    * @param  string $end    [Format - DD/MM/YYYY]
313
    * @return object         
314
    */
315
    public function getInvoiceHistory($period = null, $start = null, $end = null){
316
        if(!$period || $period === null){
317
            throw new RequiredValueMissing("Error Processing Request - period Missing");
318
        }
319
320
        //Validate Period
321
        $valid_period_options = ["today", "week", "month", "30", "90", "year", "custom"];
322
323
        if (!in_array($period, $valid_period_options)) {
324
            throw new IsInvalid("Invalid Period - Available options: today, week, month, 30, 90, year or custom");
325
        }
326
327
        $post_data = [
328
            'period' => $period
329
        ];
330
331
        if ($period == 'custom'){
332
            if (!$start || !$end || $start === null || $end === null){
333
                throw new IsNull("Invalid custom Start or End date");
334
            }
335
            $post_data['start'] = $start;
336
            $post_data['end'] = $end;
337
        }
338
339
        $url = "/invoices/history";
340
341
        return $this->sendRequest('post', $url, ['form_params' => $post_data]);
342
    }
343
344
345
@@ 427-454 (lines=28) @@
424
    * @param  string $end    [Format - DD/MM/YYYY]
425
    * @return object         
426
    */
427
    public function getTransferHistory($period = null, $start = null, $end = null){
428
        if(!$period || $period === null){
429
            throw new RequiredValueMissing("Error Processing Request - period Missing");
430
        }
431
432
        //Validate Period
433
        $valid_period_options = ["today", "week", "month", "30", "90", "year", "custom"];
434
435
        if (!in_array($period, $valid_period_options)) {
436
            throw new IsInvalid("Invalid Period - Available options: today, week, month, 30, 90, year or custom");
437
        }
438
439
        $post_data = [
440
            'period' => $period
441
        ];
442
443
        if ($period == 'custom'){
444
            if (!$start || !$end || $start === null || $end === null){
445
                throw new IsNull("Invalid custom Start or End date");
446
            }
447
            $post_data['start'] = $start;
448
            $post_data['end'] = $end;
449
        }
450
451
        $url = "/transfers/history";
452
453
        return $this->sendRequest('post', $url, ['form_params' => $post_data]);
454
    }
455
456
457
@@ 549-576 (lines=28) @@
546
    * @param  string $end    [Format - DD/MM/YYYY || Optional if $period !== 'custom']
547
    * @return object         
548
    */
549
    public function getPaymentHistory(string $period = null, string $start = null, string $end = null){
550
        if(!$period || $period === null){
551
            throw new RequiredValueMissing("Error Processing Request - period Missing");
552
        }
553
554
        //Validate Period
555
        $valid_period_options = ["today", "week", "month", "30", "90", "year", "custom"];
556
557
        if (!in_array(strtolower($period), $valid_period_options)) {
558
            throw new IsInvalid("Invalid Period - Available options: today, week, month, 30, 90, year or custom");
559
        }
560
561
        $post_data = [
562
            'period' => $period
563
        ];
564
565
        if ($period == 'custom'){
566
            if (!$start || !$end || $start === null || $end === null){
567
                throw new IsNull("Invalid custom Start or End date");
568
            }
569
            $post_data['start'] = $start;
570
            $post_data['end'] = $end;
571
        }
572
573
        $url = "/payments/history";
574
575
        return $this->sendRequest('post', $url, ['form_params' => $post_data]);
576
    }
577
578
    
579