Skip to content

Commit ef839f5

Browse files
author
Mark Baker
authored
Get started with array-enabling the Engineering functions - Erf, Bessel, bitwise, comparisons Unit of Measure and Number base conversions first (#2594)
1 parent cdbe5c7 commit ef839f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1118
-163
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,6 @@ parameters:
340340
count: 1
341341
path: src/PhpSpreadsheet/Calculation/Engine/Logger.php
342342

343-
-
344-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\:\\:BITLSHIFT\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
345-
count: 1
346-
path: src/PhpSpreadsheet/Calculation/Engineering.php
347-
348-
-
349-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\:\\:BITRSHIFT\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
350-
count: 1
351-
path: src/PhpSpreadsheet/Calculation/Engineering.php
352-
353343
-
354344
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselJ\\:\\:besselj2a\\(\\) has no return type specified\\.$#"
355345
count: 1

src/PhpSpreadsheet/Calculation/Engineering.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function parseComplex($complexNumber)
6161
* If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
6262
* If $ord < 0, BESSELI returns the #NUM! error value.
6363
*
64-
* @return float|string Result, or a string containing an error
64+
* @return array|float|string Result, or a string containing an error
6565
*/
6666
public static function BESSELI($x, $ord)
6767
{
@@ -86,7 +86,7 @@ public static function BESSELI($x, $ord)
8686
* If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
8787
* If $ord < 0, BESSELJ returns the #NUM! error value.
8888
*
89-
* @return float|string Result, or a string containing an error
89+
* @return array|float|string Result, or a string containing an error
9090
*/
9191
public static function BESSELJ($x, $ord)
9292
{
@@ -112,7 +112,7 @@ public static function BESSELJ($x, $ord)
112112
* If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
113113
* If $ord < 0, BESSELK returns the #NUM! error value.
114114
*
115-
* @return float|string Result, or a string containing an error
115+
* @return array|float|string Result, or a string containing an error
116116
*/
117117
public static function BESSELK($x, $ord)
118118
{
@@ -137,7 +137,7 @@ public static function BESSELK($x, $ord)
137137
* If $ord is nonnumeric, BESSELY returns the #VALUE! error value.
138138
* If $ord < 0, BESSELY returns the #NUM! error value.
139139
*
140-
* @return float|string Result, or a string containing an error
140+
* @return array|float|string Result, or a string containing an error
141141
*/
142142
public static function BESSELY($x, $ord)
143143
{
@@ -163,7 +163,7 @@ public static function BESSELY($x, $ord)
163163
* If number is not a valid binary number, or if number contains more than
164164
* 10 characters (10 bits), BIN2DEC returns the #NUM! error value.
165165
*
166-
* @return string
166+
* @return array|string
167167
*/
168168
public static function BINTODEC($x)
169169
{
@@ -195,7 +195,7 @@ public static function BINTODEC($x)
195195
* If places is nonnumeric, BIN2HEX returns the #VALUE! error value.
196196
* If places is negative, BIN2HEX returns the #NUM! error value.
197197
*
198-
* @return string
198+
* @return array|string
199199
*/
200200
public static function BINTOHEX($x, $places = null)
201201
{
@@ -227,7 +227,7 @@ public static function BINTOHEX($x, $places = null)
227227
* If places is nonnumeric, BIN2OCT returns the #VALUE! error value.
228228
* If places is negative, BIN2OCT returns the #NUM! error value.
229229
*
230-
* @return string
230+
* @return array|string
231231
*/
232232
public static function BINTOOCT($x, $places = null)
233233
{
@@ -263,7 +263,7 @@ public static function BINTOOCT($x, $places = null)
263263
* If places is nonnumeric, DEC2BIN returns the #VALUE! error value.
264264
* If places is zero or negative, DEC2BIN returns the #NUM! error value.
265265
*
266-
* @return string
266+
* @return array|string
267267
*/
268268
public static function DECTOBIN($x, $places = null)
269269
{
@@ -299,7 +299,7 @@ public static function DECTOBIN($x, $places = null)
299299
* If places is nonnumeric, DEC2HEX returns the #VALUE! error value.
300300
* If places is zero or negative, DEC2HEX returns the #NUM! error value.
301301
*
302-
* @return string
302+
* @return array|string
303303
*/
304304
public static function DECTOHEX($x, $places = null)
305305
{
@@ -335,7 +335,7 @@ public static function DECTOHEX($x, $places = null)
335335
* If places is nonnumeric, DEC2OCT returns the #VALUE! error value.
336336
* If places is zero or negative, DEC2OCT returns the #NUM! error value.
337337
*
338-
* @return string
338+
* @return array|string
339339
*/
340340
public static function DECTOOCT($x, $places = null)
341341
{
@@ -371,7 +371,7 @@ public static function DECTOOCT($x, $places = null)
371371
* If places is nonnumeric, HEX2BIN returns the #VALUE! error value.
372372
* If places is negative, HEX2BIN returns the #NUM! error value.
373373
*
374-
* @return string
374+
* @return array|string
375375
*/
376376
public static function HEXTOBIN($x, $places = null)
377377
{
@@ -398,7 +398,7 @@ public static function HEXTOBIN($x, $places = null)
398398
* If number is not a valid hexadecimal number, HEX2DEC returns the
399399
* #NUM! error value.
400400
*
401-
* @return string
401+
* @return array|string
402402
*/
403403
public static function HEXTODEC($x)
404404
{
@@ -438,7 +438,7 @@ public static function HEXTODEC($x)
438438
* value.
439439
* If places is negative, HEX2OCT returns the #NUM! error value.
440440
*
441-
* @return string
441+
* @return array|string
442442
*/
443443
public static function HEXTOOCT($x, $places = null)
444444
{
@@ -480,7 +480,7 @@ public static function HEXTOOCT($x, $places = null)
480480
* If places is negative, OCT2BIN returns the #NUM! error
481481
* value.
482482
*
483-
* @return string
483+
* @return array|string
484484
*/
485485
public static function OCTTOBIN($x, $places = null)
486486
{
@@ -507,7 +507,7 @@ public static function OCTTOBIN($x, $places = null)
507507
* If number is not a valid octal number, OCT2DEC returns the
508508
* #NUM! error value.
509509
*
510-
* @return string
510+
* @return array|string
511511
*/
512512
public static function OCTTODEC($x)
513513
{
@@ -544,7 +544,7 @@ public static function OCTTODEC($x)
544544
* If places is nonnumeric, OCT2HEX returns the #VALUE! error value.
545545
* If places is negative, OCT2HEX returns the #NUM! error value.
546546
*
547-
* @return string
547+
* @return array|string
548548
*/
549549
public static function OCTTOHEX($x, $places = null)
550550
{
@@ -1123,7 +1123,7 @@ public static function IMPRODUCT(...$complexNumbers)
11231123
* @param float $a the first number
11241124
* @param float $b The second number. If omitted, b is assumed to be zero.
11251125
*
1126-
* @return int|string (string in the event of an error)
1126+
* @return array|int|string (string in the event of an error)
11271127
*/
11281128
public static function DELTA($a, $b = 0)
11291129
{
@@ -1147,7 +1147,7 @@ public static function DELTA($a, $b = 0)
11471147
* @param float $number the value to test against step
11481148
* @param float $step The threshold value. If you omit a value for step, GESTEP uses zero.
11491149
*
1150-
* @return int|string (string in the event of an error)
1150+
* @return array|int|string (string in the event of an error)
11511151
*/
11521152
public static function GESTEP($number, $step = 0)
11531153
{
@@ -1169,7 +1169,7 @@ public static function GESTEP($number, $step = 0)
11691169
* @param int $number1
11701170
* @param int $number2
11711171
*
1172-
* @return int|string
1172+
* @return array|int|string
11731173
*/
11741174
public static function BITAND($number1, $number2)
11751175
{
@@ -1191,7 +1191,7 @@ public static function BITAND($number1, $number2)
11911191
* @param int $number1
11921192
* @param int $number2
11931193
*
1194-
* @return int|string
1194+
* @return array|int|string
11951195
*/
11961196
public static function BITOR($number1, $number2)
11971197
{
@@ -1213,7 +1213,7 @@ public static function BITOR($number1, $number2)
12131213
* @param int $number1
12141214
* @param int $number2
12151215
*
1216-
* @return int|string
1216+
* @return array|int|string
12171217
*/
12181218
public static function BITXOR($number1, $number2)
12191219
{
@@ -1235,7 +1235,7 @@ public static function BITXOR($number1, $number2)
12351235
* @param int $number
12361236
* @param int $shiftAmount
12371237
*
1238-
* @return int|string
1238+
* @return array|float|int|string
12391239
*/
12401240
public static function BITLSHIFT($number, $shiftAmount)
12411241
{
@@ -1257,7 +1257,7 @@ public static function BITLSHIFT($number, $shiftAmount)
12571257
* @param int $number
12581258
* @param int $shiftAmount
12591259
*
1260-
* @return int|string
1260+
* @return array|float|int|string
12611261
*/
12621262
public static function BITRSHIFT($number, $shiftAmount)
12631263
{
@@ -1285,7 +1285,7 @@ public static function BITRSHIFT($number, $shiftAmount)
12851285
* @param float $upper upper bound for integrating ERF.
12861286
* If omitted, ERF integrates between zero and lower_limit
12871287
*
1288-
* @return float|string
1288+
* @return array|float|string
12891289
*/
12901290
public static function ERF($lower, $upper = null)
12911291
{
@@ -1306,7 +1306,7 @@ public static function ERF($lower, $upper = null)
13061306
*
13071307
* @param float $limit bound for integrating ERF
13081308
*
1309-
* @return float|string
1309+
* @return array|float|string
13101310
*/
13111311
public static function ERFPRECISE($limit)
13121312
{
@@ -1332,7 +1332,7 @@ public static function ERFPRECISE($limit)
13321332
*
13331333
* @param float $x The lower bound for integrating ERFC
13341334
*
1335-
* @return float|string
1335+
* @return array|float|string
13361336
*/
13371337
public static function ERFC($x)
13381338
{
@@ -1437,7 +1437,7 @@ public static function getBinaryConversionMultipliers()
14371437
* @param string $fromUOM the units for value
14381438
* @param string $toUOM the units for the result
14391439
*
1440-
* @return float|string
1440+
* @return array|float|string
14411441
*/
14421442
public static function CONVERTUOM($value, $fromUOM, $toUOM)
14431443
{

src/PhpSpreadsheet/Calculation/Engineering/BesselI.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
44

5+
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
56
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
67
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
78

89
class BesselI
910
{
11+
use ArrayEnabled;
12+
1013
/**
1114
* BESSELI.
1215
*
@@ -21,17 +24,22 @@ class BesselI
2124
*
2225
* @param mixed $x A float value at which to evaluate the function.
2326
* If x is nonnumeric, BESSELI returns the #VALUE! error value.
27+
* Or can be an array of values
2428
* @param mixed $ord The integer order of the Bessel function.
2529
* If ord is not an integer, it is truncated.
2630
* If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
2731
* If $ord < 0, BESSELI returns the #NUM! error value.
32+
* Or can be an array of values
2833
*
29-
* @return float|string Result, or a string containing an error
34+
* @return array|float|string Result, or a string containing an error
35+
* If an array of numbers is passed as an argument, then the returned result will also be an array
36+
* with the same dimensions
3037
*/
3138
public static function BESSELI($x, $ord)
3239
{
33-
$x = Functions::flattenSingleValue($x);
34-
$ord = Functions::flattenSingleValue($ord);
40+
if (is_array($x) || is_array($ord)) {
41+
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord);
42+
}
3543

3644
try {
3745
$x = EngineeringValidations::validateFloat($x);

src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
44

5+
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
56
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
67
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
78

89
class BesselJ
910
{
11+
use ArrayEnabled;
12+
1013
/**
1114
* BESSELJ.
1215
*
@@ -20,17 +23,22 @@ class BesselJ
2023
*
2124
* @param mixed $x A float value at which to evaluate the function.
2225
* If x is nonnumeric, BESSELJ returns the #VALUE! error value.
26+
* Or can be an array of values
2327
* @param mixed $ord The integer order of the Bessel function.
2428
* If ord is not an integer, it is truncated.
2529
* If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
2630
* If $ord < 0, BESSELJ returns the #NUM! error value.
31+
* Or can be an array of values
2732
*
28-
* @return float|string Result, or a string containing an error
33+
* @return array|float|string Result, or a string containing an error
34+
* If an array of numbers is passed as an argument, then the returned result will also be an array
35+
* with the same dimensions
2936
*/
3037
public static function BESSELJ($x, $ord)
3138
{
32-
$x = Functions::flattenSingleValue($x);
33-
$ord = Functions::flattenSingleValue($ord);
39+
if (is_array($x) || is_array($ord)) {
40+
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord);
41+
}
3442

3543
try {
3644
$x = EngineeringValidations::validateFloat($x);

src/PhpSpreadsheet/Calculation/Engineering/BesselK.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
44

5+
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
56
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
67
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
78

89
class BesselK
910
{
11+
use ArrayEnabled;
12+
1013
/**
1114
* BESSELK.
1215
*
@@ -18,17 +21,22 @@ class BesselK
1821
*
1922
* @param mixed $x A float value at which to evaluate the function.
2023
* If x is nonnumeric, BESSELK returns the #VALUE! error value.
24+
* Or can be an array of values
2125
* @param mixed $ord The integer order of the Bessel function.
2226
* If ord is not an integer, it is truncated.
2327
* If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
2428
* If $ord < 0, BESSELKI returns the #NUM! error value.
29+
* Or can be an array of values
2530
*
26-
* @return float|string Result, or a string containing an error
31+
* @return array|float|string Result, or a string containing an error
32+
* If an array of numbers is passed as an argument, then the returned result will also be an array
33+
* with the same dimensions
2734
*/
2835
public static function BESSELK($x, $ord)
2936
{
30-
$x = Functions::flattenSingleValue($x);
31-
$ord = Functions::flattenSingleValue($ord);
37+
if (is_array($x) || is_array($ord)) {
38+
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord);
39+
}
3240

3341
try {
3442
$x = EngineeringValidations::validateFloat($x);

0 commit comments

Comments
 (0)