Skip to content

Commit

Permalink
Switch calls to deprecated function methods to the equivalent new met…
Browse files Browse the repository at this point in the history
…hods (#1957)
  • Loading branch information
Mark Baker authored Mar 26, 2021
1 parent 9239b3d commit d36f9d5
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function evaluate($database, $field, $criteria)
return null;
}

return MathTrig::PRODUCT(
return MathTrig\Product::funcProduct(
self::getFilteredColumn($database, $field, $criteria)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DSum.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function evaluate($database, $field, $criteria)
return null;
}

return MathTrig::SUM(
return MathTrig\Sum::funcSum(
self::getFilteredColumn($database, $field, $criteria)
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/PhpSpreadsheet/Calculation/Financial/Amortization.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;

use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;

class Amortization
Expand Down Expand Up @@ -47,7 +47,7 @@ public static function AMORDEGRC($cost, $purchased, $firstPeriod, $salvage, $per
$rate = Functions::flattenSingleValue($rate);
$basis = ($basis === null) ? 0 : (int) Functions::flattenSingleValue($basis);

$yearFrac = DateTime::YEARFRAC($purchased, $firstPeriod, $basis);
$yearFrac = DateTimeExcel\YearFrac::funcYearFrac($purchased, $firstPeriod, $basis);
if (is_string($yearFrac)) {
return $yearFrac;
}
Expand Down Expand Up @@ -116,13 +116,13 @@ public static function AMORLINC($cost, $purchased, $firstPeriod, $salvage, $peri
$fOneRate = $cost * $rate;
$fCostDelta = $cost - $salvage;
// Note, quirky variation for leap years on the YEARFRAC for this function
$purchasedYear = DateTime::YEAR($purchased);
$yearFrac = DateTime::YEARFRAC($purchased, $firstPeriod, $basis);
$purchasedYear = DateTimeExcel\Year::funcYear($purchased);
$yearFrac = DateTimeExcel\YearFrac::funcYearFrac($purchased, $firstPeriod, $basis);
if (is_string($yearFrac)) {
return $yearFrac;
}

if (($basis == 1) && ($yearFrac < 1) && (DateTime::isLeapYear($purchasedYear))) {
if (($basis == 1) && ($yearFrac < 1) && (DateTimeExcel\Helpers::isLeapYear($purchasedYear))) {
$yearFrac *= 365 / 366;
}

Expand Down
23 changes: 12 additions & 11 deletions src/PhpSpreadsheet/Calculation/Financial/Coupons.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;

use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
Expand Down Expand Up @@ -60,14 +61,14 @@ public static function COUPDAYBS($settlement, $maturity, $frequency, $basis = He
return $e->getMessage();
}

$daysPerYear = Helpers::daysPerYear(DateTime::YEAR($settlement), $basis);
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
$prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS);

if ($basis === Helpers::DAYS_PER_YEAR_ACTUAL) {
return abs(DateTime::DAYS($prev, $settlement));
return abs(DateTimeExcel\Days::funcDays($prev, $settlement));
}

return DateTime::YEARFRAC($prev, $settlement, $basis) * $daysPerYear;
return DateTimeExcel\YearFrac::funcYearFrac($prev, $settlement, $basis) * $daysPerYear;
}

/**
Expand Down Expand Up @@ -121,7 +122,7 @@ public static function COUPDAYS($settlement, $maturity, $frequency, $basis = Hel
case Helpers::DAYS_PER_YEAR_ACTUAL:
// Actual/actual
if ($frequency == self::FREQUENCY_ANNUAL) {
$daysPerYear = Helpers::daysPerYear(DateTime::YEAR($settlement), $basis);
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);

return $daysPerYear / $frequency;
}
Expand Down Expand Up @@ -179,7 +180,7 @@ public static function COUPDAYSNC($settlement, $maturity, $frequency, $basis = H
return $e->getMessage();
}

$daysPerYear = Helpers::daysPerYear(DateTime::YEAR($settlement), $basis);
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
$next = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_NEXT);

if ($basis === Helpers::DAYS_PER_YEAR_NASD) {
Expand All @@ -190,7 +191,7 @@ public static function COUPDAYSNC($settlement, $maturity, $frequency, $basis = H
}
}

return DateTime::YEARFRAC($settlement, $next, $basis) * $daysPerYear;
return DateTimeExcel\YearFrac::funcYearFrac($settlement, $next, $basis) * $daysPerYear;
}

/**
Expand Down Expand Up @@ -286,7 +287,7 @@ public static function COUPNUM($settlement, $maturity, $frequency, $basis = Help
return $e->getMessage();
}

$yearsBetweenSettlementAndMaturity = DateTime::YEARFRAC($settlement, $maturity, 0);
$yearsBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, 0);

return ceil($yearsBetweenSettlementAndMaturity * $frequency);
}
Expand Down Expand Up @@ -344,11 +345,11 @@ public static function COUPPCD($settlement, $maturity, $frequency, $basis = Help
*
* Returns a boolean TRUE/FALSE indicating if this date is the last date of the month
*
* @param \DateTime $testDate The date for testing
* @param DateTime $testDate The date for testing
*
* @return bool
*/
private static function isLastDayOfMonth(\DateTime $testDate)
private static function isLastDayOfMonth(DateTime $testDate)
{
return $testDate->format('d') === $testDate->format('t');
}
Expand Down Expand Up @@ -376,7 +377,7 @@ private static function couponFirstPeriodDate($settlement, $maturity, int $frequ

private static function validateInputDate($date)
{
$date = DateTime::getDateValue($date);
$date = DateTimeExcel\Helpers::getDateValue($date);
if (is_string($date)) {
throw new Exception(Functions::VALUE());
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/Financial/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;

use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;

class Helpers
Expand Down Expand Up @@ -42,7 +42,7 @@ public static function daysPerYear($year, $basis = 0)
case self::DAYS_PER_YEAR_365:
return 365;
case self::DAYS_PER_YEAR_ACTUAL:
return (DateTime::isLeapYear($year)) ? 366 : 365;
return (DateTimeExcel\Helpers::isLeapYear($year)) ? 366 : 365;
}

return Functions::NAN();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;

use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities\Constants as SecuritiesConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
Expand All @@ -11,7 +11,7 @@ abstract class BaseValidations
{
protected static function validateInputDate($date)
{
$date = DateTime::getDateValue($date);
$date = DateTimeExcel\Helpers::getDateValue($date);
if (is_string($date)) {
throw new Exception(Functions::VALUE());
}
Expand Down
12 changes: 6 additions & 6 deletions src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;

use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Coupons;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers;
Expand Down Expand Up @@ -117,7 +117,7 @@ public static function priceDiscounted($settlement, $maturity, $discount, $redem
return $e->getMessage();
}

$daysBetweenSettlementAndMaturity = DateTime::YEARFRAC($settlement, $maturity, $basis);
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
Expand Down Expand Up @@ -169,23 +169,23 @@ public static function priceAtMaturity($settlement, $maturity, $issue, $rate, $y
return $e->getMessage();
}

$daysPerYear = Helpers::daysPerYear(DateTime::YEAR($settlement), $basis);
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
if (!is_numeric($daysPerYear)) {
return $daysPerYear;
}
$daysBetweenIssueAndSettlement = DateTime::YEARFRAC($issue, $settlement, $basis);
$daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::funcYearFrac($issue, $settlement, $basis);
if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error
return $daysBetweenIssueAndSettlement;
}
$daysBetweenIssueAndSettlement *= $daysPerYear;
$daysBetweenIssueAndMaturity = DateTime::YEARFRAC($issue, $maturity, $basis);
$daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($issue, $maturity, $basis);
if (!is_numeric($daysBetweenIssueAndMaturity)) {
// return date error
return $daysBetweenIssueAndMaturity;
}
$daysBetweenIssueAndMaturity *= $daysPerYear;
$daysBetweenSettlementAndMaturity = DateTime::YEARFRAC($settlement, $maturity, $basis);
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
Expand Down
14 changes: 7 additions & 7 deletions src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;

use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
Expand Down Expand Up @@ -49,11 +49,11 @@ public static function yieldDiscounted($settlement, $maturity, $price, $redempti
return $e->getMessage();
}

$daysPerYear = Helpers::daysPerYear(DateTime::YEAR($settlement), $basis);
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
if (!is_numeric($daysPerYear)) {
return $daysPerYear;
}
$daysBetweenSettlementAndMaturity = DateTime::YEARFRAC($settlement, $maturity, $basis);
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
Expand Down Expand Up @@ -106,23 +106,23 @@ public static function yieldAtMaturity($settlement, $maturity, $issue, $rate, $p
return $e->getMessage();
}

$daysPerYear = Helpers::daysPerYear(DateTime::YEAR($settlement), $basis);
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
if (!is_numeric($daysPerYear)) {
return $daysPerYear;
}
$daysBetweenIssueAndSettlement = DateTime::YEARFRAC($issue, $settlement, $basis);
$daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::funcYearFrac($issue, $settlement, $basis);
if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error
return $daysBetweenIssueAndSettlement;
}
$daysBetweenIssueAndSettlement *= $daysPerYear;
$daysBetweenIssueAndMaturity = DateTime::YEARFRAC($issue, $maturity, $basis);
$daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($issue, $maturity, $basis);
if (!is_numeric($daysBetweenIssueAndMaturity)) {
// return date error
return $daysBetweenIssueAndMaturity;
}
$daysBetweenIssueAndMaturity *= $daysPerYear;
$daysBetweenSettlementAndMaturity = DateTime::YEARFRAC($settlement, $maturity, $basis);
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
Expand Down
49 changes: 24 additions & 25 deletions src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;

use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;

class TreasuryBill
Expand All @@ -27,11 +28,11 @@ public static function bondEquivalentYield($settlement, $maturity, $discount)
$maturity = Functions::flattenSingleValue($maturity);
$discount = Functions::flattenSingleValue($discount);

if (
is_string($maturity = DateTime::getDateValue($maturity)) ||
is_string($settlement = DateTime::getDateValue($settlement))
) {
return Functions::VALUE();
try {
$maturity = DateTimeExcel\Helpers::getDateValue($maturity);
$settlement = DateTimeExcel\Helpers::getDateValue($settlement);
} catch (Exception $e) {
return $e->getMessage();
}

// Validate
Expand All @@ -41,11 +42,9 @@ public static function bondEquivalentYield($settlement, $maturity, $discount)
}

$daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($maturity), Helpers::DAYS_PER_YEAR_ACTUAL);

if (
$daysBetweenSettlementAndMaturity > Helpers::daysPerYear(DateTime::YEAR($maturity), Helpers::DAYS_PER_YEAR_ACTUAL) ||
$daysBetweenSettlementAndMaturity < 0
) {
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
return Functions::NAN();
}

Expand Down Expand Up @@ -75,11 +74,11 @@ public static function price($settlement, $maturity, $discount)
$maturity = Functions::flattenSingleValue($maturity);
$discount = Functions::flattenSingleValue($discount);

if (
is_string($maturity = DateTime::getDateValue($maturity)) ||
is_string($settlement = DateTime::getDateValue($settlement))
) {
return Functions::VALUE();
try {
$maturity = DateTimeExcel\Helpers::getDateValue($maturity);
$settlement = DateTimeExcel\Helpers::getDateValue($settlement);
} catch (Exception $e) {
return $e->getMessage();
}

// Validate
Expand All @@ -89,13 +88,12 @@ public static function price($settlement, $maturity, $discount)
}

$daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($maturity), Helpers::DAYS_PER_YEAR_ACTUAL);

if (
$daysBetweenSettlementAndMaturity > Helpers::daysPerYear(DateTime::YEAR($maturity), Helpers::DAYS_PER_YEAR_ACTUAL) ||
$daysBetweenSettlementAndMaturity < 0
) {
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
return Functions::NAN();
}

$price = 100 * (1 - (($discount * $daysBetweenSettlementAndMaturity) / 360));
if ($price < 0.0) {
return Functions::NAN();
Expand Down Expand Up @@ -127,11 +125,11 @@ public static function yield($settlement, $maturity, $price)
$maturity = Functions::flattenSingleValue($maturity);
$price = Functions::flattenSingleValue($price);

if (
is_string($maturity = DateTime::getDateValue($maturity)) ||
is_string($settlement = DateTime::getDateValue($settlement))
) {
return Functions::VALUE();
try {
$maturity = DateTimeExcel\Helpers::getDateValue($maturity);
$settlement = DateTimeExcel\Helpers::getDateValue($settlement);
} catch (Exception $e) {
return $e->getMessage();
}

// Validate
Expand All @@ -141,8 +139,9 @@ public static function yield($settlement, $maturity, $price)
}

$daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($maturity), Helpers::DAYS_PER_YEAR_ACTUAL);

if ($daysBetweenSettlementAndMaturity > 360 || $daysBetweenSettlementAndMaturity < 0) {
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
return Functions::NAN();
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/MathTrig/Fact.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function funcFact($factVal)
$factLoop = floor($factVal);
if ($factVal > $factLoop) {
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
return Statistical::GAMMAFunction($factVal + 1);
return Statistical\Distributions\Gamma::gammaValue($factVal + 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Statistical.php
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ public static function GEOMEAN(...$args)
{
$aArgs = Functions::flattenArray($args);

$aMean = MathTrig::PRODUCT($aArgs);
$aMean = MathTrig\Product::funcProduct($aArgs);
if (is_numeric($aMean) && ($aMean > 0)) {
$aCount = Counts::COUNT($aArgs);
if (Minimum::MIN($aArgs) > 0) {
Expand Down
Loading

0 comments on commit d36f9d5

Please sign in to comment.