code: public static function NPER($rate = 0, $pmt = 0, $pv = 0, $fv = 0, $type = 0)
      {
          $rate = Functions::flattenSingleValue($rate);
          $pmt = Functions::flattenSingleValue($pmt);
          $pv = Functions::flattenSingleValue($pv);
          $fv = Functions::flattenSingleValue($fv);
          $type = Functions::flattenSingleValue($type);
  
          // Validate parameters
          if ($type != 0 && $type != 1) {
              return Functions::NAN();
          }
  
          // Calculate
          if ($rate !== null && $rate != 0) {
              if ($pmt == 0 && $pv == 0) {
                  return Functions::NAN();
              }
  
              return log(($pmt * (1 + $rate * $type) / $rate - $fv) / ($pv + $pmt * (1 + $rate * $type) / $rate)) / log(1 + $rate);
          }
          if ($pmt == 0) {
              return Functions::NAN();
          }
  
          return (-$pv - $fv) / $pmt;
      }
docs: NPER.
  
  Returns the number of periods for a cash flow with constant periodic payments (annuities), and interest rate.
  
  @param float $rate Interest rate per period
  @param int $pmt Periodic payment (annuity)
  @param float $pv Present Value
  @param float $fv Future Value
  @param int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period
  
  @return float