Extract information functions (#2605)

* Split Information functions into a dedicated class and namespace and categorise as Value or Error
* Refactor all error functions into the new ExcelError class
This commit is contained in:
Mark Baker 2022-02-19 13:53:17 +01:00 committed by GitHub
parent 9c473682bc
commit d5dc58d20e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
167 changed files with 1365 additions and 831 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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());
}
}
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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'];

View File

@ -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];

View File

@ -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();
}
/**

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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());
}
/**

View File

@ -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();

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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();
}
/**

View File

@ -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();
}
//

View File

@ -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;

View File

@ -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) /

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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());
}
}
}

View File

@ -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();
}
/**

View File

@ -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());
}
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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();
}
/**

View File

@ -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

View File

@ -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)) {

View File

@ -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));

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -0,0 +1,132 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Information;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class ExcelError
{
/**
* List of error codes.
*
* @var array
*/
public static $errorCodes = [
'null' => '#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'];
}
}

View File

@ -0,0 +1,291 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Information;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
class Value
{
/**
* IS_BLANK.
*
* @param mixed $value Value to check
*
* @return bool
*/
public static function isBlank($value = null)
{
if ($value !== null) {
$value = Functions::flattenSingleValue($value);
}
return $value === null;
}
/**
* IS_EVEN.
*
* @param mixed $value Value to check
*
* @return bool|string
*/
public static function isEven($value = null)
{
$value = Functions::flattenSingleValue($value);
if ($value === null) {
return ExcelError::NAME();
} elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) {
return ExcelError::VALUE();
}
return $value % 2 == 0;
}
/**
* IS_ODD.
*
* @param mixed $value Value to check
*
* @return bool|string
*/
public static function isOdd($value = null)
{
$value = Functions::flattenSingleValue($value);
if ($value === null) {
return ExcelError::NAME();
} elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) {
return ExcelError::VALUE();
}
return abs($value) % 2 == 1;
}
/**
* IS_NUMBER.
*
* @param mixed $value Value to check
*
* @return bool
*/
public static function isNumber($value = null)
{
$value = Functions::flattenSingleValue($value);
if (is_string($value)) {
return false;
}
return is_numeric($value);
}
/**
* IS_LOGICAL.
*
* @param mixed $value Value to check
*
* @return bool
*/
public static function isLogical($value = null)
{
$value = Functions::flattenSingleValue($value);
return is_bool($value);
}
/**
* IS_TEXT.
*
* @param mixed $value Value to check
*
* @return bool
*/
public static function isText($value = null)
{
$value = Functions::flattenSingleValue($value);
return is_string($value) && !self::isError($value);
}
/**
* IS_NONTEXT.
*
* @param mixed $value Value to check
*
* @return bool
*/
public static function isNonText($value = null)
{
return !self::isText($value);
}
/**
* ISFORMULA.
*
* @param mixed $cellReference The cell to check
* @param ?Cell $cell The current cell (containing this formula)
*
* @return bool|string
*/
public static function isFormula($cellReference = '', ?Cell $cell = null)
{
if ($cell === null) {
return ExcelError::REF();
}
$cellReference = Functions::expandDefinedName((string) $cellReference, $cell);
$cellReference = Functions::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 !== 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;
}
}

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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)) {

View File

@ -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();

View File

@ -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();
}
/**

View File

@ -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) == '') {

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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])) {

View File

@ -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)

View File

@ -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) {

View File

@ -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();
}
}

View File

@ -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

View File

@ -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();
}
}

View File

@ -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 {

View File

@ -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;
}
}

View File

@ -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());
}
}
}

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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();

View File

@ -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);
}
/**

View File

@ -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();
}
/**

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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));

View File

@ -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();
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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];
}

View File

@ -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;

View File

@ -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) {

View File

@ -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) {

View File

@ -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));

View File

@ -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));

View File

@ -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;

View File

@ -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);

View File

@ -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));

Some files were not shown because too many files have changed in this diff Show More