Skip to content

Converting Engineering functions to be array-enabled #2594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Calculation/Engine/Logger.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\:\\:BITLSHIFT\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Engineering.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\:\\:BITRSHIFT\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Engineering.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselJ\\:\\:besselj2a\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
54 changes: 27 additions & 27 deletions src/PhpSpreadsheet/Calculation/Engineering.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function parseComplex($complexNumber)
* If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
* If $ord < 0, BESSELI returns the #NUM! error value.
*
* @return float|string Result, or a string containing an error
* @return array|float|string Result, or a string containing an error
*/
public static function BESSELI($x, $ord)
{
Expand All @@ -86,7 +86,7 @@ public static function BESSELI($x, $ord)
* If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
* If $ord < 0, BESSELJ returns the #NUM! error value.
*
* @return float|string Result, or a string containing an error
* @return array|float|string Result, or a string containing an error
*/
public static function BESSELJ($x, $ord)
{
Expand All @@ -112,7 +112,7 @@ public static function BESSELJ($x, $ord)
* If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
* If $ord < 0, BESSELK returns the #NUM! error value.
*
* @return float|string Result, or a string containing an error
* @return array|float|string Result, or a string containing an error
*/
public static function BESSELK($x, $ord)
{
Expand All @@ -137,7 +137,7 @@ public static function BESSELK($x, $ord)
* If $ord is nonnumeric, BESSELY returns the #VALUE! error value.
* If $ord < 0, BESSELY returns the #NUM! error value.
*
* @return float|string Result, or a string containing an error
* @return array|float|string Result, or a string containing an error
*/
public static function BESSELY($x, $ord)
{
Expand All @@ -163,7 +163,7 @@ public static function BESSELY($x, $ord)
* If number is not a valid binary number, or if number contains more than
* 10 characters (10 bits), BIN2DEC returns the #NUM! error value.
*
* @return string
* @return array|string
*/
public static function BINTODEC($x)
{
Expand Down Expand Up @@ -195,7 +195,7 @@ public static function BINTODEC($x)
* If places is nonnumeric, BIN2HEX returns the #VALUE! error value.
* If places is negative, BIN2HEX returns the #NUM! error value.
*
* @return string
* @return array|string
*/
public static function BINTOHEX($x, $places = null)
{
Expand Down Expand Up @@ -227,7 +227,7 @@ public static function BINTOHEX($x, $places = null)
* If places is nonnumeric, BIN2OCT returns the #VALUE! error value.
* If places is negative, BIN2OCT returns the #NUM! error value.
*
* @return string
* @return array|string
*/
public static function BINTOOCT($x, $places = null)
{
Expand Down Expand Up @@ -263,7 +263,7 @@ public static function BINTOOCT($x, $places = null)
* If places is nonnumeric, DEC2BIN returns the #VALUE! error value.
* If places is zero or negative, DEC2BIN returns the #NUM! error value.
*
* @return string
* @return array|string
*/
public static function DECTOBIN($x, $places = null)
{
Expand Down Expand Up @@ -299,7 +299,7 @@ public static function DECTOBIN($x, $places = null)
* If places is nonnumeric, DEC2HEX returns the #VALUE! error value.
* If places is zero or negative, DEC2HEX returns the #NUM! error value.
*
* @return string
* @return array|string
*/
public static function DECTOHEX($x, $places = null)
{
Expand Down Expand Up @@ -335,7 +335,7 @@ public static function DECTOHEX($x, $places = null)
* If places is nonnumeric, DEC2OCT returns the #VALUE! error value.
* If places is zero or negative, DEC2OCT returns the #NUM! error value.
*
* @return string
* @return array|string
*/
public static function DECTOOCT($x, $places = null)
{
Expand Down Expand Up @@ -371,7 +371,7 @@ public static function DECTOOCT($x, $places = null)
* If places is nonnumeric, HEX2BIN returns the #VALUE! error value.
* If places is negative, HEX2BIN returns the #NUM! error value.
*
* @return string
* @return array|string
*/
public static function HEXTOBIN($x, $places = null)
{
Expand All @@ -398,7 +398,7 @@ public static function HEXTOBIN($x, $places = null)
* If number is not a valid hexadecimal number, HEX2DEC returns the
* #NUM! error value.
*
* @return string
* @return array|string
*/
public static function HEXTODEC($x)
{
Expand Down Expand Up @@ -438,7 +438,7 @@ public static function HEXTODEC($x)
* value.
* If places is negative, HEX2OCT returns the #NUM! error value.
*
* @return string
* @return array|string
*/
public static function HEXTOOCT($x, $places = null)
{
Expand Down Expand Up @@ -480,7 +480,7 @@ public static function HEXTOOCT($x, $places = null)
* If places is negative, OCT2BIN returns the #NUM! error
* value.
*
* @return string
* @return array|string
*/
public static function OCTTOBIN($x, $places = null)
{
Expand All @@ -507,7 +507,7 @@ public static function OCTTOBIN($x, $places = null)
* If number is not a valid octal number, OCT2DEC returns the
* #NUM! error value.
*
* @return string
* @return array|string
*/
public static function OCTTODEC($x)
{
Expand Down Expand Up @@ -544,7 +544,7 @@ public static function OCTTODEC($x)
* If places is nonnumeric, OCT2HEX returns the #VALUE! error value.
* If places is negative, OCT2HEX returns the #NUM! error value.
*
* @return string
* @return array|string
*/
public static function OCTTOHEX($x, $places = null)
{
Expand Down Expand Up @@ -1123,7 +1123,7 @@ public static function IMPRODUCT(...$complexNumbers)
* @param float $a the first number
* @param float $b The second number. If omitted, b is assumed to be zero.
*
* @return int|string (string in the event of an error)
* @return array|int|string (string in the event of an error)
*/
public static function DELTA($a, $b = 0)
{
Expand All @@ -1147,7 +1147,7 @@ public static function DELTA($a, $b = 0)
* @param float $number the value to test against step
* @param float $step The threshold value. If you omit a value for step, GESTEP uses zero.
*
* @return int|string (string in the event of an error)
* @return array|int|string (string in the event of an error)
*/
public static function GESTEP($number, $step = 0)
{
Expand All @@ -1169,7 +1169,7 @@ public static function GESTEP($number, $step = 0)
* @param int $number1
* @param int $number2
*
* @return int|string
* @return array|int|string
*/
public static function BITAND($number1, $number2)
{
Expand All @@ -1191,7 +1191,7 @@ public static function BITAND($number1, $number2)
* @param int $number1
* @param int $number2
*
* @return int|string
* @return array|int|string
*/
public static function BITOR($number1, $number2)
{
Expand All @@ -1213,7 +1213,7 @@ public static function BITOR($number1, $number2)
* @param int $number1
* @param int $number2
*
* @return int|string
* @return array|int|string
*/
public static function BITXOR($number1, $number2)
{
Expand All @@ -1235,7 +1235,7 @@ public static function BITXOR($number1, $number2)
* @param int $number
* @param int $shiftAmount
*
* @return int|string
* @return array|float|int|string
*/
public static function BITLSHIFT($number, $shiftAmount)
{
Expand All @@ -1257,7 +1257,7 @@ public static function BITLSHIFT($number, $shiftAmount)
* @param int $number
* @param int $shiftAmount
*
* @return int|string
* @return array|float|int|string
*/
public static function BITRSHIFT($number, $shiftAmount)
{
Expand Down Expand Up @@ -1285,7 +1285,7 @@ public static function BITRSHIFT($number, $shiftAmount)
* @param float $upper upper bound for integrating ERF.
* If omitted, ERF integrates between zero and lower_limit
*
* @return float|string
* @return array|float|string
*/
public static function ERF($lower, $upper = null)
{
Expand All @@ -1306,7 +1306,7 @@ public static function ERF($lower, $upper = null)
*
* @param float $limit bound for integrating ERF
*
* @return float|string
* @return array|float|string
*/
public static function ERFPRECISE($limit)
{
Expand All @@ -1332,7 +1332,7 @@ public static function ERFPRECISE($limit)
*
* @param float $x The lower bound for integrating ERFC
*
* @return float|string
* @return array|float|string
*/
public static function ERFC($x)
{
Expand Down Expand Up @@ -1437,7 +1437,7 @@ public static function getBinaryConversionMultipliers()
* @param string $fromUOM the units for value
* @param string $toUOM the units for the result
*
* @return float|string
* @return array|float|string
*/
public static function CONVERTUOM($value, $fromUOM, $toUOM)
{
Expand Down
14 changes: 11 additions & 3 deletions src/PhpSpreadsheet/Calculation/Engineering/BesselI.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;

use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;

class BesselI
{
use ArrayEnabled;

/**
* BESSELI.
*
Expand All @@ -21,17 +24,22 @@ class BesselI
*
* @param mixed $x A float value at which to evaluate the function.
* If x is nonnumeric, BESSELI returns the #VALUE! error value.
* Or can be an array of values
* @param mixed $ord The integer order of the Bessel function.
* If ord is not an integer, it is truncated.
* If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
* If $ord < 0, BESSELI returns the #NUM! error value.
* Or can be an array of values
*
* @return float|string Result, or a string containing an error
* @return array|float|string Result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BESSELI($x, $ord)
{
$x = Functions::flattenSingleValue($x);
$ord = Functions::flattenSingleValue($ord);
if (is_array($x) || is_array($ord)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord);
}

try {
$x = EngineeringValidations::validateFloat($x);
Expand Down
14 changes: 11 additions & 3 deletions src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;

use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;

class BesselJ
{
use ArrayEnabled;

/**
* BESSELJ.
*
Expand All @@ -20,17 +23,22 @@ class BesselJ
*
* @param mixed $x A float value at which to evaluate the function.
* If x is nonnumeric, BESSELJ returns the #VALUE! error value.
* Or can be an array of values
* @param mixed $ord The integer order of the Bessel function.
* If ord is not an integer, it is truncated.
* If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
* If $ord < 0, BESSELJ returns the #NUM! error value.
* Or can be an array of values
*
* @return float|string Result, or a string containing an error
* @return array|float|string Result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BESSELJ($x, $ord)
{
$x = Functions::flattenSingleValue($x);
$ord = Functions::flattenSingleValue($ord);
if (is_array($x) || is_array($ord)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord);
}

try {
$x = EngineeringValidations::validateFloat($x);
Expand Down
14 changes: 11 additions & 3 deletions src/PhpSpreadsheet/Calculation/Engineering/BesselK.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;

use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;

class BesselK
{
use ArrayEnabled;

/**
* BESSELK.
*
Expand All @@ -18,17 +21,22 @@ class BesselK
*
* @param mixed $x A float value at which to evaluate the function.
* If x is nonnumeric, BESSELK returns the #VALUE! error value.
* Or can be an array of values
* @param mixed $ord The integer order of the Bessel function.
* If ord is not an integer, it is truncated.
* If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
* If $ord < 0, BESSELKI returns the #NUM! error value.
* Or can be an array of values
*
* @return float|string Result, or a string containing an error
* @return array|float|string Result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BESSELK($x, $ord)
{
$x = Functions::flattenSingleValue($x);
$ord = Functions::flattenSingleValue($ord);
if (is_array($x) || is_array($ord)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord);
}

try {
$x = EngineeringValidations::validateFloat($x);
Expand Down
Loading