Code Duplication    Length = 32-33 lines in 2 locations

src/Payant.php 2 locations

@@ 453-484 (lines=32) @@
450
    * @param string $amount         [Mandatory]
451
    * @param string $channel        [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]]
452
    */
453
    public function addPayment(string $reference_code, string $due_date, string $amount, string $channel){
454
        if(!$reference_code){
455
            throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
456
        }
457
458
        if(!$due_date){
459
            throw new IsNullOrInvalid("Error Processing Request - Null/Invalid date");
460
        }
461
462
        if(!$amount){
463
            throw new IsNullOrInvalid("Error Processing Request - Null/Invalid amount");
464
        }
465
466
        $valid_channels = ["Cash", "BankTransfer", "POS", "Cheque"];
467
468
        if(!$channel){
469
            throw new IsNull("Error Processing Request - Null/Invalid amount");
470
        }elseif (!in_array(ucfirst($channel), $valid_channels)) {
471
            throw new IsInvalid("Invalid Channel - Cash, BankTransfer, POS or Cheque");
472
        }
473
474
        $url = "/payments";
475
476
        $post_data = [
477
            'reference_code' => $reference_code,
478
            'date' => $due_date,
479
            'amount' => $amount,
480
            'channel' => $channel
481
        ];
482
483
        return $this->sendRequest('post', $url, ['form_params' => $post_data]);
484
    }
485
486
487
@@ 539-571 (lines=33) @@
536
    * @param string $unit_cost   [Mandatory - Product's unit cost]
537
    * @param string $type        [Mandatory - Product type 'product' or 'service']
538
    */
539
    public function addProduct(string $name, string $description, string $unit_cost, string $type){
540
        if(!$name){
541
            throw new IsNull("Error Processing Request - Null/Invalid name");
542
        }
543
544
        if(!$description){
545
            throw new IsNull("Error Processing Request - Null/Invalid description");
546
        }
547
548
        if(!$unit_cost){
549
            throw new IsNull("Error Processing Request - Null/Invalid unit_cost");
550
        }
551
552
        //Validate Product Type
553
        $valid_product_type = ["product", "service"];
554
555
        if(!$type){
556
            throw new IsNull("Error Processing Request - Null/Invalid type");
557
        }elseif (!in_array(strtolower($type), $valid_product_type)) {
558
            throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'");
559
        }
560
561
        $url = "/products";
562
563
        $post_data = [
564
            'name' => $name,
565
            'description' => $description,
566
            'unit_cost' => $unit_cost,
567
            'type' => $type
568
        ];
569
570
        return $this->sendRequest('post', $url, ['form_params' => $post_data]);
571
    }
572
573
        
574