diff --git a/CHANGELOG.md b/CHANGELOG.md index ac7c5505..5c81a661 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - ### Deprecated -- Nothing +- All Excel Function implementations in `Calculation\Functions` (including the Error functions) have been moved to dedicated classes for groups of related functions. See the docblocks against all the deprecated methods for details of the new methods to call instead. At some point, these old classes will be deleted. ### Removed diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index acafd3b1..6540c849 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -595,11 +595,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Calculation/FormulaParser.php - - - message: "#^Cannot call method getCell\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Functions.php - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Functions\\:\\:ifCondition\\(\\) has no return type specified\\.$#" count: 1 diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index f28d258e..81a0353b 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engine\CyclicReferenceStack; use PhpOffice\PhpSpreadsheet\Calculation\Engine\Logger; +use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PhpOffice\PhpSpreadsheet\Calculation\Token\Stack; use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; @@ -973,7 +974,7 @@ class Calculation ], 'ERROR.TYPE' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'errorType'], + 'functionCall' => [Information\ExcelError::class, 'type'], 'argumentCount' => '1', ], 'EVEN' => [ @@ -1457,49 +1458,49 @@ class Calculation ], 'ISBLANK' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isBlank'], + 'functionCall' => [Information\Value::class, 'isBlank'], 'argumentCount' => '1', ], 'ISERR' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isErr'], + 'functionCall' => [Information\Value::class, 'isErr'], 'argumentCount' => '1', ], 'ISERROR' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isError'], + 'functionCall' => [Information\Value::class, 'isError'], 'argumentCount' => '1', ], 'ISEVEN' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isEven'], + 'functionCall' => [Information\Value::class, 'isEven'], 'argumentCount' => '1', ], 'ISFORMULA' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isFormula'], + 'functionCall' => [Information\Value::class, 'isFormula'], 'argumentCount' => '1', 'passCellReference' => true, 'passByReference' => [true], ], 'ISLOGICAL' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isLogical'], + 'functionCall' => [Information\Value::class, 'isLogical'], 'argumentCount' => '1', ], 'ISNA' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isNa'], + 'functionCall' => [Information\Value::class, 'isNa'], 'argumentCount' => '1', ], 'ISNONTEXT' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isNonText'], + 'functionCall' => [Information\Value::class, 'isNonText'], 'argumentCount' => '1', ], 'ISNUMBER' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isNumber'], + 'functionCall' => [Information\Value::class, 'isNumber'], 'argumentCount' => '1', ], 'ISO.CEILING' => [ @@ -1509,7 +1510,7 @@ class Calculation ], 'ISODD' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isOdd'], + 'functionCall' => [Information\Value::class, 'isOdd'], 'argumentCount' => '1', ], 'ISOWEEKNUM' => [ @@ -1529,7 +1530,7 @@ class Calculation ], 'ISTEXT' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'isText'], + 'functionCall' => [Information\Value::class, 'isText'], 'argumentCount' => '1', ], 'ISTHAIDIGIT' => [ @@ -1759,7 +1760,7 @@ class Calculation ], 'N' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'n'], + 'functionCall' => [Information\Value::class, 'asNumber'], 'argumentCount' => '1', ], 'NA' => [ @@ -2559,7 +2560,7 @@ class Calculation ], 'TYPE' => [ 'category' => Category::CATEGORY_INFORMATION, - 'functionCall' => [Functions::class, 'TYPE'], + 'functionCall' => [Information\Value::class, 'type'], 'argumentCount' => '1', ], 'UNICHAR' => [ @@ -3252,7 +3253,7 @@ class Calculation return self::FORMULA_STRING_QUOTE . $value . self::FORMULA_STRING_QUOTE; } elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) { // Convert numeric errors to NaN error - return Functions::NAN(); + return Information\ExcelError::NAN(); } return $value; @@ -3273,7 +3274,7 @@ class Calculation } // Convert numeric errors to NAN error } elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) { - return Functions::NAN(); + return Information\ExcelError::NAN(); } return $value; @@ -3342,7 +3343,7 @@ class Calculation self::$returnArrayAsType = $returnArrayAsType; $testResult = Functions::flattenArray($result); if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) { - return Functions::VALUE(); + return Information\ExcelError::VALUE(); } // If there's only a single cell in the array, then we allow it if (count($testResult) != 1) { @@ -3350,13 +3351,13 @@ class Calculation $r = array_keys($result); $r = array_shift($r); if (!is_numeric($r)) { - return Functions::VALUE(); + return Information\ExcelError::VALUE(); } if (is_array($result[$r])) { $c = array_keys($result[$r]); $c = array_shift($c); if (!is_numeric($c)) { - return Functions::VALUE(); + return Information\ExcelError::VALUE(); } } } @@ -3367,7 +3368,7 @@ class Calculation if ($result === null && $cell->getWorksheet()->getSheetView()->getShowZeros()) { return 0; } elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) { - return Functions::NAN(); + return Information\ExcelError::NAN(); } return $result; @@ -4428,7 +4429,7 @@ class Calculation isset($storeValue) && ( !$storeValueAsBool - || Functions::isError($storeValue) + || Value::isError($storeValue) || ($storeValue === 'Pruned branch') ) ) { @@ -4463,7 +4464,7 @@ class Calculation isset($storeValue) && ( $storeValueAsBool - || Functions::isError($storeValue) + || Value::isError($storeValue) || ($storeValue === 'Pruned branch') ) ) { @@ -4569,7 +4570,7 @@ class Calculation $stack->push('Cell Reference', $cellValue, $cellRef); } else { - $stack->push('Error', Functions::REF(), null); + $stack->push('Error', Information\ExcelError::REF(), null); } break; @@ -4704,7 +4705,7 @@ class Calculation if (isset($matches[8])) { if ($cell === null) { // We can't access the range, so return a REF error - $cellValue = Functions::REF(); + $cellValue = Information\ExcelError::REF(); } else { $cellRef = $matches[6] . $matches[7] . ':' . $matches[9] . $matches[10]; if ($matches[2] > '') { @@ -4734,7 +4735,7 @@ class Calculation } else { if ($cell === null) { // We can't access the cell, so return a REF error - $cellValue = Functions::REF(); + $cellValue = Information\ExcelError::REF(); } else { $cellRef = $matches[6] . $matches[7]; if ($matches[2] > '') { @@ -5069,7 +5070,7 @@ class Calculation ((is_string($operand1) && !is_numeric($operand1) && strlen($operand1) > 0) || (is_string($operand2) && !is_numeric($operand2) && strlen($operand2) > 0)) ) { - $result = Functions::VALUE(); + $result = Information\ExcelError::VALUE(); } else { // If we're dealing with non-matrix operations, execute the necessary operation switch ($operation) { @@ -5217,7 +5218,7 @@ class Calculation // Named range? $namedRange = DefinedName::resolveName($range, $worksheet); if ($namedRange === null) { - return Functions::REF(); + return Information\ExcelError::REF(); } $worksheet = $namedRange->getWorksheet(); @@ -5406,7 +5407,7 @@ class Calculation $definedNameScope = $namedRange->getScope(); if ($definedNameScope !== null && $definedNameScope !== $cellWorksheet) { // The defined name isn't in our current scope, so #REF - $result = Functions::REF(); + $result = Information\ExcelError::REF(); $stack->push('Error', $result, $namedRange->getName()); return $result; diff --git a/src/PhpSpreadsheet/Calculation/Database/DGet.php b/src/PhpSpreadsheet/Calculation/Database/DGet.php index c2ffe302..abe06e65 100644 --- a/src/PhpSpreadsheet/Calculation/Database/DGet.php +++ b/src/PhpSpreadsheet/Calculation/Database/DGet.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Database; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class DGet extends DatabaseAbstract { @@ -41,7 +41,7 @@ class DGet extends DatabaseAbstract $columnData = self::getFilteredColumn($database, $field, $criteria); if (count($columnData) > 1) { - return Functions::NAN(); + return ExcelError::NAN(); } $row = array_pop($columnData); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php index d23ce37b..5de671d3 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use DateTimeImmutable; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Current { @@ -29,7 +29,7 @@ class Current $dti = new DateTimeImmutable(); $dateArray = Helpers::dateParse($dti->format('c')); - return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray, true) : Functions::VALUE(); + return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray, true) : ExcelError::VALUE(); } /** @@ -54,6 +54,6 @@ class Current $dti = new DateTimeImmutable(); $dateArray = Helpers::dateParse($dti->format('c')); - return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray) : Functions::VALUE(); + return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray) : ExcelError::VALUE(); } } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php index b1c1ece8..56982c5c 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; @@ -95,15 +95,15 @@ class Date { $year = ($year !== null) ? StringHelper::testStringAsNumeric((string) $year) : 0; if (!is_numeric($year)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } $year = (int) $year; if ($year < ($baseYear - 1900)) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } if ((($baseYear - 1900) !== 0) && ($year < $baseYear) && ($year >= 1900)) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } if (($year < $baseYear) && ($year >= ($baseYear - 1900))) { @@ -126,7 +126,7 @@ class Date $month = ($month !== null) ? StringHelper::testStringAsNumeric((string) $month) : 0; if (!is_numeric($month)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (int) $month; @@ -145,7 +145,7 @@ class Date $day = ($day !== null) ? StringHelper::testStringAsNumeric((string) $day) : 0; if (!is_numeric($day)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (int) $day; @@ -166,7 +166,7 @@ class Date // Re-validate the year parameter after adjustments if (($year < $baseYear) || ($year >= 10000)) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } } } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php index 47a68cf9..466fe4a6 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use DateTimeImmutable; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class DateValue @@ -59,7 +59,7 @@ class DateValue foreach ($t1 as &$t) { if ((is_numeric($t)) && ($t > 31)) { if ($yearFound) { - return Functions::VALUE(); + return ExcelError::VALUE(); } if ($t < 100) { $t += 1900; @@ -69,7 +69,7 @@ class DateValue } if (count($t1) === 1) { // We've been fed a time value without any date - return ((strpos((string) $t, ':') === false)) ? Functions::Value() : 0.0; + return ((strpos((string) $t, ':') === false)) ? ExcelError::Value() : 0.0; } unset($t); @@ -131,12 +131,12 @@ class DateValue */ private static function finalResults(array $PHPDateArray, DateTimeImmutable $dti, int $baseYear) { - $retValue = Functions::Value(); + $retValue = ExcelError::Value(); if (Helpers::dateParseSucceeded($PHPDateArray)) { // Execute function Helpers::replaceIfEmpty($PHPDateArray['year'], $dti->format('Y')); if ($PHPDateArray['year'] < $baseYear) { - return Functions::VALUE(); + return ExcelError::VALUE(); } Helpers::replaceIfEmpty($PHPDateArray['month'], $dti->format('m')); Helpers::replaceIfEmpty($PHPDateArray['day'], $dti->format('d')); @@ -147,7 +147,7 @@ class DateValue $day = (int) $PHPDateArray['day']; $year = (int) $PHPDateArray['year']; if (!checkdate($month, $day, $year)) { - return ($year === 1900 && $month === 2 && $day === 29) ? Helpers::returnIn3FormatsFloat(60.0) : Functions::VALUE(); + return ($year === 1900 && $month === 2 && $day === 29) ? Helpers::returnIn3FormatsFloat(60.0) : ExcelError::VALUE(); } $retValue = Helpers::returnIn3FormatsArray($PHPDateArray, true); } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php index 5392b2c3..a3b97451 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php @@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use DateTimeInterface; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Days @@ -48,7 +48,7 @@ class Days $PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate); $PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate); - $days = Functions::VALUE(); + $days = ExcelError::VALUE(); $diff = $PHPStartDateObject->diff($PHPEndDateObject); if ($diff !== false && !is_bool($diff->days)) { $days = $diff->days; diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php index 2220aaee..6f71621e 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Days360 @@ -58,7 +58,7 @@ class Days360 } if (!is_bool($method)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } // Execute function diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php index 4dd78263..ecb1cf0a 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php @@ -6,7 +6,7 @@ use DateInterval; use DateTime; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Difference @@ -65,14 +65,14 @@ class Difference $retVal = self::replaceRetValue($retVal, $unit, 'YD') ?? self::datedifYD($difference, $startYears, $endYears, $PHPStartDateObject, $PHPEndDateObject); $retVal = self::replaceRetValue($retVal, $unit, 'YM') ?? self::datedifYM($PHPDiffDateObject); - return is_bool($retVal) ? Functions::VALUE() : $retVal; + return is_bool($retVal) ? ExcelError::VALUE() : $retVal; } private static function initialDiff(float $startDate, float $endDate): float { // Validate parameters if ($startDate > $endDate) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $endDate - $startDate; diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php index 55ce13f1..23845153 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use DateTime; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Helpers @@ -33,7 +34,7 @@ class Helpers if (is_object($dateValue)) { $retval = SharedDateHelper::PHPToExcel($dateValue); if (is_bool($retval)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return $retval; @@ -46,11 +47,11 @@ class Helpers $dateValue = DateValue::fromString($dateValue); Functions::setReturnDateType($saveReturnDateType); if (!is_numeric($dateValue)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } } if ($dateValue < 0 && Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return (float) $dateValue; @@ -253,7 +254,7 @@ class Helpers return (float) $number; } - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } /** @@ -266,13 +267,13 @@ class Helpers public static function validateNotNegative($number) { if (!is_numeric($number)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } if ($number >= 0) { return (float) $number; } - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } public static function silly1900(DateTime $PHPDateObject, string $mod = '-1 day'): void diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php index f5e685f4..4ff71983 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php @@ -6,6 +6,7 @@ use DateTime; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Time @@ -62,7 +63,7 @@ class Time if ($hour > 23) { $hour = $hour % 24; } elseif ($hour < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } // Execute function @@ -121,7 +122,7 @@ class Time $value = (int) $value; } if (!is_numeric($value)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (int) $value; diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php index f57c9f00..aa27206b 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use Datetime; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class TimeValue @@ -51,7 +52,7 @@ class TimeValue } $PHPDateArray = Helpers::dateParse($timeValue); - $retValue = Functions::VALUE(); + $retValue = ExcelError::VALUE(); if (Helpers::dateParseSucceeded($PHPDateArray)) { /** @var int */ $hour = $PHPDateArray['hour']; diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php index c6ca0f81..2f69007d 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php @@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use DateTime; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Week @@ -192,11 +192,11 @@ class Week private static function validateStyle($style): int { if (!is_numeric($style)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } $style = (int) $style; if (($style < 1) || ($style > 3)) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $style; @@ -233,7 +233,7 @@ class Week private static function validateDateValue($dateValue): float { if (is_bool($dateValue)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return Helpers::getDateValue($dateValue); @@ -251,12 +251,12 @@ class Week } if (!is_numeric($method)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } $method = (int) $method; if (!array_key_exists($method, Constants::METHODARR)) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } $method = Constants::METHODARR[$method]; diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php index 8dad16d8..394c6b73 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class YearFrac @@ -73,7 +74,7 @@ class YearFrac return Functions::scalar(Days360::between($startDate, $endDate, true)) / 360; } - return Functions::NAN(); + return ExcelError::NAN(); } /** diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php index 24145aa9..2afb52bd 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class BesselI { @@ -49,12 +49,12 @@ class BesselI } if ($ord < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $fResult = self::calculate($x, $ord); - return (is_nan($fResult)) ? Functions::NAN() : $fResult; + return (is_nan($fResult)) ? ExcelError::NAN() : $fResult; } private static function calculate(float $x, int $ord): float diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php index 4b6a79e9..e23b0157 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class BesselJ { @@ -48,12 +48,12 @@ class BesselJ } if ($ord < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $fResult = self::calculate($x, $ord); - return (is_nan($fResult)) ? Functions::NAN() : $fResult; + return (is_nan($fResult)) ? ExcelError::NAN() : $fResult; } private static function calculate(float $x, int $ord): float diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php index 977eadf8..76b406e4 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class BesselK { @@ -46,12 +47,12 @@ class BesselK } if (($ord < 0) || ($x <= 0.0)) { - return Functions::NAN(); + return ExcelError::NAN(); } $fBk = self::calculate($x, $ord); - return (is_nan($fBk)) ? Functions::NAN() : $fBk; + return (is_nan($fBk)) ? ExcelError::NAN() : $fBk; } private static function calculate(float $x, int $ord): float diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php index 2b373bd2..794e946d 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class BesselY { @@ -45,12 +45,12 @@ class BesselY } if (($ord < 0) || ($x <= 0.0)) { - return Functions::NAN(); + return ExcelError::NAN(); } $fBy = self::calculate($x, $ord); - return (is_nan($fBy)) ? Functions::NAN() : $fBy; + return (is_nan($fBy)) ? ExcelError::NAN() : $fBy; } private static function calculate(float $x, int $ord): float diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BitWise.php b/src/PhpSpreadsheet/Calculation/Engineering/BitWise.php index 3041a41c..25a20870 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BitWise.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BitWise.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class BitWise { @@ -161,7 +162,7 @@ class BitWise $result = floor($number * (2 ** $shiftAmount)); if ($result > 2 ** 48 - 1) { - return Functions::NAN(); + return ExcelError::NAN(); } return $result; @@ -199,7 +200,7 @@ class BitWise $result = floor($number / (2 ** $shiftAmount)); if ($result > 2 ** 48 - 1) { // possible because shiftAmount can be negative - return Functions::NAN(); + return ExcelError::NAN(); } return $result; @@ -219,16 +220,16 @@ class BitWise if (is_numeric($value)) { if ($value == floor($value)) { if (($value > 2 ** 48 - 1) || ($value < 0)) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return floor($value); } - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } /** @@ -244,13 +245,13 @@ class BitWise if (is_numeric($value)) { if (abs($value) > 53) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return (int) $value; } - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } /** diff --git a/src/PhpSpreadsheet/Calculation/Engineering/Complex.php b/src/PhpSpreadsheet/Calculation/Engineering/Complex.php index 37bc0876..691de8b7 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/Complex.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/Complex.php @@ -6,7 +6,7 @@ use Complex\Complex as ComplexObject; use Complex\Exception as ComplexException; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Complex { @@ -55,7 +55,7 @@ class Complex return (string) $complex; } - return Functions::VALUE(); + return ExcelError::VALUE(); } /** @@ -83,7 +83,7 @@ class Complex try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return $complex->getImaginary(); @@ -113,7 +113,7 @@ class Complex try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return $complex->getReal(); diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ComplexFunctions.php b/src/PhpSpreadsheet/Calculation/Engineering/ComplexFunctions.php index f05d4bd8..28a27a03 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ComplexFunctions.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ComplexFunctions.php @@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use Complex\Complex as ComplexObject; use Complex\Exception as ComplexException; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class ComplexFunctions { @@ -35,7 +35,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return $complex->abs(); @@ -66,11 +66,11 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) { - return Functions::DIV0(); + return ExcelError::DIV0(); } return $complex->argument(); @@ -100,7 +100,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->conjugate(); @@ -130,7 +130,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->cos(); @@ -160,7 +160,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->cosh(); @@ -190,7 +190,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->cot(); @@ -220,7 +220,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->csc(); @@ -250,7 +250,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->csch(); @@ -280,7 +280,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->sin(); @@ -310,7 +310,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->sinh(); @@ -340,7 +340,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->sec(); @@ -370,7 +370,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->sech(); @@ -400,7 +400,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->tan(); @@ -430,11 +430,11 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } $theta = self::IMARGUMENT($complexNumber); - if ($theta === Functions::DIV0()) { + if ($theta === ExcelError::DIV0()) { return '0'; } @@ -465,11 +465,11 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->ln(); @@ -499,11 +499,11 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->log10(); @@ -533,11 +533,11 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->log2(); @@ -567,7 +567,7 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $complex->exp(); @@ -599,11 +599,11 @@ class ComplexFunctions try { $complex = new ComplexObject($complexNumber); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } if (!is_numeric($realNumber)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } return (string) $complex->pow((float) $realNumber); diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ComplexOperations.php b/src/PhpSpreadsheet/Calculation/Engineering/ComplexOperations.php index a921be61..e525b4b9 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ComplexOperations.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ComplexOperations.php @@ -6,6 +6,7 @@ use Complex\Complex as ComplexObject; use Complex\Exception as ComplexException; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class ComplexOperations { @@ -37,7 +38,7 @@ class ComplexOperations try { return (string) (new ComplexObject($complexDividend))->divideby(new ComplexObject($complexDivisor)); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } } @@ -67,7 +68,7 @@ class ComplexOperations try { return (string) (new ComplexObject($complexNumber1))->subtract(new ComplexObject($complexNumber2)); } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } } @@ -95,7 +96,7 @@ class ComplexOperations $returnValue = $returnValue->add(new ComplexObject($complex)); } } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $returnValue; @@ -125,7 +126,7 @@ class ComplexOperations $returnValue = $returnValue->multiply(new ComplexObject($complex)); } } catch (ComplexException $e) { - return Functions::NAN(); + return ExcelError::NAN(); } return (string) $returnValue; diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php index 4a741975..e80490bd 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; abstract class ConvertBase { @@ -14,7 +15,7 @@ abstract class ConvertBase { if (is_bool($value)) { if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } $value = (int) $value; } @@ -36,13 +37,13 @@ abstract class ConvertBase if (is_numeric($places)) { if ($places < 0 || $places > 10) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return (int) $places; } - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } /** @@ -60,7 +61,7 @@ abstract class ConvertBase return substr(str_pad($value, $places, '0', STR_PAD_LEFT), -10); } - return Functions::NAN(); + return ExcelError::NAN(); } return substr($value, -10); diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertBinary.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertBinary.php index 5f1be454..4741f301 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertBinary.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertBinary.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class ConvertBinary extends ConvertBase { @@ -155,7 +155,7 @@ class ConvertBinary extends ConvertBase protected static function validateBinary(string $value): string { if ((strlen($value) > preg_match_all('/[01]/', $value)) || (strlen($value) > 10)) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $value; diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertDecimal.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertDecimal.php index 6a876786..9b59d399 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertDecimal.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertDecimal.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class ConvertDecimal extends ConvertBase { @@ -61,7 +61,7 @@ class ConvertDecimal extends ConvertBase $value = (int) floor((float) $value); if ($value > self::LARGEST_BINARY_IN_DECIMAL || $value < self::SMALLEST_BINARY_IN_DECIMAL) { - return Functions::NAN(); + return ExcelError::NAN(); } $r = decbin($value); @@ -118,7 +118,7 @@ class ConvertDecimal extends ConvertBase $value = floor((float) $value); if ($value > self::LARGEST_HEX_IN_DECIMAL || $value < self::SMALLEST_HEX_IN_DECIMAL) { - return Functions::NAN(); + return ExcelError::NAN(); } $r = strtoupper(dechex((int) $value)); $r = self::hex32bit($value, $r); @@ -194,7 +194,7 @@ class ConvertDecimal extends ConvertBase $value = (int) floor((float) $value); if ($value > self::LARGEST_OCTAL_IN_DECIMAL || $value < self::SMALLEST_OCTAL_IN_DECIMAL) { - return Functions::NAN(); + return ExcelError::NAN(); } $r = decoct($value); $r = substr($r, -10); @@ -205,7 +205,7 @@ class ConvertDecimal extends ConvertBase protected static function validateDecimal(string $value): string { if (strlen($value) > preg_match_all('/[-0123456789.]/', $value)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return $value; diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php index 12c99521..55ce209e 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class ConvertHex extends ConvertBase { @@ -92,7 +92,7 @@ class ConvertHex extends ConvertBase } if (strlen($value) > 10) { - return Functions::NAN(); + return ExcelError::NAN(); } $binX = ''; @@ -167,7 +167,7 @@ class ConvertHex extends ConvertBase protected static function validateHex(string $value): string { if (strlen($value) > preg_match_all('/[0123456789ABCDEF]/', $value)) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $value; diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php index 3c3af5c1..add7aba0 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class ConvertOctal extends ConvertBase { @@ -166,7 +166,7 @@ class ConvertOctal extends ConvertBase { $numDigits = (int) preg_match_all('/[01234567]/', $value); if (strlen($value) > $numDigits || $numDigits > 10) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $value; diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertUOM.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertUOM.php index 089ccbd7..677fb0fb 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertUOM.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertUOM.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class ConvertUOM { @@ -539,18 +539,18 @@ class ConvertUOM } if (!is_numeric($value)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } try { [$fromUOM, $fromCategory, $fromMultiplier] = self::getUOMDetails($fromUOM); [$toUOM, $toCategory, $toMultiplier] = self::getUOMDetails($toUOM); } catch (Exception $e) { - return Functions::NA(); + return ExcelError::NA(); } if ($fromCategory !== $toCategory) { - return Functions::NA(); + return ExcelError::NA(); } // @var float $value diff --git a/src/PhpSpreadsheet/Calculation/Engineering/EngineeringValidations.php b/src/PhpSpreadsheet/Calculation/Engineering/EngineeringValidations.php index 01630af3..c0202ea2 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/EngineeringValidations.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/EngineeringValidations.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class EngineeringValidations { @@ -13,7 +13,7 @@ class EngineeringValidations public static function validateFloat($value): float { if (!is_numeric($value)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (float) $value; @@ -25,7 +25,7 @@ class EngineeringValidations public static function validateInt($value): int { if (!is_numeric($value)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (int) floor((float) $value); diff --git a/src/PhpSpreadsheet/Calculation/Engineering/Erf.php b/src/PhpSpreadsheet/Calculation/Engineering/Erf.php index 5aca8f2b..6254d477 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/Erf.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/Erf.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Erf { @@ -49,7 +50,7 @@ class Erf } } - return Functions::VALUE(); + return ExcelError::VALUE(); } /** diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ErfC.php b/src/PhpSpreadsheet/Calculation/Engineering/ErfC.php index da1a932e..7b023bee 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ErfC.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ErfC.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class ErfC { @@ -39,7 +40,7 @@ class ErfC return self::erfcValue($value); } - return Functions::VALUE(); + return ExcelError::VALUE(); } // diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/CashFlowValidations.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/CashFlowValidations.php index e4c8a3a4..8ebe9ed7 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/CashFlowValidations.php +++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/CashFlowValidations.php @@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; use PhpOffice\PhpSpreadsheet\Calculation\Financial\FinancialValidations; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class CashFlowValidations extends FinancialValidations { @@ -29,7 +29,7 @@ class CashFlowValidations extends FinancialValidations $type !== FinancialConstants::PAYMENT_END_OF_PERIOD && $type !== FinancialConstants::PAYMENT_BEGINNING_OF_PERIOD ) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $rate; diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php index e8a159ce..a19c37f6 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php +++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php @@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Periodic { @@ -94,7 +95,7 @@ class Periodic // Validate parameters if ($numberOfPeriods < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } return self::calculatePresentValue($rate, $numberOfPeriods, $payment, $futureValue, $type); @@ -138,7 +139,7 @@ class Periodic // Validate parameters if ($payment == 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } return self::calculatePeriods($rate, $payment, $presentValue, $futureValue, $type); @@ -187,7 +188,7 @@ class Periodic ) { if ($rate != 0.0) { if ($presentValue == 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } return log(($payment * (1 + $rate * $type) / $rate - $futureValue) / diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php index b7f6011c..b7aaffd8 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php +++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php @@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Cumulative { @@ -57,7 +58,7 @@ class Cumulative // Validate parameters if ($start < 1 || $start > $end) { - return Functions::NAN(); + return ExcelError::NAN(); } // Calculate @@ -122,7 +123,7 @@ class Cumulative // Validate parameters if ($start < 1 || $start > $end) { - return Functions::VALUE(); + return ExcelError::VALUE(); } // Calculate diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php index 56d2e379..80412082 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php +++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php @@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Interest { @@ -59,7 +60,7 @@ class Interest // Validate parameters if ($period <= 0 || $period > $numberOfPeriods) { - return Functions::NAN(); + return ExcelError::NAN(); } // Calculate @@ -106,7 +107,7 @@ class Interest // Validate parameters if ($period <= 0 || $period > $numberOfPeriods) { - return Functions::NAN(); + return ExcelError::NAN(); } // Return value @@ -193,13 +194,13 @@ class Interest $rate = $rate1; } - return $close ? $rate : Functions::NAN(); + return $close ? $rate : ExcelError::NAN(); } private static function rateNextGuess($rate, $numberOfPeriods, $payment, $presentValue, $futureValue, $type) { if ($rate == 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } $tt1 = ($rate + 1) ** $numberOfPeriods; $tt2 = ($rate + 1) ** ($numberOfPeriods - 1); @@ -208,7 +209,7 @@ class Interest * ($rate * $type + 1) / ($rate * $rate) + $numberOfPeriods * $payment * $tt2 * ($rate * $type + 1) / $rate + $payment * ($tt1 - 1) * $type / $rate; if ($denominator == 0) { - return Functions::NAN(); + return ExcelError::NAN(); } return $numerator / $denominator; diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php index e103f923..83965f9d 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php +++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php @@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Payments { @@ -97,7 +98,7 @@ class Payments // Validate parameters if ($period <= 0 || $period > $numberOfPeriods) { - return Functions::NAN(); + return ExcelError::NAN(); } // Calculate diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php index a30634da..058e89c6 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php +++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Single { @@ -67,7 +68,7 @@ class Single // Validate parameters if ($rate <= 0.0 || $presentValue <= 0.0 || $futureValue <= 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } return (log($futureValue) - log($presentValue)) / log(1 + $rate); @@ -100,7 +101,7 @@ class Single // Validate parameters if ($periods <= 0.0 || $presentValue <= 0.0 || $futureValue < 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } return ($futureValue / $presentValue) ** (1 / $periods) - 1; diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php index d590e1a4..b8126135 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php +++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Variable; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class NonPeriodic { @@ -41,7 +42,7 @@ class NonPeriodic // create an initial range, with a root somewhere between 0 and guess $guess = Functions::flattenSingleValue($guess) ?? self::DEFAULT_GUESS; if (!is_numeric($guess)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $guess = ($guess + 0.0) ?: self::DEFAULT_GUESS; $x1 = 0.0; @@ -68,7 +69,7 @@ class NonPeriodic } } if (!$found) { - return Functions::NAN(); + return ExcelError::NAN(); } return self::xirrPart3($values, $dates, $x1, $x2); @@ -117,10 +118,10 @@ class NonPeriodic $valuesIsArray = count($values) > 1; $datesIsArray = count($dates) > 1; if (!$valuesIsArray && !$datesIsArray) { - return Functions::NA(); + return ExcelError::NA(); } if (count($values) != count($dates)) { - return Functions::NAN(); + return ExcelError::NAN(); } $datesCount = count($dates); @@ -143,7 +144,7 @@ class NonPeriodic for ($i = 0; $i < $valCount; ++$i) { $fld = $values[$i]; if (!is_numeric($fld)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } elseif ($fld > 0) { $foundpos = true; } elseif ($fld < 0) { @@ -151,7 +152,7 @@ class NonPeriodic } } if (!self::bothNegAndPos($foundneg, $foundpos)) { - return Functions::NAN(); + return ExcelError::NAN(); } return ''; @@ -171,7 +172,7 @@ class NonPeriodic $dx = $x1 - $x2; } - $rslt = Functions::VALUE(); + $rslt = ExcelError::VALUE(); for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) { $dx *= 0.5; $x_mid = $rtb + $dx; @@ -213,7 +214,7 @@ class NonPeriodic $xnpv = 0.0; for ($i = 0; $i < $valCount; ++$i) { if (!is_numeric($values[$i])) { - return Functions::VALUE(); + return ExcelError::VALUE(); } try { @@ -222,7 +223,7 @@ class NonPeriodic return $e->getMessage(); } if ($date0 > $datei) { - $dif = $ordered ? Functions::NAN() : -((int) DateTimeExcel\Difference::interval($datei, $date0, 'd')); + $dif = $ordered ? ExcelError::NAN() : -((int) DateTimeExcel\Difference::interval($datei, $date0, 'd')); } else { $dif = DateTimeExcel\Difference::interval($date0, $datei, 'd'); } @@ -236,7 +237,7 @@ class NonPeriodic } } - return is_finite($xnpv) ? $xnpv : Functions::VALUE(); + return is_finite($xnpv) ? $xnpv : ExcelError::VALUE(); } /** @@ -245,14 +246,14 @@ class NonPeriodic private static function validateXnpv($rate, array $values, array $dates): void { if (!is_numeric($rate)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } $valCount = count($values); if ($valCount != count($dates)) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } if ($valCount > 1 && ((min($values) > 0) || (max($values) < 0))) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } } } diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php index c42df0c3..49d063c9 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php +++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Variable; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Periodic { @@ -33,7 +34,7 @@ class Periodic public static function rate($values, $guess = 0.1) { if (!is_array($values)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $values = Functions::flattenArray($values); $guess = Functions::flattenSingleValue($guess); @@ -54,7 +55,7 @@ class Periodic } } if (($f1 * $f2) > 0.0) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $f = self::presentValue($x1, $values); @@ -78,7 +79,7 @@ class Periodic } } - return Functions::VALUE(); + return ExcelError::VALUE(); } /** @@ -101,7 +102,7 @@ class Periodic public static function modifiedRate($values, $financeRate, $reinvestmentRate) { if (!is_array($values)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $values = Functions::flattenArray($values); $financeRate = Functions::flattenSingleValue($financeRate); @@ -121,13 +122,13 @@ class Periodic } if (($npvNeg === 0.0) || ($npvPos === 0.0) || ($reinvestmentRate <= -1.0)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $mirr = ((-$npvPos * $rr ** $n) / ($npvNeg * ($rr))) ** (1.0 / ($n - 1)) - 1.0; - return is_finite($mirr) ? $mirr : Functions::VALUE(); + return is_finite($mirr) ? $mirr : ExcelError::VALUE(); } /** diff --git a/src/PhpSpreadsheet/Calculation/Financial/Coupons.php b/src/PhpSpreadsheet/Calculation/Financial/Coupons.php index ad487def..237d6ee8 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Coupons.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Coupons.php @@ -7,6 +7,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Date; class Coupons @@ -66,7 +67,7 @@ class Coupons $daysPerYear = Helpers::daysPerYear(Functions::scalar(DateTimeExcel\DateParts::year($settlement)), $basis); if (is_string($daysPerYear)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS); @@ -409,7 +410,7 @@ class Coupons private static function validateCouponPeriod(float $settlement, float $maturity): void { if ($settlement >= $maturity) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } } } diff --git a/src/PhpSpreadsheet/Calculation/Financial/Depreciation.php b/src/PhpSpreadsheet/Calculation/Financial/Depreciation.php index 650a4861..3d72757a 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Depreciation.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Depreciation.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Depreciation { @@ -117,7 +118,7 @@ class Depreciation } if ($period > $life) { - return Functions::NAN(); + return ExcelError::NAN(); } // Loop through each period calculating the depreciation @@ -161,7 +162,7 @@ class Depreciation } if ($life === 0.0) { - return Functions::DIV0(); + return ExcelError::DIV0(); } return ($cost - $salvage) / $life; @@ -196,7 +197,7 @@ class Depreciation } if ($period > $life) { - return Functions::NAN(); + return ExcelError::NAN(); } $syd = (($cost - $salvage) * ($life - $period + 1) * 2) / ($life * ($life + 1)); @@ -208,7 +209,7 @@ class Depreciation { $cost = FinancialValidations::validateFloat($cost); if ($cost < 0.0 && $negativeValueAllowed === false) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $cost; @@ -218,7 +219,7 @@ class Depreciation { $salvage = FinancialValidations::validateFloat($salvage); if ($salvage < 0.0 && $negativeValueAllowed === false) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $salvage; @@ -228,7 +229,7 @@ class Depreciation { $life = FinancialValidations::validateFloat($life); if ($life < 0.0 && $negativeValueAllowed === false) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $life; @@ -238,7 +239,7 @@ class Depreciation { $period = FinancialValidations::validateFloat($period); if ($period <= 0.0 && $negativeValueAllowed === false) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $period; @@ -248,7 +249,7 @@ class Depreciation { $month = FinancialValidations::validateInt($month); if ($month < 1) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $month; @@ -258,7 +259,7 @@ class Depreciation { $factor = FinancialValidations::validateFloat($factor); if ($factor <= 0.0) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $factor; diff --git a/src/PhpSpreadsheet/Calculation/Financial/Dollar.php b/src/PhpSpreadsheet/Calculation/Financial/Dollar.php index 0dde0c16..b1f0d25c 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Dollar.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Dollar.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\TextData\Format; class Dollar @@ -67,10 +68,10 @@ class Dollar // Additional parameter validations if ($fraction < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($fraction == 0) { - return Functions::DIV0(); + return ExcelError::DIV0(); } $dollars = ($fractionalDollar < 0) ? ceil($fractionalDollar) : floor($fractionalDollar); @@ -115,10 +116,10 @@ class Dollar // Additional parameter validations if ($fraction < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($fraction == 0) { - return Functions::DIV0(); + return ExcelError::DIV0(); } $dollars = ($decimalDollar < 0.0) ? ceil($decimalDollar) : floor($decimalDollar); diff --git a/src/PhpSpreadsheet/Calculation/Financial/FinancialValidations.php b/src/PhpSpreadsheet/Calculation/Financial/FinancialValidations.php index 310e0051..1b044197 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/FinancialValidations.php +++ b/src/PhpSpreadsheet/Calculation/Financial/FinancialValidations.php @@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class FinancialValidations { @@ -39,7 +39,7 @@ class FinancialValidations public static function validateFloat($value): float { if (!is_numeric($value)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (float) $value; @@ -51,7 +51,7 @@ class FinancialValidations public static function validateInt($value): int { if (!is_numeric($value)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (int) floor((float) $value); @@ -64,7 +64,7 @@ class FinancialValidations { $rate = self::validateFloat($rate); if ($rate < 0.0) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $rate; @@ -81,7 +81,7 @@ class FinancialValidations ($frequency !== FinancialConstants::FREQUENCY_SEMI_ANNUAL) && ($frequency !== FinancialConstants::FREQUENCY_QUARTERLY) ) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $frequency; @@ -93,12 +93,12 @@ class FinancialValidations public static function validateBasis($basis): int { if (!is_numeric($basis)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } $basis = (int) $basis; if (($basis < 0) || ($basis > 4)) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $basis; @@ -111,7 +111,7 @@ class FinancialValidations { $price = self::validateFloat($price); if ($price < 0.0) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $price; @@ -124,7 +124,7 @@ class FinancialValidations { $parValue = self::validateFloat($parValue); if ($parValue < 0.0) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $parValue; @@ -137,7 +137,7 @@ class FinancialValidations { $yield = self::validateFloat($yield); if ($yield < 0.0) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $yield; @@ -150,7 +150,7 @@ class FinancialValidations { $discount = self::validateFloat($discount); if ($discount <= 0.0) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $discount; diff --git a/src/PhpSpreadsheet/Calculation/Financial/Helpers.php b/src/PhpSpreadsheet/Calculation/Financial/Helpers.php index d339b134..c7f1f46a 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Helpers.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Helpers.php @@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial; use DateTimeInterface; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Helpers { @@ -27,7 +27,7 @@ class Helpers public static function daysPerYear($year, $basis = 0) { if (!is_numeric($basis)) { - return Functions::NAN(); + return ExcelError::NAN(); } switch ($basis) { @@ -41,7 +41,7 @@ class Helpers return (DateTimeExcel\Helpers::isLeapYear($year)) ? 366 : 365; } - return Functions::NAN(); + return ExcelError::NAN(); } /** diff --git a/src/PhpSpreadsheet/Calculation/Financial/InterestRate.php b/src/PhpSpreadsheet/Calculation/Financial/InterestRate.php index 72df31e1..1cbe2657 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/InterestRate.php +++ b/src/PhpSpreadsheet/Calculation/Financial/InterestRate.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class InterestRate { @@ -34,7 +35,7 @@ class InterestRate } if ($nominalRate <= 0 || $periodsPerYear < 1) { - return Functions::NAN(); + return ExcelError::NAN(); } return ((1 + $nominalRate / $periodsPerYear) ** $periodsPerYear) - 1; @@ -63,7 +64,7 @@ class InterestRate } if ($effectiveRate <= 0 || $periodsPerYear < 1) { - return Functions::NAN(); + return ExcelError::NAN(); } // Calculate diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php index cb893707..de1748a1 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php @@ -8,6 +8,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstan use PhpOffice\PhpSpreadsheet\Calculation\Financial\Coupons; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Price { @@ -270,7 +271,7 @@ class Price } if ($investment <= 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis); if (!is_numeric($daysBetweenSettlementAndMaturity)) { diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php index 84218a96..f8d86736 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php @@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Rates { @@ -60,7 +61,7 @@ class Rates } if ($price <= 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } $daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis)); @@ -123,7 +124,7 @@ class Rates } if ($investment <= 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis)); diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/SecurityValidations.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/SecurityValidations.php index 497197b8..d3196f0f 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Securities/SecurityValidations.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/SecurityValidations.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Financial\FinancialValidations; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class SecurityValidations extends FinancialValidations { @@ -23,7 +23,7 @@ class SecurityValidations extends FinancialValidations public static function validateSecurityPeriod($settlement, $maturity): void { if ($settlement >= $maturity) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } } @@ -34,7 +34,7 @@ class SecurityValidations extends FinancialValidations { $redemption = self::validateFloat($redemption); if ($redemption <= 0.0) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $redemption; diff --git a/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php b/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php index b2c84627..7ee34f73 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php +++ b/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php @@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class TreasuryBill { @@ -38,7 +39,7 @@ class TreasuryBill } if ($discount <= 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $daysBetweenSettlementAndMaturity = $maturity - $settlement; @@ -48,7 +49,7 @@ class TreasuryBill ); if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } return (365 * $discount) / (360 - $discount * $daysBetweenSettlementAndMaturity); @@ -83,7 +84,7 @@ class TreasuryBill } if ($discount <= 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $daysBetweenSettlementAndMaturity = $maturity - $settlement; @@ -93,12 +94,12 @@ class TreasuryBill ); if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $price = 100 * (1 - (($discount * $daysBetweenSettlementAndMaturity) / 360)); if ($price < 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } return $price; @@ -139,7 +140,7 @@ class TreasuryBill ); if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } return ((100 - $price) / $price) * (360 / $daysBetweenSettlementAndMaturity); diff --git a/src/PhpSpreadsheet/Calculation/Functions.php b/src/PhpSpreadsheet/Calculation/Functions.php index 0ccf72e9..1165a281 100644 --- a/src/PhpSpreadsheet/Calculation/Functions.php +++ b/src/PhpSpreadsheet/Calculation/Functions.php @@ -41,30 +41,14 @@ class Functions */ protected static $returnDateType = self::RETURNDATE_EXCEL; - /** - * List of error codes. - * - * @var array - */ - protected static $errorCodes = [ - 'null' => '#NULL!', - 'divisionbyzero' => '#DIV/0!', - 'value' => '#VALUE!', - 'reference' => '#REF!', - 'name' => '#NAME?', - 'num' => '#NUM!', - 'na' => '#N/A', - 'gettingdata' => '#GETTING_DATA', - ]; - /** * Set the Compatibility Mode. * * @param string $compatibilityMode Compatibility Mode - * Permitted values are: - * Functions::COMPATIBILITY_EXCEL 'Excel' - * Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' - * Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' + * Permitted values are: + * Functions::COMPATIBILITY_EXCEL 'Excel' + * Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' + * Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' * * @return bool (Success or Failure) */ @@ -87,10 +71,10 @@ class Functions * Return the current Compatibility Mode. * * @return string Compatibility Mode - * Possible Return values are: - * Functions::COMPATIBILITY_EXCEL 'Excel' - * Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' - * Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' + * Possible Return values are: + * Functions::COMPATIBILITY_EXCEL 'Excel' + * Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' + * Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' */ public static function getCompatibilityMode() { @@ -98,13 +82,13 @@ class Functions } /** - * Set the Return Date Format used by functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object). + * Set the Return Date Format used by functions that return a date/time (Excel, PHP Serialized Numeric or PHP DateTime Object). * * @param string $returnDateType Return Date Format - * Permitted values are: - * Functions::RETURNDATE_UNIX_TIMESTAMP 'P' - * Functions::RETURNDATE_PHP_DATETIME_OBJECT 'O' - * Functions::RETURNDATE_EXCEL 'E' + * Permitted values are: + * Functions::RETURNDATE_UNIX_TIMESTAMP 'P' + * Functions::RETURNDATE_PHP_DATETIME_OBJECT 'O' + * Functions::RETURNDATE_EXCEL 'E' * * @return bool Success or failure */ @@ -127,10 +111,10 @@ class Functions * Return the current Return Date Format for functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object). * * @return string Return Date Format - * Possible Return values are: - * Functions::RETURNDATE_UNIX_TIMESTAMP 'P' - * Functions::RETURNDATE_PHP_DATETIME_OBJECT 'O' - * Functions::RETURNDATE_EXCEL 'E' + * Possible Return values are: + * Functions::RETURNDATE_UNIX_TIMESTAMP 'P' + * Functions::RETURNDATE_PHP_DATETIME_OBJECT 'O' + * Functions::RETURNDATE_EXCEL ' 'E' */ public static function getReturnDateType() { @@ -147,90 +131,21 @@ class Functions return '#Not Yet Implemented'; } - /** - * DIV0. - * - * @return string #Not Yet Implemented - */ - public static function DIV0() - { - return self::$errorCodes['divisionbyzero']; - } - - /** - * NA. - * - * Excel Function: - * =NA() - * - * Returns the error value #N/A - * #N/A is the error value that means "no value is available." - * - * @return string #N/A! - */ - public static function NA() - { - return self::$errorCodes['na']; - } - - /** - * NaN. - * - * Returns the error value #NUM! - * - * @return string #NUM! - */ - public static function NAN() - { - return self::$errorCodes['num']; - } - - /** - * NAME. - * - * Returns the error value #NAME? - * - * @return string #NAME? - */ - public static function NAME() - { - return self::$errorCodes['name']; - } - - /** - * REF. - * - * Returns the error value #REF! - * - * @return string #REF! - */ - public static function REF() - { - return self::$errorCodes['reference']; - } - /** * NULL. * * Returns the error value #NULL! * + * @Deprecated 1.23.0 + * * @return string #NULL! + * + *@see Information\ExcelError::null() + * Use the null() method in the Information\Error class instead */ public static function null() { - return self::$errorCodes['null']; - } - - /** - * VALUE. - * - * Returns the error value #VALUE! - * - * @return string #VALUE! - */ - public static function VALUE() - { - return self::$errorCodes['value']; + return Information\ExcelError::null(); } public static function isMatrixValue($idx) @@ -240,7 +155,7 @@ class Functions public static function isValue($idx) { - return substr_count($idx, '.') == 0; + return substr_count($idx, '.') === 0; } public static function isCellValue($idx) @@ -300,26 +215,125 @@ class Functions return $operand; } + /** + * NaN. + * + * Returns the error value #NUM! + * + * @Deprecated 1.23.0 + * + * @return string #NUM! + * + * @see Information\ExcelError::NAN() + * Use the NAN() method in the Information\Error class instead + */ + public static function NAN() + { + return Information\ExcelError::NAN(); + } + + /** + * REF. + * + * Returns the error value #REF! + * + * @Deprecated 1.23.0 + * + * @return string #REF! + * + * @see Information\ExcelError::REF() + * Use the REF() method in the Information\Error class instead + */ + public static function REF() + { + return Information\ExcelError::REF(); + } + + /** + * NA. + * + * Excel Function: + * =NA() + * + * Returns the error value #N/A + * #N/A is the error value that means "no value is available." + * + * @Deprecated 1.23.0 + * + * @return string #N/A! + * + * @see Information\ExcelError::NA() + * Use the NA() method in the Information\Error class instead + */ + public static function NA() + { + return Information\ExcelError::NA(); + } + + /** + * VALUE. + * + * Returns the error value #VALUE! + * + * @Deprecated 1.23.0 + * + * @return string #VALUE! + * + * @see Information\ExcelError::VALUE() + * Use the VALUE() method in the Information\Error class instead + */ + public static function VALUE() + { + return Information\ExcelError::VALUE(); + } + + /** + * NAME. + * + * Returns the error value #NAME? + * + * @Deprecated 1.23.0 + * + * @return string #NAME? + * + * @see Information\ExcelError::NAME() + * Use the NAME() method in the Information\Error class instead + */ + public static function NAME() + { + return Information\ExcelError::NAME(); + } + + /** + * DIV0. + * + * @Deprecated 1.23.0 + * + * @return string #Not Yet Implemented + * + *@see Information\ExcelError::DIV0() + * Use the DIV0() method in the Information\Error class instead + */ + public static function DIV0() + { + return Information\ExcelError::DIV0(); + } + /** * ERROR_TYPE. * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * * @return int|string + * + * @see Information\ExcelError::type() + * Use the type() method in the Information\Error class instead */ public static function errorType($value = '') { - $value = self::flattenSingleValue($value); - - $i = 1; - foreach (self::$errorCodes as $errorCode) { - if ($value === $errorCode) { - return $i; - } - ++$i; - } - - return self::NA(); + return Information\ExcelError::type($value); } /** @@ -327,15 +341,16 @@ class Functions * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * + * @see Information\Value::isBlank() + * Use the isBlank() method in the Information\Value class instead + * * @return bool */ public static function isBlank($value = null) { - if ($value !== null) { - $value = self::flattenSingleValue($value); - } - - return $value === null; + return Information\Value::isBlank($value); } /** @@ -343,13 +358,16 @@ class Functions * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * + * @see Information\Value::isErr() + * Use the isErr() method in the Information\Value class instead + * * @return bool */ public static function isErr($value = '') { - $value = self::flattenSingleValue($value); - - return self::isError($value) && (!self::isNa(($value))); + return Information\Value::isErr($value); } /** @@ -357,17 +375,16 @@ class Functions * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * + * @see Information\Value::isError() + * Use the isError() method in the Information\Value class instead + * * @return bool */ public static function isError($value = '') { - $value = self::flattenSingleValue($value); - - if (!is_string($value)) { - return false; - } - - return in_array($value, self::$errorCodes); + return Information\Value::isError($value); } /** @@ -375,13 +392,16 @@ class Functions * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * + * @see Information\Value::isNa() + * Use the isNa() method in the Information\Value class instead + * * @return bool */ public static function isNa($value = '') { - $value = self::flattenSingleValue($value); - - return $value === self::NA(); + return Information\Value::isNa($value); } /** @@ -389,19 +409,16 @@ class Functions * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * + * @see Information\Value::isEven() + * Use the isEven() method in the Information\Value class instead + * * @return bool|string */ public static function isEven($value = null) { - $value = self::flattenSingleValue($value); - - if ($value === null) { - return self::NAME(); - } elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) { - return self::VALUE(); - } - - return $value % 2 == 0; + return Information\Value::isEven($value); } /** @@ -409,19 +426,16 @@ class Functions * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * + * @see Information\Value::isOdd() + * Use the isOdd() method in the Information\Value class instead + * * @return bool|string */ public static function isOdd($value = null) { - $value = self::flattenSingleValue($value); - - if ($value === null) { - return self::NAME(); - } elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) { - return self::VALUE(); - } - - return abs($value) % 2 == 1; + return Information\Value::isOdd($value); } /** @@ -429,17 +443,16 @@ class Functions * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * + * @see Information\Value::isNumber() + * Use the isNumber() method in the Information\Value class instead + * * @return bool */ public static function isNumber($value = null) { - $value = self::flattenSingleValue($value); - - if (is_string($value)) { - return false; - } - - return is_numeric($value); + return Information\Value::isNumber($value); } /** @@ -447,13 +460,16 @@ class Functions * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * + * @see Information\Value::isLogical() + * Use the isLogical() method in the Information\Value class instead + * * @return bool */ public static function isLogical($value = null) { - $value = self::flattenSingleValue($value); - - return is_bool($value); + return Information\Value::isLogical($value); } /** @@ -461,13 +477,16 @@ class Functions * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * + * @see Information\Value::isText() + * Use the isText() method in the Information\Value class instead + * * @return bool */ public static function isText($value = null) { - $value = self::flattenSingleValue($value); - - return is_string($value) && !self::isError($value); + return Information\Value::isText($value); } /** @@ -475,11 +494,16 @@ class Functions * * @param mixed $value Value to check * + * @Deprecated 1.23.0 + * + * @see Information\Value::isNonText() + * Use the isNonText() method in the Information\Value class instead + * * @return bool */ public static function isNonText($value = null) { - return !self::isText($value); + return Information\Value::isNonText($value); } /** @@ -487,6 +511,11 @@ class Functions * * Returns a value converted to a number * + * @Deprecated 1.23.0 + * + * @see Information\Value::asNumber() + * Use the asNumber() method in the Information\Value class instead + * * @param null|mixed $value The value you want converted * * @return number N converts values listed in the following table @@ -500,27 +529,7 @@ class Functions */ public static function n($value = null) { - while (is_array($value)) { - $value = array_shift($value); - } - - switch (gettype($value)) { - case 'double': - case 'float': - case 'integer': - return $value; - case 'boolean': - return (int) $value; - case 'string': - // Errors - if ((strlen($value) > 0) && ($value[0] == '#')) { - return $value; - } - - break; - } - - return 0; + return Information\Value::asNumber($value); } /** @@ -528,6 +537,11 @@ class Functions * * Returns a number that identifies the type of a value * + * @Deprecated 1.23.0 + * + * @see Information\Value::type() + * Use the type() method in the Information\Value class instead + * * @param null|mixed $value The value you want tested * * @return number N converts values listed in the following table @@ -540,39 +554,7 @@ class Functions */ public static function TYPE($value = null) { - $value = self::flattenArrayIndexed($value); - if (is_array($value) && (count($value) > 1)) { - end($value); - $a = key($value); - // Range of cells is an error - if (self::isCellValue($a)) { - return 16; - // Test for Matrix - } elseif (self::isMatrixValue($a)) { - return 64; - } - } elseif (empty($value)) { - // Empty Cell - return 1; - } - $value = self::flattenSingleValue($value); - - if (($value === null) || (is_float($value)) || (is_int($value))) { - return 1; - } elseif (is_bool($value)) { - return 4; - } elseif (is_array($value)) { - return 64; - } elseif (is_string($value)) { - // Errors - if ((strlen($value) > 0) && ($value[0] == '#')) { - return 16; - } - - return 2; - } - - return 0; + return Information\Value::type($value); } /** @@ -678,6 +660,11 @@ class Functions /** * ISFORMULA. * + * @Deprecated 1.23.0 + * + * @see Information\Value::isFormula() + * Use the isFormula() method in the Information\Value class instead + * * @param mixed $cellReference The cell to check * @param ?Cell $cell The current cell (containing this formula) * @@ -685,22 +672,7 @@ class Functions */ public static function isFormula($cellReference = '', ?Cell $cell = null) { - if ($cell === null) { - return self::REF(); - } - $cellReference = self::expandDefinedName((string) $cellReference, $cell); - $cellReference = self::trimTrailingRange($cellReference); - - preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches); - - $cellReference = $matches[6] . $matches[7]; - $worksheetName = str_replace("''", "'", trim($matches[2], "'")); - - $worksheet = (!empty($worksheetName)) - ? $cell->getWorksheet()->getParent()->getSheetByName($worksheetName) - : $cell->getWorksheet(); - - return $worksheet->getCell($cellReference)->isFormula(); + return Information\Value::isFormula($cellReference, $cell); } public static function expandDefinedName(string $coordinate, Cell $cell): string diff --git a/src/PhpSpreadsheet/Calculation/Information/ExcelError.php b/src/PhpSpreadsheet/Calculation/Information/ExcelError.php new file mode 100644 index 00000000..df003d26 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/Information/ExcelError.php @@ -0,0 +1,132 @@ + '#NULL!', + 'divisionbyzero' => '#DIV/0!', + 'value' => '#VALUE!', + 'reference' => '#REF!', + 'name' => '#NAME?', + 'num' => '#NUM!', + 'na' => '#N/A', + 'gettingdata' => '#GETTING_DATA', + ]; + + /** + * ERROR_TYPE. + * + * @param mixed $value Value to check + * + * @return int|string + */ + public static function type($value = '') + { + $value = Functions::flattenSingleValue($value); + + $i = 1; + foreach (self::$errorCodes as $errorCode) { + if ($value === $errorCode) { + return $i; + } + ++$i; + } + + return self::NA(); + } + + /** + * NULL. + * + * Returns the error value #NULL! + * + * @return string #NULL! + */ + public static function null() + { + return self::$errorCodes['null']; + } + + /** + * NaN. + * + * Returns the error value #NUM! + * + * @return string #NUM! + */ + public static function NAN() + { + return self::$errorCodes['num']; + } + + /** + * REF. + * + * Returns the error value #REF! + * + * @return string #REF! + */ + public static function REF() + { + return self::$errorCodes['reference']; + } + + /** + * NA. + * + * Excel Function: + * =NA() + * + * Returns the error value #N/A + * #N/A is the error value that means "no value is available." + * + * @return string #N/A! + */ + public static function NA() + { + return self::$errorCodes['na']; + } + + /** + * VALUE. + * + * Returns the error value #VALUE! + * + * @return string #VALUE! + */ + public static function VALUE() + { + return self::$errorCodes['value']; + } + + /** + * NAME. + * + * Returns the error value #NAME? + * + * @return string #NAME? + */ + public static function NAME() + { + return self::$errorCodes['name']; + } + + /** + * DIV0. + * + * @return string #Not Yet Implemented + */ + public static function DIV0() + { + return self::$errorCodes['divisionbyzero']; + } +} diff --git a/src/PhpSpreadsheet/Calculation/Information/Value.php b/src/PhpSpreadsheet/Calculation/Information/Value.php new file mode 100644 index 00000000..9c4d09b0 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/Information/Value.php @@ -0,0 +1,291 @@ +getWorksheet()->getParent()->getSheetByName($worksheetName) + : $cell->getWorksheet(); + + return ($worksheet !== null) ? $worksheet->getCell($cellReference)->isFormula() : ExcelError::REF(); + } + + /** + * IS_ERR. + * + * @param mixed $value Value to check + * + * @return bool + */ + public static function isErr($value = '') + { + $value = Functions::flattenSingleValue($value); + + return self::isError($value) && (!self::isNa(($value))); + } + + /** + * IS_ERROR. + * + * @param mixed $value Value to check + * + * @return bool + */ + public static function isError($value = '') + { + $value = Functions::flattenSingleValue($value); + + if (!is_string($value)) { + return false; + } + + return in_array($value, ExcelError::$errorCodes); + } + + /** + * IS_NA. + * + * @param mixed $value Value to check + * + * @return bool + */ + public static function isNa($value = '') + { + $value = Functions::flattenSingleValue($value); + + return $value === ExcelError::NA(); + } + + /** + * N. + * + * Returns a value converted to a number + * + * @param null|mixed $value The value you want converted + * + * @return number N converts values listed in the following table + * If value is or refers to N returns + * A number That number + * A date The serial number of that date + * TRUE 1 + * FALSE 0 + * An error value The error value + * Anything else 0 + */ + public static function asNumber($value = null) + { + while (is_array($value)) { + $value = array_shift($value); + } + + switch (gettype($value)) { + case 'double': + case 'float': + case 'integer': + return $value; + case 'boolean': + return (int) $value; + case 'string': + // Errors + if ((strlen($value) > 0) && ($value[0] == '#')) { + return $value; + } + + break; + } + + return 0; + } + + /** + * TYPE. + * + * Returns a number that identifies the type of a value + * + * @param null|mixed $value The value you want tested + * + * @return number N converts values listed in the following table + * If value is or refers to N returns + * A number 1 + * Text 2 + * Logical Value 4 + * An error value 16 + * Array or Matrix 64 + */ + public static function type($value = null) + { + $value = Functions::flattenArrayIndexed($value); + if (is_array($value) && (count($value) > 1)) { + end($value); + $a = key($value); + // Range of cells is an error + if (Functions::isCellValue($a)) { + return 16; + // Test for Matrix + } elseif (Functions::isMatrixValue($a)) { + return 64; + } + } elseif (empty($value)) { + // Empty Cell + return 1; + } + $value = Functions::flattenSingleValue($value); + + if (($value === null) || (is_float($value)) || (is_int($value))) { + return 1; + } elseif (is_bool($value)) { + return 4; + } elseif (is_array($value)) { + return 64; + } elseif (is_string($value)) { + // Errors + if ((strlen($value) > 0) && ($value[0] == '#')) { + return 16; + } + + return 2; + } + + return 0; + } +} diff --git a/src/PhpSpreadsheet/Calculation/Logical/Conditional.php b/src/PhpSpreadsheet/Calculation/Logical/Conditional.php index 12d5b855..86842d3a 100644 --- a/src/PhpSpreadsheet/Calculation/Logical/Conditional.php +++ b/src/PhpSpreadsheet/Calculation/Logical/Conditional.php @@ -5,6 +5,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Logical; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; +use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; class Conditional { @@ -45,7 +47,7 @@ class Conditional */ public static function statementIf($condition = true, $returnIfTrue = 0, $returnIfFalse = false) { - if (Functions::isError($condition)) { + if (Value::isError($condition)) { return $condition; } @@ -84,7 +86,7 @@ class Conditional */ public static function statementSwitch(...$arguments) { - $result = Functions::VALUE(); + $result = ExcelError::VALUE(); if (count($arguments) > 0) { $targetValue = Functions::flattenSingleValue($arguments[0]); @@ -106,7 +108,7 @@ class Conditional } if ($switchSatisfied !== true) { - $result = $hasDefaultClause ? $defaultClause : Functions::NA(); + $result = $hasDefaultClause ? $defaultClause : ExcelError::NA(); } } @@ -136,7 +138,7 @@ class Conditional $errorpart = $errorpart ?? ''; - return self::statementIf(Functions::isError($testValue), $errorpart, $testValue); + return self::statementIf(Value::isError($testValue), $errorpart, $testValue); } /** @@ -162,7 +164,7 @@ class Conditional $napart = $napart ?? ''; - return self::statementIf(Functions::isNa($testValue), $napart, $testValue); + return self::statementIf(Value::isNa($testValue), $napart, $testValue); } /** @@ -186,7 +188,7 @@ class Conditional $argumentCount = count($arguments); if ($argumentCount % 2 != 0) { - return Functions::NA(); + return ExcelError::NA(); } // We use instance of Exception as a falseValue in order to prevent string collision with value in cell $falseValueException = new Exception(); @@ -200,6 +202,6 @@ class Conditional } } - return Functions::NA(); + return ExcelError::NA(); } } diff --git a/src/PhpSpreadsheet/Calculation/Logical/Operations.php b/src/PhpSpreadsheet/Calculation/Logical/Operations.php index 7c839859..2e2faa13 100644 --- a/src/PhpSpreadsheet/Calculation/Logical/Operations.php +++ b/src/PhpSpreadsheet/Calculation/Logical/Operations.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Logical; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Operations { @@ -35,7 +36,7 @@ class Operations $args = Functions::flattenArray($args); if (count($args) == 0) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $args = array_filter($args, function ($value) { @@ -76,7 +77,7 @@ class Operations $args = Functions::flattenArray($args); if (count($args) == 0) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $args = array_filter($args, function ($value) { @@ -118,7 +119,7 @@ class Operations $args = Functions::flattenArray($args); if (count($args) == 0) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $args = array_filter($args, function ($value) { @@ -169,7 +170,7 @@ class Operations return true; } - return Functions::VALUE(); + return ExcelError::VALUE(); } return !$logical; @@ -195,7 +196,7 @@ class Operations } elseif (($arg == 'FALSE') || ($arg == Calculation::getFALSE())) { $arg = false; } else { - return Functions::VALUE(); + return ExcelError::VALUE(); } $trueValueCount += ($arg != 0); } diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Address.php b/src/PhpSpreadsheet/Calculation/LookupRef/Address.php index 58215f27..34215ca6 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/Address.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/Address.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; class Address @@ -46,7 +47,7 @@ class Address $sheetName = Functions::flattenSingleValue($sheetName); if (($row < 1) || ($column < 1)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $sheetName = self::sheetName($sheetName); diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/ExcelMatch.php b/src/PhpSpreadsheet/Calculation/LookupRef/ExcelMatch.php index 71358bf3..4d2361a0 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/ExcelMatch.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/ExcelMatch.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\Internal\WildcardMatch; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; @@ -79,7 +80,7 @@ class ExcelMatch } // Unsuccessful in finding a match, return #N/A error value - return Functions::NA(); + return ExcelError::NA(); } private static function matchFirstValue($lookupArray, $lookupValue) @@ -149,7 +150,7 @@ class ExcelMatch { // Lookup_value type has to be number, text, or logical values if ((!is_numeric($lookupValue)) && (!is_string($lookupValue)) && (!is_bool($lookupValue))) { - throw new Exception(Functions::NA()); + throw new Exception(ExcelError::NA()); } } @@ -160,7 +161,7 @@ class ExcelMatch ($matchType !== self::MATCHTYPE_FIRST_VALUE) && ($matchType !== self::MATCHTYPE_LARGEST_VALUE) && ($matchType !== self::MATCHTYPE_SMALLEST_VALUE) ) { - throw new Exception(Functions::NA()); + throw new Exception(ExcelError::NA()); } } @@ -169,7 +170,7 @@ class ExcelMatch // Lookup_array should not be empty $lookupArraySize = count($lookupArray); if ($lookupArraySize <= 0) { - throw new Exception(Functions::NA()); + throw new Exception(ExcelError::NA()); } } @@ -179,7 +180,7 @@ class ExcelMatch foreach ($lookupArray as $i => $value) { // check the type of the value if ((!is_numeric($value)) && (!is_string($value)) && (!is_bool($value)) && ($value !== null)) { - throw new Exception(Functions::NA()); + throw new Exception(ExcelError::NA()); } // Convert strings to lowercase for case-insensitive testing if (is_string($value)) { diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Formula.php b/src/PhpSpreadsheet/Calculation/LookupRef/Formula.php index f3e6c419..834fe52a 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/Formula.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/Formula.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Cell\Cell; class Formula @@ -19,7 +19,7 @@ class Formula public static function text($cellReference = '', ?Cell $cell = null) { if ($cell === null) { - return Functions::REF(); + return ExcelError::REF(); } preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches); @@ -35,7 +35,7 @@ class Formula !$worksheet->cellExists($cellReference) || !$worksheet->getCell($cellReference)->isFormula() ) { - return Functions::NA(); + return ExcelError::NA(); } return $worksheet->getCell($cellReference)->getValue(); diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php b/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php index 7db27804..69060e1d 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; @@ -38,7 +39,7 @@ class HLookup extends LookupBase $f = array_keys($lookupArray); $firstRow = reset($f); if ((!is_array($lookupArray[$firstRow])) || ($indexNumber > count($lookupArray))) { - return Functions::REF(); + return ExcelError::REF(); } $firstkey = $f[0] - 1; @@ -51,7 +52,7 @@ class HLookup extends LookupBase return $lookupArray[$returnColumn][Coordinate::stringFromColumnIndex($rowNumber)]; } - return Functions::NA(); + return ExcelError::NA(); } /** diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php b/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php index 1448c089..5387833f 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Cell\Cell; class Hyperlink @@ -25,7 +26,7 @@ class Hyperlink $displayName = ($displayName === null) ? '' : Functions::flattenSingleValue($displayName); if ((!is_object($cell)) || (trim($linkURL) == '')) { - return Functions::REF(); + return ExcelError::REF(); } if ((is_object($displayName)) || trim($displayName) == '') { diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Indirect.php b/src/PhpSpreadsheet/Calculation/LookupRef/Indirect.php index b5a35410..d0c13a5c 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/Indirect.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/Indirect.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use Exception; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; @@ -23,7 +24,7 @@ class Indirect return Helpers::CELLADDRESS_USE_A1; } if (is_string($a1fmt)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (bool) $a1fmt; @@ -38,7 +39,7 @@ class Indirect { $cellAddress = Functions::flattenSingleValue($cellAddress); if (!is_string($cellAddress) || !$cellAddress) { - throw new Exception(Functions::REF()); + throw new Exception(ExcelError::REF()); } return $cellAddress; @@ -77,7 +78,7 @@ class Indirect (!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress1, $matches)) || (($cellAddress2 !== null) && (!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress2, $matches))) ) { - return Functions::REF(); + return ExcelError::REF(); } return self::extractRequiredCells($worksheet, $cellAddress); diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Lookup.php b/src/PhpSpreadsheet/Calculation/LookupRef/Lookup.php index e21d35dc..a3e57a1e 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/Lookup.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/Lookup.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\LookupRef; class Lookup @@ -22,7 +23,7 @@ class Lookup $lookupValue = Functions::flattenSingleValue($lookupValue); if (!is_array($lookupVector)) { - return Functions::NA(); + return ExcelError::NA(); } $hasResultVector = isset($resultVector); $lookupRows = self::rowCount($lookupVector); diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php b/src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php index 80fc99ad..b2627891 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; abstract class LookupBase { @@ -11,12 +11,12 @@ abstract class LookupBase { // index_number must be a number greater than or equal to 1 if (!is_numeric($index_number) || $index_number < 1) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } // index_number must be less than or equal to the number of columns in lookup_array if ((!is_array($lookup_array)) || (empty($lookup_array))) { - throw new Exception(Functions::REF()); + throw new Exception(ExcelError::REF()); } return (int) $index_number; diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/LookupRefValidations.php b/src/PhpSpreadsheet/Calculation/LookupRef/LookupRefValidations.php index b0739eb3..e1f39765 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/LookupRefValidations.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/LookupRefValidations.php @@ -3,7 +3,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; +use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; class LookupRefValidations { @@ -13,11 +14,11 @@ class LookupRefValidations public static function validateInt($value): int { if (!is_numeric($value)) { - if (Functions::isError($value)) { + if (Value::isError($value)) { throw new Exception($value); } - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (int) floor((float) $value); @@ -31,7 +32,7 @@ class LookupRefValidations $value = self::validateInt($value); if (($allowZero === false && $value <= 0) || $value < 0) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return $value; diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Matrix.php b/src/PhpSpreadsheet/Calculation/LookupRef/Matrix.php index 71d22b3d..e3e5cd98 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/Matrix.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/Matrix.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Matrix { @@ -65,14 +66,14 @@ class Matrix } if (!is_array($matrix) || ($rowNum > count($matrix))) { - return Functions::REF(); + return ExcelError::REF(); } $rowKeys = array_keys($matrix); $columnKeys = @array_keys($matrix[$rowKeys[0]]); if ($columnNum > count($columnKeys)) { - return Functions::REF(); + return ExcelError::REF(); } if ($columnNum === 0) { diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Offset.php b/src/PhpSpreadsheet/Calculation/LookupRef/Offset.php index 7e33f55a..9f3377f6 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/Offset.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/Offset.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; @@ -48,11 +49,11 @@ class Offset $width = Functions::flattenSingleValue($width); if ($cellAddress === null || $cellAddress === '') { - return Functions::VALUE(); + return ExcelError::VALUE(); } if (!is_object($cell)) { - return Functions::REF(); + return ExcelError::REF(); } [$cellAddress, $worksheet] = self::extractWorksheet($cellAddress, $cell); @@ -69,7 +70,7 @@ class Offset $startCellColumn += $columns; if (($startCellRow <= 0) || ($startCellColumn < 0)) { - return Functions::REF(); + return ExcelError::REF(); } $endCellColumn = self::adjustEndCellColumnForWidth($endCellColumn, $width, $startCellColumn, $columns); @@ -78,7 +79,7 @@ class Offset $endCellRow = self::adustEndCellRowForHeight($height, $startCellRow, $rows, $endCellRow); if (($endCellRow <= 0) || ($endCellColumn < 0)) { - return Functions::REF(); + return ExcelError::REF(); } $endCellColumn = Coordinate::stringFromColumnIndex($endCellColumn + 1); diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php b/src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php index 9752d673..625784fd 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; @@ -99,7 +99,7 @@ class RowColumnInformation return 1; } if (!is_array($cellAddress)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } reset($cellAddress); @@ -193,7 +193,7 @@ class RowColumnInformation return 1; } if (!is_array($cellAddress)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } reset($cellAddress); diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Selection.php b/src/PhpSpreadsheet/Calculation/LookupRef/Selection.php index 6c18d73b..05df11ed 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/Selection.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/Selection.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Selection { @@ -30,11 +31,11 @@ class Selection if (is_numeric($chosenEntry)) { --$chosenEntry; } else { - return Functions::VALUE(); + return ExcelError::VALUE(); } $chosenEntry = floor($chosenEntry); if (($chosenEntry < 0) || ($chosenEntry > $entryCount)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } if (is_array($chooseArgs[$chosenEntry])) { diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php b/src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php index ddd5d9ee..bbbaeda1 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; class VLookup extends LookupBase @@ -36,7 +37,7 @@ class VLookup extends LookupBase $f = array_keys($lookupArray); $firstRow = array_pop($f); if ((!is_array($lookupArray[$firstRow])) || ($indexNumber > count($lookupArray[$firstRow]))) { - return Functions::REF(); + return ExcelError::REF(); } $columnKeys = array_keys($lookupArray[$firstRow]); $returnColumn = $columnKeys[--$indexNumber]; @@ -53,7 +54,7 @@ class VLookup extends LookupBase return $lookupArray[$rowNumber][$returnColumn]; } - return Functions::NA(); + return ExcelError::NA(); } private static function vlookupSort($a, $b) diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php b/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php index 200d2578..ee488505 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Arabic { @@ -100,7 +100,7 @@ class Arabic try { $arabic = self::calculateArabic(self::strSplit($roman)); } catch (Exception $e) { - return Functions::VALUE(); // Invalid character detected + return ExcelError::VALUE(); // Invalid character detected } if ($negativeNumber) { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Base.php b/src/PhpSpreadsheet/Calculation/MathTrig/Base.php index a31a5681..2fec9473 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Base.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Base.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Base { @@ -52,7 +52,7 @@ class Base { if ($minLength === null || is_numeric($minLength)) { if ($number < 0 || $number >= 2 ** 53 || $radix < 2 || $radix > 36) { - return Functions::NAN(); // Numeric range constraints + return ExcelError::NAN(); // Numeric range constraints } $outcome = strtoupper((string) base_convert("$number", 10, $radix)); @@ -63,6 +63,6 @@ class Base return $outcome; } - return Functions::VALUE(); + return ExcelError::VALUE(); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php b/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php index fd17f653..635f1bbb 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Ceiling { @@ -153,7 +154,7 @@ class Ceiling return ceil($number / $significance) * $significance; } - return Functions::NAN(); + return ExcelError::NAN(); } private static function floorCheck1Arg(): void diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php b/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php index 16cde987..2199dda0 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Floor { @@ -132,7 +133,7 @@ class Floor private static function argumentsOkPrecise(float $number, float $significance) { if ($significance == 0.0) { - return Functions::DIV0(); + return ExcelError::DIV0(); } if ($number == 0.0) { return 0.0; @@ -149,7 +150,7 @@ class Floor private static function argsOk(float $number, float $significance, int $mode) { if (!$significance) { - return Functions::DIV0(); + return ExcelError::DIV0(); } if (!$number) { return 0.0; @@ -177,7 +178,7 @@ class Floor private static function argumentsOk(float $number, float $significance) { if ($significance == 0.0) { - return Functions::DIV0(); + return ExcelError::DIV0(); } if ($number == 0.0) { return 0.0; @@ -189,6 +190,6 @@ class Floor return floor($number / $significance) * $significance; } - return Functions::NAN(); + return ExcelError::NAN(); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Gcd.php b/src/PhpSpreadsheet/Calculation/MathTrig/Gcd.php index 1dd52faa..f7035998 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Gcd.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Gcd.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Gcd { @@ -57,7 +58,7 @@ class Gcd } if (count($arrayArgs) <= 0) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $gcd = (int) array_pop($arrayArgs); do { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php b/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php index b89644a9..348aa5b3 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Helpers { @@ -14,7 +15,7 @@ class Helpers */ public static function verySmallDenominator(float $numerator, float $denominator) { - return (abs($denominator) < 1.0E-12) ? Functions::DIV0() : ($numerator / $denominator); + return (abs($denominator) < 1.0E-12) ? ExcelError::DIV0() : ($numerator / $denominator); } /** @@ -37,7 +38,7 @@ class Helpers return 0 + $number; } - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } /** @@ -58,7 +59,7 @@ class Helpers return 0 + $number; } - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } /** @@ -72,7 +73,7 @@ class Helpers return; } - throw new Exception($except ?? Functions::NAN()); + throw new Exception($except ?? ExcelError::NAN()); } /** @@ -86,7 +87,7 @@ class Helpers return; } - throw new Exception($except ?? Functions::NAN()); + throw new Exception($except ?? ExcelError::NAN()); } /** @@ -100,7 +101,7 @@ class Helpers return; } - throw new Exception(Functions::DIV0()); + throw new Exception(ExcelError::DIV0()); } public static function returnSign(float $number): int @@ -124,6 +125,6 @@ class Helpers */ public static function numberOrNan($result) { - return is_nan($result) ? Functions::NAN() : $result; + return is_nan($result) ? ExcelError::NAN() : $result; } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php b/src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php index 46e9816d..3b23c1da 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Lcm { @@ -104,7 +105,7 @@ class Lcm private static function testNonNulls(int $anyNonNulls): void { if (!$anyNonNulls) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php b/src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php index 474f862d..5a5125a8 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php @@ -7,7 +7,7 @@ use Matrix\Div0Exception as MatrixDiv0Exception; use Matrix\Exception as MatrixException; use Matrix\Matrix; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class MatrixFunctions { @@ -31,7 +31,7 @@ class MatrixFunctions $column = 0; foreach ($matrixRow as $matrixCell) { if ((is_string($matrixCell)) || ($matrixCell === null)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } $matrixData[$row][$column] = $matrixCell; ++$column; @@ -102,7 +102,7 @@ class MatrixFunctions return $matrix->determinant(); } catch (MatrixException $ex) { - return Functions::VALUE(); + return ExcelError::VALUE(); } catch (Exception $e) { return $e->getMessage(); } @@ -127,9 +127,9 @@ class MatrixFunctions return $matrix->inverse()->toArray(); } catch (MatrixDiv0Exception $e) { - return Functions::NAN(); + return ExcelError::NAN(); } catch (MatrixException $e) { - return Functions::VALUE(); + return ExcelError::VALUE(); } catch (Exception $e) { return $e->getMessage(); } @@ -151,7 +151,7 @@ class MatrixFunctions return $matrixA->multiply($matrixB)->toArray(); } catch (MatrixException $ex) { - return Functions::VALUE(); + return ExcelError::VALUE(); } catch (Exception $e) { return $e->getMessage(); } @@ -168,7 +168,7 @@ class MatrixFunctions { try { $dimension = (int) Helpers::validateNumericNullBool($dimension); - Helpers::validatePositive($dimension, Functions::VALUE()); + Helpers::validatePositive($dimension, ExcelError::VALUE()); $matrix = Builder::createIdentityMatrix($dimension, 0)->toArray(); return $matrix; diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php b/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php index 4e481512..7fd30233 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Operations { @@ -75,10 +76,10 @@ class Operations // Validate parameters if (!$x && !$y) { - return Functions::NAN(); + return ExcelError::NAN(); } if (!$x && $y < 0.0) { - return Functions::DIV0(); + return ExcelError::DIV0(); } // Return @@ -114,7 +115,7 @@ class Operations $returnValue *= $arg; } } else { - return Functions::VALUE(); + return ExcelError::VALUE(); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Random.php b/src/PhpSpreadsheet/Calculation/MathTrig/Random.php index 76e983e5..b9fcfc73 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Random.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Random.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Random { @@ -78,7 +78,7 @@ class Random $max = Helpers::validateNumericNullSubstitution($max, 1); if ($max <= $min) { - return Functions::VALUE(); + return ExcelError::VALUE(); } } catch (Exception $e) { return $e->getMessage(); diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php b/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php index 7d771b29..05415481 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Roman { @@ -803,12 +803,12 @@ class Roman private static function styleOk(int $aValue, int $style): string { - return ($aValue < 0 || $aValue > self::MAX_ROMAN_VALUE) ? Functions::VALUE() : self::valueOk($aValue, $style); + return ($aValue < 0 || $aValue > self::MAX_ROMAN_VALUE) ? ExcelError::VALUE() : self::valueOk($aValue, $style); } public static function calculateRoman(int $aValue, int $style): string { - return ($style < 0 || $style > self::MAX_ROMAN_STYLE) ? Functions::VALUE() : self::styleOk($aValue, $style); + return ($style < 0 || $style > self::MAX_ROMAN_STYLE) ? ExcelError::VALUE() : self::styleOk($aValue, $style); } /** diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Round.php b/src/PhpSpreadsheet/Calculation/MathTrig/Round.php index c419ca4d..776f7eb9 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Round.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Round.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Round { @@ -144,7 +144,7 @@ class Round return round($number * $multiplier) / $multiplier; } - return Functions::NAN(); + return ExcelError::NAN(); } /** diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php b/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php index be065791..74f95dec 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\Statistical; class Subtotal @@ -109,6 +110,6 @@ class Subtotal return call_user_func_array($call, $aArgs); } - return Functions::VALUE(); + return ExcelError::VALUE(); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php index 741734d9..82b261f1 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php @@ -3,6 +3,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; +use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; class Sum { @@ -27,7 +29,7 @@ class Sum // Is it a numeric value? if (is_numeric($arg)) { $returnValue += $arg; - } elseif (Functions::isError($arg)) { + } elseif (Value::isError($arg)) { return $arg; } } @@ -61,11 +63,11 @@ class Sum $returnValue += $arg; } elseif (is_bool($arg)) { $returnValue += (int) $arg; - } elseif (Functions::isError($arg)) { + } elseif (Value::isError($arg)) { return $arg; // ignore non-numerics from cell, but fail as literals (except null) } elseif ($arg !== null && !Functions::isCellValue($k)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } } @@ -99,7 +101,7 @@ class Sum $array2 = Functions::flattenArray($matrixData); $count = count($array2); if ($wrkCellCount != $count) { - return Functions::VALUE(); + return ExcelError::VALUE(); } foreach ($array2 as $i => $val) { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php b/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php index 49fa6381..34b397cd 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class SumSquares { @@ -40,7 +41,7 @@ class SumSquares { $count = count($array1); if ($count !== count($array2)) { - throw new Exception(Functions::NA()); + throw new Exception(ExcelError::NA()); } return $count; diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php index 26bd44f7..9e770210 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Trig; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Helpers; class Tangent @@ -153,7 +153,7 @@ class Tangent } if (($xCoordinate == 0) && ($yCoordinate == 0)) { - return Functions::DIV0(); + return ExcelError::DIV0(); } return atan2($yCoordinate, $xCoordinate); diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Averages.php b/src/PhpSpreadsheet/Calculation/Statistical/Averages.php index c6d84e74..41b011a5 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Averages.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Averages.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Averages extends AggregateBase { @@ -27,10 +28,10 @@ class Averages extends AggregateBase $returnValue = 0.0; $aMean = self::average(...$args); - if ($aMean === Functions::DIV0()) { - return Functions::NAN(); - } elseif ($aMean === Functions::VALUE()) { - return Functions::VALUE(); + if ($aMean === ExcelError::DIV0()) { + return ExcelError::NAN(); + } elseif ($aMean === ExcelError::VALUE()) { + return ExcelError::VALUE(); } $aCount = 0; @@ -40,7 +41,7 @@ class Averages extends AggregateBase // Strings containing numeric values are only counted if they are string literals (not cell values) // and then only in MS Excel and in Open Office, not in Gnumeric if ((is_string($arg)) && (!is_numeric($arg)) && (!Functions::isCellValue($k))) { - return Functions::VALUE(); + return ExcelError::VALUE(); } if (self::isAcceptedCountable($arg, $k)) { $returnValue += abs($arg - $aMean); @@ -50,7 +51,7 @@ class Averages extends AggregateBase // Return if ($aCount === 0) { - return Functions::DIV0(); + return ExcelError::DIV0(); } return $returnValue / $aCount; @@ -79,7 +80,7 @@ class Averages extends AggregateBase // Strings containing numeric values are only counted if they are string literals (not cell values) // and then only in MS Excel and in Open Office, not in Gnumeric if ((is_string($arg)) && (!is_numeric($arg)) && (!Functions::isCellValue($k))) { - return Functions::VALUE(); + return ExcelError::VALUE(); } if (self::isAcceptedCountable($arg, $k)) { $returnValue += $arg; @@ -92,7 +93,7 @@ class Averages extends AggregateBase return $returnValue / $aCount; } - return Functions::DIV0(); + return ExcelError::DIV0(); } /** @@ -132,7 +133,7 @@ class Averages extends AggregateBase return $returnValue / $aCount; } - return Functions::DIV0(); + return ExcelError::DIV0(); } /** @@ -151,7 +152,7 @@ class Averages extends AggregateBase { $aArgs = Functions::flattenArray($args); - $returnValue = Functions::NAN(); + $returnValue = ExcelError::NAN(); $aArgs = self::filterArguments($aArgs); $valueCount = count($aArgs); @@ -183,7 +184,7 @@ class Averages extends AggregateBase */ public static function mode(...$args) { - $returnValue = Functions::NA(); + $returnValue = ExcelError::NA(); // Loop through arguments $aArgs = Functions::flattenArray($args); @@ -251,7 +252,7 @@ class Averages extends AggregateBase } if ($maxfreq <= 1) { - return Functions::NA(); + return ExcelError::NA(); } return $maxfreqdatum; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Averages/Mean.php b/src/PhpSpreadsheet/Calculation/Statistical/Averages/Mean.php index d4d0c7ee..001c91eb 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Averages/Mean.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Averages/Mean.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Averages; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Averages; use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Counts; @@ -36,7 +37,7 @@ class Mean } } - return Functions::NAN(); + return ExcelError::NAN(); } /** @@ -57,7 +58,7 @@ class Mean // Loop through arguments $aArgs = Functions::flattenArray($args); if (Minimum::min($aArgs) < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $returnValue = 0; @@ -66,7 +67,7 @@ class Mean // Is it a numeric value? if ((is_numeric($arg)) && (!is_string($arg))) { if ($arg <= 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $returnValue += (1 / $arg); ++$aCount; @@ -78,7 +79,7 @@ class Mean return 1 / ($returnValue / $aCount); } - return Functions::NA(); + return ExcelError::NA(); } /** @@ -104,7 +105,7 @@ class Mean if ((is_numeric($percent)) && (!is_string($percent))) { if (($percent < 0) || ($percent > 1)) { - return Functions::NAN(); + return ExcelError::NAN(); } $mArgs = []; @@ -126,6 +127,6 @@ class Mean return Averages::average($mArgs); } - return Functions::VALUE(); + return ExcelError::VALUE(); } } diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Confidence.php b/src/PhpSpreadsheet/Calculation/Statistical/Confidence.php index 8f1a0018..f2e65041 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Confidence.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Confidence.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Confidence { @@ -41,7 +42,7 @@ class Confidence } if (($alpha <= 0) || ($alpha >= 1) || ($stdDev <= 0) || ($size < 1)) { - return Functions::NAN(); + return ExcelError::NAN(); } return Functions::scalar(Distributions\StandardNormal::inverse(1 - $alpha / 2) * $stdDev / sqrt($size)); diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Deviations.php b/src/PhpSpreadsheet/Calculation/Statistical/Deviations.php index 55da9f1d..6b1db3a4 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Deviations.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Deviations.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Deviations { @@ -24,7 +25,7 @@ class Deviations $aMean = Averages::average($aArgs); if (!is_numeric($aMean)) { - return Functions::NAN(); + return ExcelError::NAN(); } // Return value @@ -45,7 +46,7 @@ class Deviations } } - return $aCount === 0 ? Functions::VALUE() : $returnValue; + return $aCount === 0 ? ExcelError::VALUE() : $returnValue; } /** @@ -65,7 +66,7 @@ class Deviations $aArgs = Functions::flattenArrayIndexed($args); $mean = Averages::average($aArgs); if (!is_numeric($mean)) { - return Functions::DIV0(); + return ExcelError::DIV0(); } $stdDev = StandardDeviations::STDEV($aArgs); @@ -90,7 +91,7 @@ class Deviations } } - return Functions::DIV0(); + return ExcelError::DIV0(); } /** @@ -110,11 +111,11 @@ class Deviations $aArgs = Functions::flattenArrayIndexed($args); $mean = Averages::average($aArgs); if (!is_numeric($mean)) { - return Functions::DIV0(); + return ExcelError::DIV0(); } $stdDev = StandardDeviations::STDEV($aArgs); if ($stdDev === 0.0 || is_string($stdDev)) { - return Functions::DIV0(); + return ExcelError::DIV0(); } $count = $summer = 0; @@ -122,7 +123,7 @@ class Deviations foreach ($aArgs as $k => $arg) { if ((is_bool($arg)) && (!Functions::isMatrixValue($k))) { } elseif (!is_numeric($arg)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } else { // Is it a numeric value? if ((is_numeric($arg)) && (!is_string($arg))) { @@ -136,6 +137,6 @@ class Deviations return $summer * ($count / (($count - 1) * ($count - 2))); } - return Functions::DIV0(); + return ExcelError::DIV0(); } } diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php index 0c6131dd..224872bf 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Beta { @@ -61,7 +62,7 @@ class Beta $rMax = $tmp; } if (($value < $rMin) || ($value > $rMax) || ($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax)) { - return Functions::NAN(); + return ExcelError::NAN(); } $value -= $rMin; @@ -115,7 +116,7 @@ class Beta $rMax = $tmp; } if (($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax) || ($probability <= 0.0)) { - return Functions::NAN(); + return ExcelError::NAN(); } return self::calculateInverse($probability, $alpha, $beta, $rMin, $rMax); @@ -143,7 +144,7 @@ class Beta } if ($i === self::MAX_ITERATIONS) { - return Functions::NA(); + return ExcelError::NA(); } return round($rMin + $guess * ($rMax - $rMin), 12); diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php index d188f2af..c255a65c 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Combinations; class Binomial @@ -49,7 +50,7 @@ class Binomial } if (($value < 0) || ($value > $trials)) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($cumulative) { @@ -98,10 +99,10 @@ class Binomial } if (($successes < 0) || ($successes > $trials)) { - return Functions::NAN(); + return ExcelError::NAN(); } if (($limit < 0) || ($limit > $trials) || $limit < $successes) { - return Functions::NAN(); + return ExcelError::NAN(); } $summer = 0; @@ -151,11 +152,11 @@ class Binomial } if (($failures < 0) || ($successes < 1)) { - return Functions::NAN(); + return ExcelError::NAN(); } if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) { if (($failures + $successes - 1) <= 0) { - return Functions::NAN(); + return ExcelError::NAN(); } } @@ -195,9 +196,9 @@ class Binomial } if ($trials < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } elseif (($alpha < 0.0) || ($alpha > 1.0)) { - return Functions::NAN(); + return ExcelError::NAN(); } $successes = 0; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php index 4ccae932..11f083c9 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class ChiSquared { @@ -42,14 +43,14 @@ class ChiSquared } if ($degrees < 1) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($value < 0) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) { return 1; } - return Functions::NAN(); + return ExcelError::NAN(); } return 1 - (Gamma::incompleteGamma($degrees / 2, $value / 2) / Gamma::gammaValue($degrees / 2)); @@ -86,14 +87,14 @@ class ChiSquared } if ($degrees < 1) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($value < 0) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) { return 1; } - return Functions::NAN(); + return ExcelError::NAN(); } if ($cumulative === true) { @@ -132,7 +133,7 @@ class ChiSquared } if ($degrees < 1) { - return Functions::NAN(); + return ExcelError::NAN(); } $callback = function ($value) use ($degrees) { @@ -173,7 +174,7 @@ class ChiSquared } if ($degrees < 1) { - return Functions::NAN(); + return ExcelError::NAN(); } return self::inverseLeftTailCalculation($probability, $degrees); @@ -201,15 +202,15 @@ class ChiSquared $countActuals = count($actual); $countExpected = count($expected); if ($countActuals !== $countExpected || $countActuals === 1) { - return Functions::NAN(); + return ExcelError::NAN(); } $result = 0.0; for ($i = 0; $i < $countActuals; ++$i) { if ($expected[$i] == 0.0) { - return Functions::DIV0(); + return ExcelError::DIV0(); } elseif ($expected[$i] < 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } $result += (($actual[$i] - $expected[$i]) ** 2) / $expected[$i]; } diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/DistributionValidations.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/DistributionValidations.php index 57ef00af..bd45a229 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/DistributionValidations.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/DistributionValidations.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\Statistical\StatisticalValidations; class DistributionValidations extends StatisticalValidations @@ -16,7 +16,7 @@ class DistributionValidations extends StatisticalValidations $probability = self::validateFloat($probability); if ($probability < 0.0 || $probability > 1.0) { - throw new Exception(Functions::NAN()); + throw new Exception(ExcelError::NAN()); } return $probability; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php index ca55857e..a03671cc 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Exponential { @@ -43,7 +43,7 @@ class Exponential } if (($value < 0) || ($lambda < 0)) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($cumulative === true) { diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php index 0fd0aab3..ff413b6b 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class F { @@ -47,7 +47,7 @@ class F } if ($value < 0 || $u < 1 || $v < 1) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($cumulative) { diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php index 8d1b5ce6..df9906ea 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Fisher { @@ -37,7 +37,7 @@ class Fisher } if (($value <= -1) || ($value >= 1)) { - return Functions::NAN(); + return ExcelError::NAN(); } return 0.5 * log((1 + $value) / (1 - $value)); diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Gamma.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Gamma.php index adf53428..216f234c 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Gamma.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Gamma.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Gamma extends GammaBase { @@ -35,7 +35,7 @@ class Gamma extends GammaBase } if ((((int) $value) == ((float) $value)) && $value <= 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } return self::gammaValue($value); @@ -75,7 +75,7 @@ class Gamma extends GammaBase } if (($value < 0) || ($a <= 0) || ($b <= 0)) { - return Functions::NAN(); + return ExcelError::NAN(); } return self::calculateDistribution($value, $a, $b, $cumulative); @@ -112,7 +112,7 @@ class Gamma extends GammaBase } if (($alpha <= 0.0) || ($beta <= 0.0)) { - return Functions::NAN(); + return ExcelError::NAN(); } return self::calculateInverse($probability, $alpha, $beta); @@ -143,7 +143,7 @@ class Gamma extends GammaBase } if ($value <= 0) { - return Functions::NAN(); + return ExcelError::NAN(); } return log(self::gammaValue($value)); diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/GammaBase.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/GammaBase.php index 89170f7c..404230ba 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/GammaBase.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/GammaBase.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; abstract class GammaBase { @@ -65,7 +66,7 @@ abstract class GammaBase } if ($i === self::MAX_ITERATIONS) { - return Functions::NA(); + return ExcelError::NA(); } return $x; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php index bb7adf7b..b3ad69d1 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Combinations; class HyperGeometric @@ -55,13 +55,13 @@ class HyperGeometric } if (($sampleSuccesses < 0) || ($sampleSuccesses > $sampleNumber) || ($sampleSuccesses > $populationSuccesses)) { - return Functions::NAN(); + return ExcelError::NAN(); } if (($sampleNumber <= 0) || ($sampleNumber > $populationNumber)) { - return Functions::NAN(); + return ExcelError::NAN(); } if (($populationSuccesses <= 0) || ($populationSuccesses > $populationNumber)) { - return Functions::NAN(); + return ExcelError::NAN(); } $successesPopulationAndSample = (float) Combinations::withoutRepetition($populationSuccesses, $sampleSuccesses); diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/LogNormal.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/LogNormal.php index 4bf2e0c5..4484f789 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/LogNormal.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/LogNormal.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class LogNormal { @@ -42,7 +42,7 @@ class LogNormal } if (($value <= 0) || ($stdDev <= 0)) { - return Functions::NAN(); + return ExcelError::NAN(); } return StandardNormal::cumulative((log($value) - $mean) / $stdDev); @@ -83,7 +83,7 @@ class LogNormal } if (($value <= 0) || ($stdDev <= 0)) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($cumulative === true) { @@ -129,7 +129,7 @@ class LogNormal } if ($stdDev <= 0) { - return Functions::NAN(); + return ExcelError::NAN(); } return exp($mean + $stdDev * StandardNormal::inverse($probability)); diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/NewtonRaphson.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/NewtonRaphson.php index 26211672..b994864e 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/NewtonRaphson.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/NewtonRaphson.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class NewtonRaphson { @@ -54,7 +55,7 @@ class NewtonRaphson } if ($i == self::MAX_ITERATIONS) { - return Functions::NA(); + return ExcelError::NA(); } return $x; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php index f876ed6d..67533c49 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php @@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Normal { @@ -49,7 +49,7 @@ class Normal } if ($stdDev < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($cumulative) { @@ -90,7 +90,7 @@ class Normal } if ($stdDev < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } return (self::inverseNcdf($probability) * $stdDev) + $mean; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php index 484bed31..0ac38746 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; class Poisson @@ -44,7 +44,7 @@ class Poisson } if (($value < 0) || ($mean < 0)) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($cumulative) { diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StandardNormal.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StandardNormal.php index 575add8a..31a02e29 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StandardNormal.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StandardNormal.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Averages; use PhpOffice\PhpSpreadsheet\Calculation\Statistical\StandardDeviations; @@ -100,7 +101,7 @@ class StandardNormal } if (!is_numeric($value)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } return self::distribution($value, true) - 0.5; @@ -128,7 +129,7 @@ class StandardNormal $sigma = Functions::flattenSingleValue($sigma); if (!is_numeric($m0) || ($sigma !== null && !is_numeric($sigma))) { - return Functions::VALUE(); + return ExcelError::VALUE(); } if ($sigma === null) { diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StudentT.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StudentT.php index 27539d62..8afc5c4b 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StudentT.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StudentT.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class StudentT { @@ -43,7 +44,7 @@ class StudentT } if (($value < 0) || ($degrees < 1) || ($tails < 1) || ($tails > 2)) { - return Functions::NAN(); + return ExcelError::NAN(); } return self::calculateDistribution($value, $degrees, $tails); @@ -77,7 +78,7 @@ class StudentT } if ($degrees <= 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $callback = function ($value) use ($degrees) { diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.php index 053a27ed..51392c41 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Weibull { @@ -45,7 +45,7 @@ class Weibull } if (($value < 0) || ($alpha <= 0) || ($beta <= 0)) { - return Functions::NAN(); + return ExcelError::NAN(); } if ($cumulative) { diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Percentiles.php b/src/PhpSpreadsheet/Calculation/Statistical/Percentiles.php index 16cb06e8..99738232 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Percentiles.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Percentiles.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Percentiles { @@ -37,7 +38,7 @@ class Percentiles } if (($entry < 0) || ($entry > 1)) { - return Functions::NAN(); + return ExcelError::NAN(); } $mArgs = self::percentileFilterValues($aArgs); @@ -56,7 +57,7 @@ class Percentiles return $mArgs[$iBase] + (($mArgs[$iNext] - $mArgs[$iBase]) * $iProportion); } - return Functions::NAN(); + return ExcelError::NAN(); } /** @@ -89,13 +90,13 @@ class Percentiles $valueSet = self::rankFilterValues($valueSet); $valueCount = count($valueSet); if ($valueCount == 0) { - return Functions::NA(); + return ExcelError::NA(); } sort($valueSet, SORT_NUMERIC); $valueAdjustor = $valueCount - 1; if (($value < $valueSet[0]) || ($value > $valueSet[$valueAdjustor])) { - return Functions::NA(); + return ExcelError::NA(); } $pos = array_search($value, $valueSet); @@ -138,7 +139,7 @@ class Percentiles $entry = floor($entry); $entry /= 4; if (($entry < 0) || ($entry > 1)) { - return Functions::NAN(); + return ExcelError::NAN(); } return self::PERCENTILE($aArgs, $entry); @@ -177,7 +178,7 @@ class Percentiles $pos = array_search($value, $valueSet); if ($pos === false) { - return Functions::NA(); + return ExcelError::NA(); } return ++$pos; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Permutations.php b/src/PhpSpreadsheet/Calculation/Statistical/Permutations.php index 7696878e..5d9d3048 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Permutations.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Permutations.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Shared\IntOrFloat; @@ -44,7 +44,7 @@ class Permutations } if ($numObjs < $numInSet) { - return Functions::NAN(); + return ExcelError::NAN(); } $result = round(MathTrig\Factorial::fact($numObjs) / MathTrig\Factorial::fact($numObjs - $numInSet)); @@ -80,7 +80,7 @@ class Permutations } if ($numObjs < 0 || $numInSet < 0) { - return Functions::NAN(); + return ExcelError::NAN(); } $result = $numObjs ** $numInSet; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Size.php b/src/PhpSpreadsheet/Calculation/Statistical/Size.php index de4b6d6c..dbffed5d 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Size.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Size.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Size { @@ -31,14 +32,14 @@ class Size $count = Counts::COUNT($mArgs); --$entry; if (($entry < 0) || ($entry >= $count) || ($count == 0)) { - return Functions::NAN(); + return ExcelError::NAN(); } rsort($mArgs); return $mArgs[$entry]; } - return Functions::VALUE(); + return ExcelError::VALUE(); } /** @@ -67,14 +68,14 @@ class Size $count = Counts::COUNT($mArgs); --$entry; if (($entry < 0) || ($entry >= $count) || ($count == 0)) { - return Functions::NAN(); + return ExcelError::NAN(); } sort($mArgs); return $mArgs[$entry]; } - return Functions::VALUE(); + return ExcelError::VALUE(); } /** diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Standardize.php b/src/PhpSpreadsheet/Calculation/Statistical/Standardize.php index 13240cc2..51b0a518 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Standardize.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Standardize.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Standardize extends StatisticalValidations { @@ -41,7 +41,7 @@ class Standardize extends StatisticalValidations } if ($stdDev <= 0) { - return Functions::NAN(); + return ExcelError::NAN(); } return ($value - $mean) / $stdDev; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/StatisticalValidations.php b/src/PhpSpreadsheet/Calculation/Statistical/StatisticalValidations.php index 5b315da4..e23a52cc 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/StatisticalValidations.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/StatisticalValidations.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class StatisticalValidations { @@ -13,7 +13,7 @@ class StatisticalValidations public static function validateFloat($value): float { if (!is_numeric($value)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (float) $value; @@ -25,7 +25,7 @@ class StatisticalValidations public static function validateInt($value): int { if (!is_numeric($value)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (int) floor((float) $value); @@ -37,7 +37,7 @@ class StatisticalValidations public static function validateBool($value): bool { if (!is_bool($value) && !is_numeric($value)) { - throw new Exception(Functions::VALUE()); + throw new Exception(ExcelError::VALUE()); } return (bool) $value; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Trends.php b/src/PhpSpreadsheet/Calculation/Statistical/Trends.php index a43926fa..af73519e 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Trends.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Trends.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\Trend\Trend; class Trends @@ -46,9 +47,9 @@ class Trends $xValueCount = count($xValues); if (($yValueCount === 0) || ($yValueCount !== $xValueCount)) { - throw new Exception(Functions::NA()); + throw new Exception(ExcelError::NA()); } elseif ($yValueCount === 1) { - throw new Exception(Functions::DIV0()); + throw new Exception(ExcelError::DIV0()); } } @@ -65,7 +66,7 @@ class Trends public static function CORREL($yValues, $xValues = null) { if (($xValues === null) || (!is_array($yValues)) || (!is_array($xValues))) { - return Functions::VALUE(); + return ExcelError::VALUE(); } try { @@ -232,7 +233,7 @@ class Trends ], [ $bestFitLinear->getSlopeSE(), - ($const === false) ? Functions::NA() : $bestFitLinear->getIntersectSE(), + ($const === false) ? ExcelError::NA() : $bestFitLinear->getIntersectSE(), ], [ $bestFitLinear->getGoodnessOfFit(), @@ -285,7 +286,7 @@ class Trends foreach ($yValues as $value) { if ($value < 0.0) { - return Functions::NAN(); + return ExcelError::NAN(); } } @@ -299,7 +300,7 @@ class Trends ], [ $bestFitExponential->getSlopeSE(), - ($const === false) ? Functions::NA() : $bestFitExponential->getIntersectSE(), + ($const === false) ? ExcelError::NA() : $bestFitExponential->getIntersectSE(), ], [ $bestFitExponential->getGoodnessOfFit(), diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Variances.php b/src/PhpSpreadsheet/Calculation/Statistical/Variances.php index ac9c3320..35d01d1c 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Variances.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Variances.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Variances extends VarianceBase { @@ -20,7 +21,7 @@ class Variances extends VarianceBase */ public static function VAR(...$args) { - $returnValue = Functions::DIV0(); + $returnValue = ExcelError::DIV0(); $summerA = $summerB = 0.0; @@ -62,7 +63,7 @@ class Variances extends VarianceBase */ public static function VARA(...$args) { - $returnValue = Functions::DIV0(); + $returnValue = ExcelError::DIV0(); $summerA = $summerB = 0.0; @@ -71,7 +72,7 @@ class Variances extends VarianceBase $aCount = 0; foreach ($aArgs as $k => $arg) { if ((is_string($arg)) && (Functions::isValue($k))) { - return Functions::VALUE(); + return ExcelError::VALUE(); } elseif ((is_string($arg)) && (!Functions::isMatrixValue($k))) { } else { // Is it a numeric value? @@ -109,7 +110,7 @@ class Variances extends VarianceBase public static function VARP(...$args) { // Return value - $returnValue = Functions::DIV0(); + $returnValue = ExcelError::DIV0(); $summerA = $summerB = 0.0; @@ -151,7 +152,7 @@ class Variances extends VarianceBase */ public static function VARPA(...$args) { - $returnValue = Functions::DIV0(); + $returnValue = ExcelError::DIV0(); $summerA = $summerB = 0.0; @@ -160,7 +161,7 @@ class Variances extends VarianceBase $aCount = 0; foreach ($aArgs as $k => $arg) { if ((is_string($arg)) && (Functions::isValue($k))) { - return Functions::VALUE(); + return ExcelError::VALUE(); } elseif ((is_string($arg)) && (!Functions::isMatrixValue($k))) { } else { // Is it a numeric value? diff --git a/src/PhpSpreadsheet/Calculation/TextData/CharacterConvert.php b/src/PhpSpreadsheet/Calculation/TextData/CharacterConvert.php index 714d789e..83af499b 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/CharacterConvert.php +++ b/src/PhpSpreadsheet/Calculation/TextData/CharacterConvert.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class CharacterConvert { @@ -28,7 +29,7 @@ class CharacterConvert $character = Helpers::validateInt($character); $min = Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE ? 0 : 1; if ($character < $min || $character > 255) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $result = iconv('UCS-4LE', 'UTF-8', pack('V', $character)); @@ -53,7 +54,7 @@ class CharacterConvert $characters = Helpers::extractString($characters); if ($characters === '') { - return Functions::VALUE(); + return ExcelError::VALUE(); } $character = $characters; diff --git a/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php b/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php index f23996a6..4413b4a4 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Concatenate { @@ -89,7 +90,7 @@ class Concatenate $stringValue = Helpers::extractString($stringValue); if (!is_numeric($repeatCount) || $repeatCount < 0) { - return Functions::VALUE(); + return ExcelError::VALUE(); } return str_repeat($stringValue, (int) $repeatCount); diff --git a/src/PhpSpreadsheet/Calculation/TextData/Format.php b/src/PhpSpreadsheet/Calculation/TextData/Format.php index b4b634fb..bec11496 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Format.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Format.php @@ -7,6 +7,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; @@ -144,7 +145,7 @@ class Format if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) { $value = (int) $value; } else { - throw new CalcExp(Functions::VALUE()); + throw new CalcExp(ExcelError::VALUE()); } } @@ -187,21 +188,21 @@ class Format if (strpos($value, ':') !== false) { $timeValue = Functions::scalar(DateTimeExcel\TimeValue::fromString($value)); - if ($timeValue !== Functions::VALUE()) { + if ($timeValue !== ExcelError::VALUE()) { Functions::setReturnDateType($dateSetting); return $timeValue; } } $dateValue = Functions::scalar(DateTimeExcel\DateValue::fromString($value)); - if ($dateValue !== Functions::VALUE()) { + if ($dateValue !== ExcelError::VALUE()) { Functions::setReturnDateType($dateSetting); return $dateValue; } Functions::setReturnDateType($dateSetting); - return Functions::VALUE(); + return ExcelError::VALUE(); } return (float) $value; @@ -252,11 +253,11 @@ class Format if (!is_numeric($value)) { $decimalPositions = preg_match_all('/' . preg_quote($decimalSeparator) . '/', $value, $matches, PREG_OFFSET_CAPTURE); if ($decimalPositions > 1) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $decimalOffset = array_pop($matches[0])[1]; if (strpos($value, $groupSeparator, $decimalOffset) !== false) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $value = str_replace([$groupSeparator, $decimalSeparator], ['', '.'], $value); @@ -264,7 +265,7 @@ class Format // Handle the special case of trailing % signs $percentageString = rtrim($value, '%'); if (!is_numeric($percentageString)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } $percentageAdjustment = strlen($value) - strlen($percentageString); @@ -274,6 +275,6 @@ class Format } } - return is_array($value) ? Functions::VALUE() : (float) $value; + return is_array($value) ? ExcelError::VALUE() : (float) $value; } } diff --git a/src/PhpSpreadsheet/Calculation/TextData/Helpers.php b/src/PhpSpreadsheet/Calculation/TextData/Helpers.php index 86c405ab..0fdf6af8 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Helpers.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Helpers.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Helpers { @@ -42,11 +43,11 @@ class Helpers $value = (int) $value; } if (!is_numeric($value)) { - throw new CalcExp(Functions::VALUE()); + throw new CalcExp(ExcelError::VALUE()); } $value = (int) $value; if ($value < $minValue) { - throw new CalcExp(Functions::VALUE()); + throw new CalcExp(ExcelError::VALUE()); } return (int) $value; @@ -64,7 +65,7 @@ class Helpers $value = (float) $value; } if (!is_numeric($value)) { - throw new CalcExp(Functions::VALUE()); + throw new CalcExp(ExcelError::VALUE()); } return (float) $value; diff --git a/src/PhpSpreadsheet/Calculation/TextData/Replace.php b/src/PhpSpreadsheet/Calculation/TextData/Replace.php index c3290a2a..a07ea104 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Replace.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Replace.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; class Replace { @@ -78,7 +79,7 @@ class Replace } if (is_bool($instance)) { if ($instance === false || Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) { - return Functions::Value(); + return ExcelError::Value(); } $instance = 1; } diff --git a/src/PhpSpreadsheet/Calculation/TextData/Search.php b/src/PhpSpreadsheet/Calculation/TextData/Search.php index b6a72380..10b6a1aa 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Search.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Search.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; class Search @@ -50,7 +50,7 @@ class Search } } - return Functions::VALUE(); + return ExcelError::VALUE(); } /** @@ -92,6 +92,6 @@ class Search } } - return Functions::VALUE(); + return ExcelError::VALUE(); } } diff --git a/src/PhpSpreadsheet/Calculation/Web/Service.php b/src/PhpSpreadsheet/Calculation/Web/Service.php index 05e04bf9..697d3a61 100644 --- a/src/PhpSpreadsheet/Calculation/Web/Service.php +++ b/src/PhpSpreadsheet/Calculation/Web/Service.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Web; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Settings; use Psr\Http\Client\ClientExceptionInterface; @@ -22,11 +22,11 @@ class Service { $url = trim($url); if (strlen($url) > 2048) { - return Functions::VALUE(); // Invalid URL length + return ExcelError::VALUE(); // Invalid URL length } if (!preg_match('/^http[s]?:\/\//', $url)) { - return Functions::VALUE(); // Invalid protocol + return ExcelError::VALUE(); // Invalid protocol } // Get results from the the webservice @@ -37,16 +37,16 @@ class Service try { $response = $client->sendRequest($request); } catch (ClientExceptionInterface $e) { - return Functions::VALUE(); // cURL error + return ExcelError::VALUE(); // cURL error } if ($response->getStatusCode() != 200) { - return Functions::VALUE(); // cURL error + return ExcelError::VALUE(); // cURL error } $output = $response->getBody()->getContents(); if (strlen($output) > 32767) { - return Functions::VALUE(); // Output not a string or too long + return ExcelError::VALUE(); // Output not a string or too long } return $output; @@ -67,7 +67,7 @@ class Service public static function urlEncode($text) { if (!is_string($text)) { - return Functions::VALUE(); + return ExcelError::VALUE(); } return str_replace('+', '%20', urlencode($text)); diff --git a/src/PhpSpreadsheet/Cell/Cell.php b/src/PhpSpreadsheet/Cell/Cell.php index fe4a1f41..70df0979 100644 --- a/src/PhpSpreadsheet/Cell/Cell.php +++ b/src/PhpSpreadsheet/Cell/Cell.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Cell; use DateTime; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Collection\Cells; use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\RichText\RichText; @@ -298,7 +299,7 @@ class Cell if (($ex->getMessage() === 'Unable to access External Workbook') && ($this->calculatedValue !== null)) { return $this->calculatedValue; // Fallback for calculations referencing external files. } elseif (preg_match('/[Uu]ndefined (name|offset: 2|array key 2)/', $ex->getMessage()) === 1) { - return \PhpOffice\PhpSpreadsheet\Calculation\Functions::NAME(); + return ExcelError::NAME(); } throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception( diff --git a/src/PhpSpreadsheet/Cell/DataValidator.php b/src/PhpSpreadsheet/Cell/DataValidator.php index 430d81b9..c1991ae0 100644 --- a/src/PhpSpreadsheet/Cell/DataValidator.php +++ b/src/PhpSpreadsheet/Cell/DataValidator.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Exception; /** @@ -65,7 +65,7 @@ class DataValidator try { $result = $calculation->calculateFormula($matchFormula, $cell->getCoordinate(), $cell); - return $result !== Functions::NA(); + return $result !== ExcelError::NA(); } catch (Exception $ex) { return false; } diff --git a/src/PhpSpreadsheet/Reader/Xlsx/Chart.php b/src/PhpSpreadsheet/Reader/Xlsx/Chart.php index 667e3674..a5635128 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx/Chart.php +++ b/src/PhpSpreadsheet/Reader/Xlsx/Chart.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Layout; @@ -414,7 +414,7 @@ class Chart $pointVal = self::getAttribute($seriesValue, 'idx', 'integer'); if ($dataType == 's') { $seriesVal[$pointVal] = (string) $seriesValue->v; - } elseif ($seriesValue->v === Functions::NA()) { + } elseif ($seriesValue->v === ExcelError::NA()) { $seriesVal[$pointVal] = null; } else { $seriesVal[$pointVal] = (float) $seriesValue->v; @@ -452,7 +452,7 @@ class Chart $pointVal = self::getAttribute($seriesValue, 'idx', 'integer'); if ($dataType == 's') { $seriesVal[$pointVal][] = (string) $seriesValue->v; - } elseif ($seriesValue->v === Functions::NA()) { + } elseif ($seriesValue->v === ExcelError::NA()) { $seriesVal[$pointVal] = null; } else { $seriesVal[$pointVal][] = (float) $seriesValue->v; diff --git a/src/PhpSpreadsheet/Shared/Date.php b/src/PhpSpreadsheet/Shared/Date.php index b4cf1913..b5c7c8fe 100644 --- a/src/PhpSpreadsheet/Shared/Date.php +++ b/src/PhpSpreadsheet/Shared/Date.php @@ -7,6 +7,7 @@ use DateTimeInterface; use DateTimeZone; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; @@ -454,13 +455,13 @@ class Date $dateValueNew = DateTimeExcel\DateValue::fromString($dateValue); - if ($dateValueNew === Functions::VALUE()) { + if ($dateValueNew === ExcelError::VALUE()) { return false; } if (strpos($dateValue, ':') !== false) { $timeValue = DateTimeExcel\TimeValue::fromString($dateValue); - if ($timeValue === Functions::VALUE()) { + if ($timeValue === ExcelError::VALUE()) { return false; } $dateValueNew += $timeValue; diff --git a/src/PhpSpreadsheet/Shared/JAMA/Matrix.php b/src/PhpSpreadsheet/Shared/JAMA/Matrix.php index adf399ac..a96d4cda 100644 --- a/src/PhpSpreadsheet/Shared/JAMA/Matrix.php +++ b/src/PhpSpreadsheet/Shared/JAMA/Matrix.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Shared\JAMA; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; /** @@ -543,7 +543,7 @@ class Matrix if ($validValues) { $this->A[$i][$j] += $value; } else { - $this->A[$i][$j] = Functions::NAN(); + $this->A[$i][$j] = ExcelError::NAN(); } } } @@ -643,7 +643,7 @@ class Matrix if ($validValues) { $this->A[$i][$j] -= $value; } else { - $this->A[$i][$j] = Functions::NAN(); + $this->A[$i][$j] = ExcelError::NAN(); } } } @@ -745,7 +745,7 @@ class Matrix if ($validValues) { $this->A[$i][$j] *= $value; } else { - $this->A[$i][$j] = Functions::NAN(); + $this->A[$i][$j] = ExcelError::NAN(); } } } @@ -808,7 +808,7 @@ class Matrix $M->set($i, $j, $this->A[$i][$j] / $value); } } else { - $M->set($i, $j, Functions::NAN()); + $M->set($i, $j, ExcelError::NAN()); } } } @@ -1090,7 +1090,7 @@ class Matrix if ($validValues) { $this->A[$i][$j] = $this->A[$i][$j] ** $value; } else { - $this->A[$i][$j] = Functions::NAN(); + $this->A[$i][$j] = ExcelError::NAN(); } } } diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php index ab390a90..2028fa30 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\RichText\RichText; @@ -1250,7 +1251,7 @@ class Worksheet extends WriterPart { $calculatedValue = $this->getParentWriter()->getPreCalculateFormulas() ? $cell->getCalculatedValue() : $cellValue; if (is_string($calculatedValue)) { - if (\PhpOffice\PhpSpreadsheet\Calculation\Functions::isError($calculatedValue)) { + if (Value::isError($calculatedValue)) { $this->writeCellError($objWriter, 'e', $cellValue, $calculatedValue); return; diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DGetTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DGetTest.php index 565588fc..6df9c1bd 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DGetTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DGetTest.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\TestCase; class DGetTest extends TestCase @@ -67,7 +68,7 @@ class DGetTest extends TestCase { return [ [ - Functions::NAN(), + ExcelError::NAN(), $this->database1(), 'Yield', [ @@ -96,7 +97,7 @@ class DGetTest extends TestCase ], ], [ - Functions::NAN(), + ExcelError::NAN(), $this->database2(), 'Sales', [ diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DeprecatedExcelErrorTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DeprecatedExcelErrorTest.php new file mode 100644 index 00000000..48a3dcf0 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DeprecatedExcelErrorTest.php @@ -0,0 +1,55 @@ + [ + [Functions::class, 'null'], + ExcelError::null(), + ], + 'NAN' => [ + [Functions::class, 'NAN'], + ExcelError::NAN(), + ], + 'NA' => [ + [Functions::class, 'NA'], + ExcelError::NA(), + ], + 'NAME' => [ + [Functions::class, 'NAME'], + ExcelError::NAME(), + ], + 'REF' => [ + [Functions::class, 'REF'], + ExcelError::REF(), + ], + 'VALUE' => [ + [Functions::class, 'VALUE'], + ExcelError::VALUE(), + ], + 'DIV0' => [ + [Functions::class, 'DIV0'], + ExcelError::DIV0(), + ], + ]; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HyperlinkTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HyperlinkTest.php index 0aef51de..328cc2fa 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HyperlinkTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HyperlinkTest.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\LookupRef; class HyperlinkTest extends AllSetupTeardown @@ -97,6 +97,6 @@ class HyperlinkTest extends AllSetupTeardown public function testHYPERLINKwithoutCell(): void { $result = LookupRef\Hyperlink::set('https://phpspreadsheet.readthedocs.io/en/latest/', 'Read the Docs'); - self::assertSame(Functions::REF(), $result); + self::assertSame(ExcelError::REF(), $result); } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/MovedFunctionsTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/MovedFunctionsTest.php index e69af7d9..007ce1d2 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/MovedFunctionsTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/MovedFunctionsTest.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PHPUnit\Framework\TestCase; @@ -19,8 +20,8 @@ class MovedFunctionsTest extends TestCase public function testMovedFunctions(): void { self::assertSame(3, LookupRef::COLUMN('C5')); - self::assertSame(Functions::REF(), LookupRef::FORMULATEXT('A1')); - self::assertSame(Functions::REF(), LookupRef::HYPERLINK('https://phpspreadsheet.readthedocs.io/en/latest/', 'Read the Docs')); + self::assertSame(ExcelError::REF(), LookupRef::FORMULATEXT('A1')); + self::assertSame(ExcelError::REF(), LookupRef::HYPERLINK('https://phpspreadsheet.readthedocs.io/en/latest/', 'Read the Docs')); self::assertSame('#VALUE!', LookupRef::OFFSET(null)); self::assertSame(5, LookupRef::ROW('C5')); self::assertSame([[1, 2], [3, 4]], LookupRef::TRANSPOSE([[1, 3], [2, 4]])); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandArrayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandArrayTest.php index ad142fb1..6e63e5ca 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandArrayTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandArrayTest.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; class RandArrayTest extends AllSetupTeardown @@ -61,7 +62,7 @@ class RandArrayTest extends AllSetupTeardown $max = -2; $result = MathTrig\Random::randArray($rows, $cols, $min, $max, false); - self::assertSame(Functions::VALUE(), $result); + self::assertSame(ExcelError::VALUE(), $result); $rows = 3; $cols = 2; @@ -69,6 +70,6 @@ class RandArrayTest extends AllSetupTeardown $max = -2; $result = MathTrig\Random::randArray($rows, $cols, $min, $max, false); - self::assertSame(Functions::VALUE(), $result); + self::assertSame(ExcelError::VALUE(), $result); } } diff --git a/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php b/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php index c03167ca..0f518ea5 100644 --- a/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\TestCase; class FunctionsTest extends TestCase @@ -75,31 +76,31 @@ class FunctionsTest extends TestCase public function testDIV0(): void { - $result = Functions::DIV0(); + $result = ExcelError::DIV0(); self::assertEquals('#DIV/0!', $result); } public function testNA(): void { - $result = Functions::NA(); + $result = ExcelError::NA(); self::assertEquals('#N/A', $result); } public function testNAN(): void { - $result = Functions::NAN(); + $result = ExcelError::NAN(); self::assertEquals('#NUM!', $result); } public function testNAME(): void { - $result = Functions::NAME(); + $result = ExcelError::NAME(); self::assertEquals('#NAME?', $result); } public function testREF(): void { - $result = Functions::REF(); + $result = ExcelError::REF(); self::assertEquals('#REF!', $result); } @@ -111,7 +112,7 @@ class FunctionsTest extends TestCase public function testVALUE(): void { - $result = Functions::VALUE(); + $result = ExcelError::VALUE(); self::assertEquals('#VALUE!', $result); } @@ -338,4 +339,17 @@ class FunctionsTest extends TestCase { return require 'tests/data/Calculation/Functions/IF_CONDITION.php'; } + + public function testDeprecatedIsFormula(): void + { + $result = Functions::isFormula('="STRING"'); + self::assertEquals(ExcelError::REF(), $result); + } + + public function testScalar(): void + { + $value = 'scalar'; + $result = Functions::scalar([[$value]]); + self::assertSame($value, $result); + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/MergedCellTest.php b/tests/PhpSpreadsheetTests/Calculation/MergedCellTest.php index f6e98474..5e5aff6a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/MergedCellTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/MergedCellTest.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Exception as SpreadException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; @@ -47,7 +47,7 @@ class MergedCellTest extends TestCase ['=COUNTA(A1:A5)', 3], ['=SUM(A3:A4)', 0], ['=A2+A3+A4', 2.2], - ['=A2/A3', Functions::DIV0()], + ['=A2/A3', ExcelError::DIV0()], ['=SUM(B1:C2)', 8.8], ]; } @@ -89,7 +89,7 @@ class MergedCellTest extends TestCase ['=COUNTA(A1:E1)', 3], ['=SUM(C1:D1)', 0], ['=B1+C1+D1', 2.2], - ['=B1/C1', Functions::DIV0()], + ['=B1/C1', ExcelError::DIV0()], ['=SUM(A2:B3)', 8.8], ]; } diff --git a/tests/data/Calculation/Engineering/COMPLEX.php b/tests/data/Calculation/Engineering/COMPLEX.php index 22e21a8f..ee27db85 100644 --- a/tests/data/Calculation/Engineering/COMPLEX.php +++ b/tests/data/Calculation/Engineering/COMPLEX.php @@ -1,6 +1,6 @@