Code Duplication    Length = 25-25 lines in 2 locations

src/PhpSpreadsheet/Calculation/Financial.php 2 locations

@@ 817-841 (lines=25) @@
814
     *
815
     * @return float
816
     */
817
    public static function CUMIPMT($rate, $nper, $pv, $start, $end, $type = 0)
818
    {
819
        $rate = Functions::flattenSingleValue($rate);
820
        $nper = (int) Functions::flattenSingleValue($nper);
821
        $pv = Functions::flattenSingleValue($pv);
822
        $start = (int) Functions::flattenSingleValue($start);
823
        $end = (int) Functions::flattenSingleValue($end);
824
        $type = (int) Functions::flattenSingleValue($type);
825
826
        // Validate parameters
827
        if ($type != 0 && $type != 1) {
828
            return Functions::NAN();
829
        }
830
        if ($start < 1 || $start > $end) {
831
            return Functions::VALUE();
832
        }
833
834
        // Calculate
835
        $interest = 0;
836
        for ($per = $start; $per <= $end; ++$per) {
837
            $interest += self::IPMT($rate, $per, $nper, $pv, 0, $type);
838
        }
839
840
        return $interest;
841
    }
842
843
    /**
844
     * CUMPRINC.
@@ 865-889 (lines=25) @@
862
     *
863
     * @return float
864
     */
865
    public static function CUMPRINC($rate, $nper, $pv, $start, $end, $type = 0)
866
    {
867
        $rate = Functions::flattenSingleValue($rate);
868
        $nper = (int) Functions::flattenSingleValue($nper);
869
        $pv = Functions::flattenSingleValue($pv);
870
        $start = (int) Functions::flattenSingleValue($start);
871
        $end = (int) Functions::flattenSingleValue($end);
872
        $type = (int) Functions::flattenSingleValue($type);
873
874
        // Validate parameters
875
        if ($type != 0 && $type != 1) {
876
            return Functions::NAN();
877
        }
878
        if ($start < 1 || $start > $end) {
879
            return Functions::VALUE();
880
        }
881
882
        // Calculate
883
        $principal = 0;
884
        for ($per = $start; $per <= $end; ++$per) {
885
            $principal += self::PPMT($rate, $per, $nper, $pv, 0, $type);
886
        }
887
888
        return $principal;
889
    }
890
891
    /**
892
     * DB.