More grouping and renaming

This commit is contained in:
MarkBaker 2021-05-14 12:43:52 +02:00 committed by Mark Baker
parent fb251eb6ab
commit 5173eaa302
10 changed files with 182 additions and 214 deletions

View File

@ -838,7 +838,7 @@ class Calculation
],
'DEGREES' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Degrees::class, 'evaluate'],
'functionCall' => [MathTrig\Angle::class, 'toDegrees'],
'argumentCount' => '1',
],
'DELTA' => [
@ -1704,7 +1704,7 @@ class Calculation
],
'MOD' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Mod::class, 'evaluate'],
'functionCall' => [MathTrig\Operations::class, 'mod'],
'argumentCount' => '2',
],
'MODE' => [
@ -1976,7 +1976,7 @@ class Calculation
],
'POWER' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Power::class, 'evaluate'],
'functionCall' => [MathTrig\Operations::class, 'power'],
'argumentCount' => '2',
],
'PPMT' => [
@ -2006,7 +2006,7 @@ class Calculation
],
'PRODUCT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Product::class, 'evaluate'],
'functionCall' => [MathTrig\Operations::class, 'product'],
'argumentCount' => '1+',
],
'PROPER' => [
@ -2036,12 +2036,12 @@ class Calculation
],
'QUOTIENT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Quotient::class, 'evaluate'],
'functionCall' => [MathTrig\Operations::class, 'quotient'],
'argumentCount' => '2',
],
'RADIANS' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Radians::class, 'evaluate'],
'functionCall' => [MathTrig\Angle::class, 'toRadians'],
'argumentCount' => '1',
],
'RAND' => [

View File

@ -449,8 +449,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @see MathTrig\Mod::evaluate()
* Use the evaluate() method in the MathTrig\Mod class instead
* @see MathTrig\Operations::mod()
* Use the mod() method in the MathTrig\Operations class instead
*
* @param int $a Dividend
* @param int $b Divisor
@ -459,7 +459,7 @@ class MathTrig
*/
public static function MOD($a = 1, $b = 1)
{
return MathTrig\Mod::evaluate($a, $b);
return MathTrig\Operations::mod($a, $b);
}
/**
@ -527,7 +527,7 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Power::evaluate()
* @See MathTrig\Operations::power()
* Use the evaluate method in the MathTrig\Power class instead
*
* @param float $x
@ -537,7 +537,7 @@ class MathTrig
*/
public static function POWER($x = 0, $y = 2)
{
return MathTrig\Power::evaluate($x, $y);
return MathTrig\Operations::power($x, $y);
}
/**
@ -547,8 +547,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Product::evaluate()
* Use the evaluate method in the MathTrig\Product class instead
* @See MathTrig\Operations::product()
* Use the product method in the MathTrig\Operations class instead
*
* Excel Function:
* PRODUCT(value1[,value2[, ...]])
@ -559,7 +559,7 @@ class MathTrig
*/
public static function PRODUCT(...$args)
{
return MathTrig\Product::evaluate(...$args);
return MathTrig\Operations::product(...$args);
}
/**
@ -570,8 +570,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Quotient::evaluate()
* Use the evaluate method in the MathTrig\Quotient class instead
* @See MathTrig\Operations::quotient()
* Use the quotient method in the MathTrig\Operations class instead
*
* Excel Function:
* QUOTIENT(value1[,value2[, ...]])
@ -583,7 +583,7 @@ class MathTrig
*/
public static function QUOTIENT($numerator, $denominator)
{
return MathTrig\Quotient::evaluate($numerator, $denominator);
return MathTrig\Operations::quotient($numerator, $denominator);
}
/**
@ -1315,8 +1315,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Degrees::evaluate()
* Use the evaluate method in the MathTrig\Degrees class instead
* @See MathTrig\Angle::toDegrees()
* Use the toDegrees method in the MathTrig\Angle class instead
*
* @param mixed $number Should be numeric
*
@ -1324,7 +1324,7 @@ class MathTrig
*/
public static function builtinDEGREES($number)
{
return MathTrig\Degrees::evaluate($number);
return MathTrig\Angle::toDegrees($number);
}
/**
@ -1391,8 +1391,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Radians::evaluate()
* Use the evaluate method in the MathTrig\Radians class instead
* @See MathTrig\Angle::toRadians()
* Use the toRadians method in the MathTrig\Angle class instead
*
* @param mixed $number Should be numeric
*
@ -1400,7 +1400,7 @@ class MathTrig
*/
public static function builtinRADIANS($number)
{
return MathTrig\Radians::evaluate($number);
return MathTrig\Angle::toRadians($number);
}
/**

View File

@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Degrees
class Angle
{
/**
* DEGREES.
@ -15,7 +15,7 @@ class Degrees
*
* @return float|string Rounded number
*/
public static function evaluate($number)
public static function toDegrees($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
@ -25,4 +25,24 @@ class Degrees
return rad2deg($number);
}
/**
* RADIANS.
*
* Returns the result of builtin function deg2rad after validating args.
*
* @param mixed $number Should be numeric
*
* @return float|string Rounded number
*/
public static function toRadians($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return deg2rad($number);
}
}

View File

@ -1,36 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Mod
{
/**
* MOD.
*
* @param mixed $dividend Dividend
* @param mixed $divisor Divisor
*
* @return float|int|string Remainder, or a string containing an error
*/
public static function evaluate($dividend, $divisor)
{
try {
$dividend = Helpers::validateNumericNullBool($dividend);
$divisor = Helpers::validateNumericNullBool($divisor);
Helpers::validateNotZero($divisor);
} catch (Exception $e) {
return $e->getMessage();
}
if (($dividend < 0.0) && ($divisor > 0.0)) {
return $divisor - fmod(abs($dividend), $divisor);
}
if (($dividend > 0.0) && ($divisor < 0.0)) {
return $divisor + fmod($dividend, abs($divisor));
}
return fmod($dividend, $divisor);
}
}

View File

@ -0,0 +1,136 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Operations
{
/**
* MOD.
*
* @param mixed $dividend Dividend
* @param mixed $divisor Divisor
*
* @return float|int|string Remainder, or a string containing an error
*/
public static function mod($dividend, $divisor)
{
try {
$dividend = Helpers::validateNumericNullBool($dividend);
$divisor = Helpers::validateNumericNullBool($divisor);
Helpers::validateNotZero($divisor);
} catch (Exception $e) {
return $e->getMessage();
}
if (($dividend < 0.0) && ($divisor > 0.0)) {
return $divisor - fmod(abs($dividend), $divisor);
}
if (($dividend > 0.0) && ($divisor < 0.0)) {
return $divisor + fmod($dividend, abs($divisor));
}
return fmod($dividend, $divisor);
}
/**
* POWER.
*
* Computes x raised to the power y.
*
* @param float|int $x
* @param float|int $y
*
* @return float|int|string The result, or a string containing an error
*/
public static function power($x, $y)
{
try {
$x = Helpers::validateNumericNullBool($x);
$y = Helpers::validateNumericNullBool($y);
} catch (Exception $e) {
return $e->getMessage();
}
// Validate parameters
if (!$x && !$y) {
return Functions::NAN();
}
if (!$x && $y < 0.0) {
return Functions::DIV0();
}
// Return
$result = $x ** $y;
return Helpers::numberOrNan($result);
}
/**
* PRODUCT.
*
* PRODUCT returns the product of all the values and cells referenced in the argument list.
*
* Excel Function:
* PRODUCT(value1[,value2[, ...]])
*
* @param mixed ...$args Data values
*
* @return float|string
*/
public static function product(...$args)
{
// Return value
$returnValue = null;
// Loop through arguments
foreach (Functions::flattenArray($args) as $arg) {
// Is it a numeric value?
if (is_numeric($arg)) {
if ($returnValue === null) {
$returnValue = $arg;
} else {
$returnValue *= $arg;
}
} else {
return Functions::VALUE();
}
}
// Return
if ($returnValue === null) {
return 0;
}
return $returnValue;
}
/**
* QUOTIENT.
*
* QUOTIENT function returns the integer portion of a division. Numerator is the divided number
* and denominator is the divisor.
*
* Excel Function:
* QUOTIENT(value1,value2)
*
* @param mixed $numerator Expect float|int
* @param mixed $denominator Expect float|int
*
* @return int|string
*/
public static function quotient($numerator, $denominator)
{
try {
$numerator = Helpers::validateNumericNullSubstitution($numerator, 0);
$denominator = Helpers::validateNumericNullSubstitution($denominator, 0);
Helpers::validateNotZero($denominator);
} catch (Exception $e) {
return $e->getMessage();
}
return (int) ($numerator / $denominator);
}
}

View File

@ -1,42 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Power
{
/**
* POWER.
*
* Computes x raised to the power y.
*
* @param float|int $x
* @param float|int $y
*
* @return float|int|string The result, or a string containing an error
*/
public static function evaluate($x, $y)
{
try {
$x = Helpers::validateNumericNullBool($x);
$y = Helpers::validateNumericNullBool($y);
} catch (Exception $e) {
return $e->getMessage();
}
// Validate parameters
if (!$x && !$y) {
return Functions::NAN();
}
if (!$x && $y < 0.0) {
return Functions::DIV0();
}
// Return
$result = $x ** $y;
return Helpers::numberOrNan($result);
}
}

View File

@ -1,47 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Product
{
/**
* PRODUCT.
*
* PRODUCT returns the product of all the values and cells referenced in the argument list.
*
* Excel Function:
* PRODUCT(value1[,value2[, ...]])
*
* @param mixed ...$args Data values
*
* @return float|string
*/
public static function evaluate(...$args)
{
// Return value
$returnValue = null;
// Loop through arguments
foreach (Functions::flattenArray($args) as $arg) {
// Is it a numeric value?
if (is_numeric($arg)) {
if ($returnValue === null) {
$returnValue = $arg;
} else {
$returnValue *= $arg;
}
} else {
return Functions::VALUE();
}
}
// Return
if ($returnValue === null) {
return 0;
}
return $returnValue;
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Quotient
{
/**
* QUOTIENT.
*
* QUOTIENT function returns the integer portion of a division. Numerator is the divided number
* and denominator is the divisor.
*
* Excel Function:
* QUOTIENT(value1,value2)
*
* @param mixed $numerator Expect float|int
* @param mixed $denominator Expect float|int
*
* @return int|string
*/
public static function evaluate($numerator, $denominator)
{
try {
$numerator = Helpers::validateNumericNullSubstitution($numerator, 0);
$denominator = Helpers::validateNumericNullSubstitution($denominator, 0);
Helpers::validateNotZero($denominator);
} catch (Exception $e) {
return $e->getMessage();
}
return (int) ($numerator / $denominator);
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Radians
{
/**
* RADIANS.
*
* Returns the result of builtin function deg2rad after validating args.
*
* @param mixed $number Should be numeric
*
* @return float|string Rounded number
*/
public static function evaluate($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return deg2rad($number);
}
}

View File

@ -57,7 +57,7 @@ class Subtotal
[Statistical\Counts::class, 'COUNTA'], // 3
[Statistical\Maximum::class, 'MAX'], // 4
[Statistical\Minimum::class, 'MIN'], // 5
[Product::class, 'evaluate'], // 6
[Operations::class, 'product'], // 6
[Statistical\StandardDeviations::class, 'STDEV'], // 7
[Statistical\StandardDeviations::class, 'STDEVP'], // 8
[Sum::class, 'sumIgnoringStrings'], // 9