Code Duplication    Length = 25-25 lines in 2 locations

src/PhpSpreadsheet/Calculation/Financial.php 2 locations

@@ 833-857 (lines=25) @@
830
     *
831
     * @return float
832
     */
833
    public static function CUMIPMT($rate, $nper, $pv, $start, $end, $type = 0)
834
    {
835
        $rate = Functions::flattenSingleValue($rate);
836
        $nper = (int) Functions::flattenSingleValue($nper);
837
        $pv = Functions::flattenSingleValue($pv);
838
        $start = (int) Functions::flattenSingleValue($start);
839
        $end = (int) Functions::flattenSingleValue($end);
840
        $type = (int) Functions::flattenSingleValue($type);
841
842
        // Validate parameters
843
        if ($type != 0 && $type != 1) {
844
            return Functions::NAN();
845
        }
846
        if ($start < 1 || $start > $end) {
847
            return Functions::VALUE();
848
        }
849
850
        // Calculate
851
        $interest = 0;
852
        for ($per = $start; $per <= $end; ++$per) {
853
            $interest += self::IPMT($rate, $per, $nper, $pv, 0, $type);
854
        }
855
856
        return $interest;
857
    }
858
859
    /**
860
     * CUMPRINC.
@@ 881-905 (lines=25) @@
878
     *
879
     * @return float
880
     */
881
    public static function CUMPRINC($rate, $nper, $pv, $start, $end, $type = 0)
882
    {
883
        $rate = Functions::flattenSingleValue($rate);
884
        $nper = (int) Functions::flattenSingleValue($nper);
885
        $pv = Functions::flattenSingleValue($pv);
886
        $start = (int) Functions::flattenSingleValue($start);
887
        $end = (int) Functions::flattenSingleValue($end);
888
        $type = (int) Functions::flattenSingleValue($type);
889
890
        // Validate parameters
891
        if ($type != 0 && $type != 1) {
892
            return Functions::NAN();
893
        }
894
        if ($start < 1 || $start > $end) {
895
            return Functions::VALUE();
896
        }
897
898
        // Calculate
899
        $principal = 0;
900
        for ($per = $start; $per <= $end; ++$per) {
901
            $principal += self::PPMT($rate, $per, $nper, $pv, 0, $type);
902
        }
903
904
        return $principal;
905
    }
906
907
    /**
908
     * DB.