Text function array value tests, plus some cleanup

This commit is contained in:
MarkBaker 2022-02-11 12:34:29 +01:00
parent 5ab3cbc8db
commit df12b06c59
20 changed files with 281 additions and 50 deletions

View File

@ -927,7 +927,12 @@ parameters:
- -
message: "#^Parameter \\#1 \\$year of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Helpers\\:\\:daysPerYear\\(\\) expects int\\|string, array\\|int\\|string given\\.$#" message: "#^Parameter \\#1 \\$year of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Helpers\\:\\:daysPerYear\\(\\) expects int\\|string, array\\|int\\|string given\\.$#"
count: 3 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Parameter \\#1 \\$year of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Helpers\\:\\:daysPerYear\\(\\) expects int\\|string, mixed given\\.$#"
count: 2
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
- -
@ -976,12 +981,12 @@ parameters:
path: src/PhpSpreadsheet/Calculation/Financial/Dollar.php path: src/PhpSpreadsheet/Calculation/Financial/Dollar.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:atMaturity\\(\\) should return float\\|string but returns array\\|string\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:atMaturity\\(\\) should return float\\|string but returns mixed\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:periodic\\(\\) should return float\\|string but returns array\\|string\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:periodic\\(\\) should return float\\|string but returns mixed\\.$#"
count: 2 count: 2
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
@ -991,12 +996,12 @@ parameters:
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:priceAtMaturity\\(\\) should return float\\|string but returns array\\|string\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:priceAtMaturity\\(\\) should return float\\|string but returns mixed\\.$#"
count: 3 count: 4
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:priceDiscounted\\(\\) should return float\\|string but returns array\\|string\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:priceDiscounted\\(\\) should return float\\|string but returns mixed\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
@ -1011,22 +1016,22 @@ parameters:
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Rates\\:\\:discount\\(\\) should return float\\|string but returns array\\|string\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Rates\\:\\:discount\\(\\) should return float\\|string but returns mixed\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Rates\\:\\:interest\\(\\) should return float\\|string but returns array\\|string\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Rates\\:\\:interest\\(\\) should return float\\|string but returns mixed\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:yieldAtMaturity\\(\\) should return float\\|string but returns array\\|string\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:yieldAtMaturity\\(\\) should return float\\|string but returns mixed\\.$#"
count: 3 count: 3
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:yieldDiscounted\\(\\) should return float\\|string but returns array\\|string\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:yieldDiscounted\\(\\) should return float\\|string but returns mixed\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
@ -1036,7 +1041,7 @@ parameters:
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
- -
message: "#^Parameter \\#1 \\$year of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Helpers\\:\\:daysPerYear\\(\\) expects int\\|string, array\\|int\\|string given\\.$#" message: "#^Parameter \\#1 \\$year of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Helpers\\:\\:daysPerYear\\(\\) expects int\\|string, mixed given\\.$#"
count: 3 count: 3
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php

View File

@ -587,10 +587,10 @@ class Financial
* @see Financial\Dollar::decimal() * @see Financial\Dollar::decimal()
* Use the decimal() method in the Financial\Dollar class instead * Use the decimal() method in the Financial\Dollar class instead
* *
* @param float $fractional_dollar Fractional Dollar * @param array|float $fractional_dollar Fractional Dollar
* @param int $fraction Fraction * @param array|int $fraction Fraction
* *
* @return float|string * @return array|float|string
*/ */
public static function DOLLARDE($fractional_dollar = null, $fraction = 0) public static function DOLLARDE($fractional_dollar = null, $fraction = 0)
{ {
@ -612,10 +612,10 @@ class Financial
* @see Financial\Dollar::fractional() * @see Financial\Dollar::fractional()
* Use the fractional() method in the Financial\Dollar class instead * Use the fractional() method in the Financial\Dollar class instead
* *
* @param float $decimal_dollar Decimal Dollar * @param array|float $decimal_dollar Decimal Dollar
* @param int $fraction Fraction * @param array|int $fraction Fraction
* *
* @return float|string * @return array|float|string
*/ */
public static function DOLLARFR($decimal_dollar = null, $fraction = 0) public static function DOLLARFR($decimal_dollar = null, $fraction = 0)
{ {

View File

@ -168,7 +168,7 @@ class Amortization
if ( if (
($basis == FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL) && ($basis == FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL) &&
($yearFrac < 1) && (DateTimeExcel\Helpers::isLeapYear($purchasedYear)) ($yearFrac < 1) && (Functions::scalar(DateTimeExcel\Helpers::isLeapYear($purchasedYear)))
) { ) {
$yearFrac *= 365 / 366; $yearFrac *= 365 / 366;
} }

View File

@ -64,7 +64,7 @@ class Coupons
return $e->getMessage(); return $e->getMessage();
} }
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis); $daysPerYear = Helpers::daysPerYear(Functions::scalar(DateTimeExcel\DateParts::year($settlement)), $basis);
if (is_string($daysPerYear)) { if (is_string($daysPerYear)) {
return Functions::VALUE(); return Functions::VALUE();
} }
@ -134,7 +134,7 @@ class Coupons
case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL: case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL:
// Actual/actual // Actual/actual
if ($frequency == FinancialConstants::FREQUENCY_ANNUAL) { if ($frequency == FinancialConstants::FREQUENCY_ANNUAL) {
$daysPerYear = (int) Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis); $daysPerYear = (int) Helpers::daysPerYear(Functions::scalar(DateTimeExcel\DateParts::year($settlement)), $basis);
return $daysPerYear / $frequency; return $daysPerYear / $frequency;
} }

View File

@ -2,21 +2,25 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial; namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData\Format; use PhpOffice\PhpSpreadsheet\Calculation\TextData\Format;
class Dollar class Dollar
{ {
use ArrayEnabled;
/** /**
* DOLLAR. * DOLLAR.
* *
* This function converts a number to text using currency format, with the decimals rounded to the specified place. * This function converts a number to text using currency format, with the decimals rounded to the specified place.
* The format used is $#,##0.00_);($#,##0.00).. * The format used is $#,##0.00_);($#,##0.00)..
* *
* @param mixed $number The value to format * @param mixed $number The value to format, or can be an array of numbers
* @param mixed $precision The number of digits to display to the right of the decimal point (as an integer). * @param mixed $precision The number of digits to display to the right of the decimal point (as an integer).
* If precision is negative, number is rounded to the left of the decimal point. * If precision is negative, number is rounded to the left of the decimal point.
* If you omit precision, it is assumed to be 2 * If you omit precision, it is assumed to be 2
* Or can be an array of precision values
*/ */
public static function format($number, $precision = 2): string public static function format($number, $precision = 2): string
{ {
@ -34,12 +38,18 @@ class Dollar
* DOLLARDE(fractional_dollar,fraction) * DOLLARDE(fractional_dollar,fraction)
* *
* @param mixed $fractionalDollar Fractional Dollar * @param mixed $fractionalDollar Fractional Dollar
* Or can be an array of values
* @param mixed $fraction Fraction * @param mixed $fraction Fraction
* Or can be an array of values
* *
* @return float|string * @return array|float|string
*/ */
public static function decimal($fractionalDollar = null, $fraction = 0) public static function decimal($fractionalDollar = null, $fraction = 0)
{ {
if (is_array($fractionalDollar) || is_array($fraction)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $fractionalDollar, $fraction);
}
$fractionalDollar = Functions::flattenSingleValue($fractionalDollar); $fractionalDollar = Functions::flattenSingleValue($fractionalDollar);
$fraction = (int) Functions::flattenSingleValue($fraction); $fraction = (int) Functions::flattenSingleValue($fraction);
@ -51,8 +61,8 @@ class Dollar
return Functions::DIV0(); return Functions::DIV0();
} }
$dollars = floor($fractionalDollar); $dollars = ($fractionalDollar < 0) ? ceil($fractionalDollar): floor($fractionalDollar);
$cents = fmod($fractionalDollar, 1); $cents = fmod($fractionalDollar, 1.0);
$cents /= $fraction; $cents /= $fraction;
$cents *= 10 ** ceil(log10($fraction)); $cents *= 10 ** ceil(log10($fraction));
@ -70,12 +80,18 @@ class Dollar
* DOLLARFR(decimal_dollar,fraction) * DOLLARFR(decimal_dollar,fraction)
* *
* @param mixed $decimalDollar Decimal Dollar * @param mixed $decimalDollar Decimal Dollar
* Or can be an array of values
* @param mixed $fraction Fraction * @param mixed $fraction Fraction
* Or can be an array of values
* *
* @return float|string * @return array|float|string
*/ */
public static function fractional($decimalDollar = null, $fraction = 0) public static function fractional($decimalDollar = null, $fraction = 0)
{ {
if (is_array($decimalDollar) || is_array($fraction)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $decimalDollar, $fraction);
}
$decimalDollar = Functions::flattenSingleValue($decimalDollar); $decimalDollar = Functions::flattenSingleValue($decimalDollar);
$fraction = (int) Functions::flattenSingleValue($fraction); $fraction = (int) Functions::flattenSingleValue($fraction);

View File

@ -78,12 +78,12 @@ class AccruedInterest
return $e->getMessage(); return $e->getMessage();
} }
$daysBetweenIssueAndSettlement = YearFrac::fraction($issue, $settlement, $basis); $daysBetweenIssueAndSettlement = Functions::scalar(YearFrac::fraction($issue, $settlement, $basis));
if (!is_numeric($daysBetweenIssueAndSettlement)) { if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error // return date error
return $daysBetweenIssueAndSettlement; return $daysBetweenIssueAndSettlement;
} }
$daysBetweenFirstInterestAndSettlement = YearFrac::fraction($firstInterest, $settlement, $basis); $daysBetweenFirstInterestAndSettlement = Functions::scalar(YearFrac::fraction($firstInterest, $settlement, $basis));
if (!is_numeric($daysBetweenFirstInterestAndSettlement)) { if (!is_numeric($daysBetweenFirstInterestAndSettlement)) {
// return date error // return date error
return $daysBetweenFirstInterestAndSettlement; return $daysBetweenFirstInterestAndSettlement;
@ -140,7 +140,7 @@ class AccruedInterest
return $e->getMessage(); return $e->getMessage();
} }
$daysBetweenIssueAndSettlement = YearFrac::fraction($issue, $settlement, $basis); $daysBetweenIssueAndSettlement = Functions::scalar(YearFrac::fraction($issue, $settlement, $basis));
if (!is_numeric($daysBetweenIssueAndSettlement)) { if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error // return date error
return $daysBetweenIssueAndSettlement; return $daysBetweenIssueAndSettlement;

View File

@ -134,7 +134,7 @@ class Price
return $e->getMessage(); return $e->getMessage();
} }
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;
@ -194,23 +194,23 @@ class Price
return $e->getMessage(); return $e->getMessage();
} }
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis); $daysPerYear = Functions::scalar(Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis));
if (!is_numeric($daysPerYear)) { if (!is_numeric($daysPerYear)) {
return $daysPerYear; return $daysPerYear;
} }
$daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::fraction($issue, $settlement, $basis); $daysBetweenIssueAndSettlement = Functions::scalar(DateTimeExcel\YearFrac::fraction($issue, $settlement, $basis));
if (!is_numeric($daysBetweenIssueAndSettlement)) { if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error // return date error
return $daysBetweenIssueAndSettlement; return $daysBetweenIssueAndSettlement;
} }
$daysBetweenIssueAndSettlement *= $daysPerYear; $daysBetweenIssueAndSettlement *= $daysPerYear;
$daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::fraction($issue, $maturity, $basis); $daysBetweenIssueAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($issue, $maturity, $basis));
if (!is_numeric($daysBetweenIssueAndMaturity)) { if (!is_numeric($daysBetweenIssueAndMaturity)) {
// return date error // return date error
return $daysBetweenIssueAndMaturity; return $daysBetweenIssueAndMaturity;
} }
$daysBetweenIssueAndMaturity *= $daysPerYear; $daysBetweenIssueAndMaturity *= $daysPerYear;
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;

View File

@ -63,7 +63,7 @@ class Rates
return Functions::NAN(); return Functions::NAN();
} }
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;
@ -126,7 +126,7 @@ class Rates
return Functions::NAN(); return Functions::NAN();
} }
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;

View File

@ -61,7 +61,7 @@ class Yields
if (!is_numeric($daysPerYear)) { if (!is_numeric($daysPerYear)) {
return $daysPerYear; return $daysPerYear;
} }
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;
@ -126,19 +126,19 @@ class Yields
if (!is_numeric($daysPerYear)) { if (!is_numeric($daysPerYear)) {
return $daysPerYear; return $daysPerYear;
} }
$daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::fraction($issue, $settlement, $basis); $daysBetweenIssueAndSettlement = Functions::scalar(DateTimeExcel\YearFrac::fraction($issue, $settlement, $basis));
if (!is_numeric($daysBetweenIssueAndSettlement)) { if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error // return date error
return $daysBetweenIssueAndSettlement; return $daysBetweenIssueAndSettlement;
} }
$daysBetweenIssueAndSettlement *= $daysPerYear; $daysBetweenIssueAndSettlement *= $daysPerYear;
$daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::fraction($issue, $maturity, $basis); $daysBetweenIssueAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($issue, $maturity, $basis));
if (!is_numeric($daysBetweenIssueAndMaturity)) { if (!is_numeric($daysBetweenIssueAndMaturity)) {
// return date error // return date error
return $daysBetweenIssueAndMaturity; return $daysBetweenIssueAndMaturity;
} }
$daysBetweenIssueAndMaturity *= $daysPerYear; $daysBetweenIssueAndMaturity *= $daysPerYear;
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;

View File

@ -43,7 +43,7 @@ class TreasuryBill
$daysBetweenSettlementAndMaturity = $maturity - $settlement; $daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear( $daysPerYear = Helpers::daysPerYear(
DateTimeExcel\DateParts::year($maturity), Functions::scalar(DateTimeExcel\DateParts::year($maturity)),
FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
); );
@ -88,7 +88,7 @@ class TreasuryBill
$daysBetweenSettlementAndMaturity = $maturity - $settlement; $daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear( $daysPerYear = Helpers::daysPerYear(
DateTimeExcel\DateParts::year($maturity), Functions::scalar(DateTimeExcel\DateParts::year($maturity)),
FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
); );
@ -134,7 +134,7 @@ class TreasuryBill
$daysBetweenSettlementAndMaturity = $maturity - $settlement; $daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear( $daysPerYear = Helpers::daysPerYear(
DateTimeExcel\DateParts::year($maturity), Functions::scalar(DateTimeExcel\DateParts::year($maturity)),
FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
); );

View File

@ -16,7 +16,7 @@ class Sqrt
* *
* @param mixed $number Should be numeric, or can be an array of numbers * @param mixed $number Should be numeric, or can be an array of numbers
* *
* @return array|float|string square roor * @return array|float|string square root
* If an array of numbers is passed as the argument, then the returned result will also be an array * If an array of numbers is passed as the argument, then the returned result will also be an array
* with the same dimensions * with the same dimensions
*/ */

View File

@ -2,20 +2,32 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; namespace PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
class CaseConvert class CaseConvert
{ {
use ArrayEnabled;
/** /**
* LOWERCASE. * LOWERCASE.
* *
* Converts a string value to upper case. * Converts a string value to upper case.
* *
* @param mixed $mixedCaseValue The string value to convert to lower case * @param mixed $mixedCaseValue The string value to convert to lower case
* Or can be an array of values
*
* @return array|string
* If an array of values is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function lower($mixedCaseValue): string public static function lower($mixedCaseValue)
{ {
if (is_array($mixedCaseValue)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue);
}
$mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue); $mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue);
$mixedCaseValue = Helpers::extractString($mixedCaseValue); $mixedCaseValue = Helpers::extractString($mixedCaseValue);
@ -28,9 +40,18 @@ class CaseConvert
* Converts a string value to upper case. * Converts a string value to upper case.
* *
* @param mixed $mixedCaseValue The string value to convert to upper case * @param mixed $mixedCaseValue The string value to convert to upper case
* Or can be an array of values
*
* @return array|string
* If an array of values is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function upper($mixedCaseValue): string public static function upper($mixedCaseValue)
{ {
if (is_array($mixedCaseValue)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue);
}
$mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue); $mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue);
$mixedCaseValue = Helpers::extractString($mixedCaseValue); $mixedCaseValue = Helpers::extractString($mixedCaseValue);
@ -43,9 +64,18 @@ class CaseConvert
* Converts a string value to proper or title case. * Converts a string value to proper or title case.
* *
* @param mixed $mixedCaseValue The string value to convert to title case * @param mixed $mixedCaseValue The string value to convert to title case
* Or can be an array of values
*
* @return array|string
* If an array of values is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function proper($mixedCaseValue): string public static function proper($mixedCaseValue)
{ {
if (is_array($mixedCaseValue)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue);
}
$mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue); $mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue);
$mixedCaseValue = Helpers::extractString($mixedCaseValue); $mixedCaseValue = Helpers::extractString($mixedCaseValue);

View File

@ -2,17 +2,29 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; namespace PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class CharacterConvert class CharacterConvert
{ {
use ArrayEnabled;
/** /**
* CHAR. * CHAR.
* *
* @param mixed $character Integer Value to convert to its character representation * @param mixed $character Integer Value to convert to its character representation
* Or can be an array of values
*
* @return array|string The character string
* If an array of values is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function character($character): string public static function character($character)
{ {
if (is_array($character)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $character);
}
$character = Helpers::validateInt($character); $character = Helpers::validateInt($character);
$min = Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE ? 0 : 1; $min = Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE ? 0 : 1;
if ($character < $min || $character > 255) { if ($character < $min || $character > 255) {
@ -27,11 +39,18 @@ class CharacterConvert
* CODE. * CODE.
* *
* @param mixed $characters String character to convert to its ASCII value * @param mixed $characters String character to convert to its ASCII value
* Or can be an array of values
* *
* @return int|string A string if arguments are invalid * @return array|int|string A string if arguments are invalid
* If an array of values is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function code($characters) public static function code($characters)
{ {
if (is_array($characters)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $characters);
}
$characters = Helpers::extractString($characters); $characters = Helpers::extractString($characters);
if ($characters === '') { if ($characters === '') {
return Functions::VALUE(); return Functions::VALUE();

View File

@ -146,14 +146,14 @@ class Format
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
if (strpos($value, ':') !== false) { if (strpos($value, ':') !== false) {
$timeValue = DateTimeExcel\TimeValue::fromString($value); $timeValue = Functions::scalar(DateTimeExcel\TimeValue::fromString($value));
if ($timeValue !== Functions::VALUE()) { if ($timeValue !== Functions::VALUE()) {
Functions::setReturnDateType($dateSetting); Functions::setReturnDateType($dateSetting);
return $timeValue; return $timeValue;
} }
} }
$dateValue = DateTimeExcel\DateValue::fromString($value); $dateValue = Functions::scalar(DateTimeExcel\DateValue::fromString($value));
if ($dateValue !== Functions::VALUE()) { if ($dateValue !== Functions::VALUE()) {
Functions::setReturnDateType($dateSetting); Functions::setReturnDateType($dateSetting);

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Financial; use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -28,4 +29,52 @@ class DollarDeTest extends TestCase
{ {
return require 'tests/data/Calculation/Financial/DOLLARDE.php'; return require 'tests/data/Calculation/Financial/DOLLARDE.php';
} }
/**
* @dataProvider providerDollarDeArray
*/
public function testDollarDeArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=DollarDe({$argument1},{$argument2})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}
public function providerDollarDeArray(): array
{
return [
'first argument row vector' => [
[[1.125, 2.0625, -12.625, 3.5]],
'{1.02, 2.01, -12.1, 1.4}',
'16',
],
'first argument column vector' => [
[[1.0625], [2.03125], [-12.3125], [2.25]],
'{1.02; 2.01; -12.1; 1.4}',
'32',
],
'first argument matrix' => [
[[1.05, 2.25], [-12.5, 2.0]],
'{1.02, 2.1; -12.2, 1.4}',
'4',
],
'second argument row vector' => [
[[4.25, 3.625, 6.125, 4.5625]],
'3.5',
'{4, 8, 16, 32}',
],
'second argument column vector' => [
[[5.5], [4.25], [3.625], [6.125]],
'3.5',
'{2; 4; 8; 16}',
],
'second argument matrix' => [
[[-4.875, -3.9375], [-9.25, -7.6875]],
'-3.75',
'{4, 8; 12, 16}',
],
];
}
} }

View File

@ -2,6 +2,8 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CharTest extends AllSetupTeardown class CharTest extends AllSetupTeardown
{ {
/** /**
@ -28,4 +30,25 @@ class CharTest extends AllSetupTeardown
{ {
return require 'tests/data/Calculation/TextData/CHAR.php'; return require 'tests/data/Calculation/TextData/CHAR.php';
} }
/**
* @dataProvider providerCharArray
*/
public function testCharArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=CHAR({$array})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerCharArray(): array
{
return [
'row vector' => [[['P', 'H', 'P']], '{80, 72, 80}'],
'column vector' => [[['P'], ['H'], ['P']], '{80; 72; 80}'],
'matrix' => [[['Y', 'o'], ['l', 'o']], '{89, 111; 108, 111}'],
];
}
} }

View File

@ -2,6 +2,8 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CodeTest extends AllSetupTeardown class CodeTest extends AllSetupTeardown
{ {
/** /**
@ -28,4 +30,25 @@ class CodeTest extends AllSetupTeardown
{ {
return require 'tests/data/Calculation/TextData/CODE.php'; return require 'tests/data/Calculation/TextData/CODE.php';
} }
/**
* @dataProvider providerCodeArray
*/
public function testCodeArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=CODE({$array})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerCodeArray(): array
{
return [
'row vector' => [[[80, 72, 80]], '{"P", "H", "P"}'],
'column vector' => [[[80], [72], [80]], '{"P"; "H"; "P"}'],
'matrix' => [[[89, 111], [108, 111]], '{"Y", "o"; "l", "o"}'],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Settings;
class LowerTest extends AllSetupTeardown class LowerTest extends AllSetupTeardown
@ -64,4 +65,25 @@ class LowerTest extends AllSetupTeardown
['ложь', 'bg', false], ['ложь', 'bg', false],
]; ];
} }
/**
* @dataProvider providerLowerArray
*/
public function testLowerArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=LOWER({$array})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerLowerArray(): array
{
return [
'row vector' => [[["let's", 'all change', 'case']], '{"lEt\'S", "aLl chAngE", "cAsE"}'],
'column vector' => [[["let's"], ['all change'], ['case']], '{"lEt\'S"; "aLl chAngE"; "cAsE"}'],
'matrix' => [[['build all', 'your workbooks'], ['with', 'phpspreadsheet']], '{"bUIld aLL", "yOUr WOrkBOOks"; "wiTH", "PhpSpreadsheet"}'],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Settings;
class ProperTest extends AllSetupTeardown class ProperTest extends AllSetupTeardown
@ -64,4 +65,25 @@ class ProperTest extends AllSetupTeardown
['Ложь', 'bg', false], ['Ложь', 'bg', false],
]; ];
} }
/**
* @dataProvider providerProperArray
*/
public function testProperArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=PROPER({$array})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerProperArray(): array
{
return [
'row vector' => [[["Let's", 'All Change', 'Case']], '{"lEt\'S", "aLl chAngE", "cAsE"}'],
'column vector' => [[["Let's"], ['All Change'], ['Case']], '{"lEt\'S"; "aLl chAngE"; "cAsE"}'],
'matrix' => [[['Build All', 'Your Workbooks'], ['With', 'Phpspreadsheet']], '{"bUIld aLL", "yOUr WOrkBOOks"; "wiTH", "PhpSpreadsheet"}'],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Settings;
class UpperTest extends AllSetupTeardown class UpperTest extends AllSetupTeardown
@ -64,4 +65,25 @@ class UpperTest extends AllSetupTeardown
['ЛОЖЬ', 'bg', false], ['ЛОЖЬ', 'bg', false],
]; ];
} }
/**
* @dataProvider providerUpperArray
*/
public function testUpperArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=UPPER({$array})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerUpperArray(): array
{
return [
'row vector' => [[["LET'S", 'ALL CHANGE', 'CASE']], '{"lEt\'S", "aLl chAngE", "cAsE"}'],
'column vector' => [[["LET'S"], ['ALL CHANGE'], ['CASE']], '{"lEt\'S"; "aLl chAngE"; "cAsE"}'],
'matrix' => [[['BUILD ALL', 'YOUR WORKBOOKS'], ['WITH', 'PHPSPREADSHEET']], '{"bUIld aLL", "yOUr WOrkBOOks"; "wiTH", "PhpSpreadsheet"}'],
];
}
} }