Skip to content

Commit 8dddf56

Browse files
committed
Use proper syntax for variadic functions
This simplify code, increase readability and improve the function signature for API users.
1 parent 682b1b8 commit 8dddf56

File tree

218 files changed

+5199
-4549
lines changed

Some content is hidden

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

218 files changed

+5199
-4549
lines changed

src/PhpSpreadsheet/CalcEngine/Logger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ public function getEchoDebugLog()
112112
/**
113113
* Write an entry to the calculation engine debug log.
114114
*/
115-
public function writeDebugLog()
115+
public function writeDebugLog(...$args)
116116
{
117117
// Only write the debug log if logging is enabled
118118
if ($this->writeDebugLog) {
119-
$message = implode(func_get_args());
119+
$message = implode($args);
120120
$cellReference = implode(' -> ', $this->cellStack->showStack());
121121
if ($this->echoDebugLog) {
122122
echo $cellReference,

src/PhpSpreadsheet/Calculation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,9 +3051,9 @@ private function convertMatrixReferences($formula)
30513051
return $formula;
30523052
}
30533053

3054-
private static function mkMatrix()
3054+
private static function mkMatrix(...$args)
30553055
{
3056-
return func_get_args();
3056+
return $args;
30573057
}
30583058

30593059
// Binary Operators

src/PhpSpreadsheet/Calculation/DateTime.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -951,15 +951,13 @@ public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
951951
*
952952
* @return int Interval between the dates
953953
*/
954-
public static function NETWORKDAYS($startDate, $endDate)
954+
public static function NETWORKDAYS($startDate, $endDate, ...$dateArgs)
955955
{
956956
// Retrieve the mandatory start and end date that are referenced in the function definition
957957
$startDate = Functions::flattenSingleValue($startDate);
958958
$endDate = Functions::flattenSingleValue($endDate);
959-
// Flush the mandatory start and end date that are referenced in the function definition, and get the optional days
960-
$dateArgs = Functions::flattenArray(func_get_args());
961-
array_shift($dateArgs);
962-
array_shift($dateArgs);
959+
// Get the optional days
960+
$dateArgs = Functions::flattenArray($dateArgs);
963961

964962
// Validate the start and end dates
965963
if (is_string($startDate = $sDate = self::getDateValue($startDate))) {
@@ -1035,15 +1033,13 @@ public static function NETWORKDAYS($startDate, $endDate)
10351033
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
10361034
* depending on the value of the ReturnDateType flag
10371035
*/
1038-
public static function WORKDAY($startDate, $endDays)
1036+
public static function WORKDAY($startDate, $endDays, ...$dateArgs)
10391037
{
10401038
// Retrieve the mandatory start date and days that are referenced in the function definition
10411039
$startDate = Functions::flattenSingleValue($startDate);
10421040
$endDays = Functions::flattenSingleValue($endDays);
1043-
// Flush the mandatory start date and days that are referenced in the function definition, and get the optional days
1044-
$dateArgs = Functions::flattenArray(func_get_args());
1045-
array_shift($dateArgs);
1046-
array_shift($dateArgs);
1041+
// Get the optional days
1042+
$dateArgs = Functions::flattenArray($dateArgs);
10471043

10481044
if ((is_string($startDate = self::getDateValue($startDate))) || (!is_numeric($endDays))) {
10491045
return Functions::VALUE();

src/PhpSpreadsheet/Calculation/Engineering.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,18 +2291,18 @@ public static function IMSUB($complexNumber1, $complexNumber2)
22912291
* Excel Function:
22922292
* IMSUM(complexNumber[,complexNumber[,...]])
22932293
*
2294-
* @param string $complexNumber,... Series of complex numbers to add
2294+
* @param string $complexNumbers Series of complex numbers to add
22952295
*
22962296
* @return string
22972297
*/
2298-
public static function IMSUM()
2298+
public static function IMSUM(...$complexNumbers)
22992299
{
23002300
// Return value
23012301
$returnValue = self::parseComplex('0');
23022302
$activeSuffix = '';
23032303

23042304
// Loop through the arguments
2305-
$aArgs = Functions::flattenArray(func_get_args());
2305+
$aArgs = Functions::flattenArray($complexNumbers);
23062306
foreach ($aArgs as $arg) {
23072307
$parsedComplex = self::parseComplex($arg);
23082308

@@ -2331,18 +2331,18 @@ public static function IMSUM()
23312331
* Excel Function:
23322332
* IMPRODUCT(complexNumber[,complexNumber[,...]])
23332333
*
2334-
* @param string $complexNumber,... Series of complex numbers to multiply
2334+
* @param string $complexNumbers Series of complex numbers to multiply
23352335
*
23362336
* @return string
23372337
*/
2338-
public static function IMPRODUCT()
2338+
public static function IMPRODUCT(...$complexNumbers)
23392339
{
23402340
// Return value
23412341
$returnValue = self::parseComplex('1');
23422342
$activeSuffix = '';
23432343

23442344
// Loop through the arguments
2345-
$aArgs = Functions::flattenArray(func_get_args());
2345+
$aArgs = Functions::flattenArray($complexNumbers);
23462346
foreach ($aArgs as $arg) {
23472347
$parsedComplex = self::parseComplex($arg);
23482348

src/PhpSpreadsheet/Calculation/Financial.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,13 +1480,13 @@ public static function IRR($values, $guess = 0.1)
14801480
*
14811481
* PV is the loan amount or present value of the payments
14821482
*/
1483-
public static function ISPMT()
1483+
public static function ISPMT(...$args)
14841484
{
14851485
// Return value
14861486
$returnValue = 0;
14871487

14881488
// Get the parameters
1489-
$aArgs = Functions::flattenArray(func_get_args());
1489+
$aArgs = Functions::flattenArray($args);
14901490
$interestRate = array_shift($aArgs);
14911491
$period = array_shift($aArgs);
14921492
$numberPeriods = array_shift($aArgs);
@@ -1627,13 +1627,13 @@ public static function NPER($rate = 0, $pmt = 0, $pv = 0, $fv = 0, $type = 0)
16271627
*
16281628
* @return float
16291629
*/
1630-
public static function NPV()
1630+
public static function NPV(...$args)
16311631
{
16321632
// Return value
16331633
$returnValue = 0;
16341634

16351635
// Loop through arguments
1636-
$aArgs = Functions::flattenArray(func_get_args());
1636+
$aArgs = Functions::flattenArray($args);
16371637

16381638
// Calculate
16391639
$rate = array_shift($aArgs);

src/PhpSpreadsheet/Calculation/Logical.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ public static function false()
7878
*
7979
* @category Logical Functions
8080
*
81-
* @param mixed $arg,... Data values
81+
* @param mixed $args Data values
8282
*
8383
* @return string|bool the logical AND of the arguments
8484
*/
85-
public static function logicalAnd()
85+
public static function logicalAnd(...$args)
8686
{
8787
// Return value
8888
$returnValue = true;
8989

9090
// Loop through the arguments
91-
$aArgs = Functions::flattenArray(func_get_args());
91+
$aArgs = Functions::flattenArray($args);
9292
$argCount = -1;
9393
foreach ($aArgs as $argCount => $arg) {
9494
// Is it a boolean value?
@@ -135,17 +135,17 @@ public static function logicalAnd()
135135
*
136136
* @category Logical Functions
137137
*
138-
* @param mixed $arg,... Data values
138+
* @param mixed $args Data values
139139
*
140140
* @return string|bool the logical OR of the arguments
141141
*/
142-
public static function logicalOr()
142+
public static function logicalOr(...$args)
143143
{
144144
// Return value
145145
$returnValue = false;
146146

147147
// Loop through the arguments
148-
$aArgs = Functions::flattenArray(func_get_args());
148+
$aArgs = Functions::flattenArray($args);
149149
$argCount = -1;
150150
foreach ($aArgs as $argCount => $arg) {
151151
// Is it a boolean value?

src/PhpSpreadsheet/Calculation/LookupRef.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,6 @@ public static function ROWS($cellAddress = null)
270270
*/
271271
public static function HYPERLINK($linkURL = '', $displayName = null, \PhpOffice\PhpSpreadsheet\Cell $pCell = null)
272272
{
273-
$args = func_get_args();
274-
$pCell = array_pop($args);
275-
276273
$linkURL = (is_null($linkURL)) ? '' : Functions::flattenSingleValue($linkURL);
277274
$displayName = (is_null($displayName)) ? '' : Functions::flattenSingleValue($displayName);
278275

@@ -377,10 +374,11 @@ public static function INDIRECT($cellAddress = null, \PhpOffice\PhpSpreadsheet\C
377374
* @param mixed $columns
378375
* @param null|mixed $height
379376
* @param null|mixed $width
377+
* @param \PhpOffice\PhpSpreadsheet\Cell $pCell
380378
*
381379
* @return string A reference to a cell or range of cells
382380
*/
383-
public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null)
381+
public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null, \PhpOffice\PhpSpreadsheet\Cell $pCell = null)
384382
{
385383
$rows = Functions::flattenSingleValue($rows);
386384
$columns = Functions::flattenSingleValue($columns);
@@ -390,8 +388,6 @@ public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $hei
390388
return 0;
391389
}
392390

393-
$args = func_get_args();
394-
$pCell = array_pop($args);
395391
if (!is_object($pCell)) {
396392
return Functions::REF();
397393
}
@@ -468,9 +464,8 @@ public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $hei
468464
*
469465
* @return mixed The selected value
470466
*/
471-
public static function CHOOSE()
467+
public static function CHOOSE(...$chooseArgs)
472468
{
473-
$chooseArgs = func_get_args();
474469
$chosenEntry = Functions::flattenArray(array_shift($chooseArgs));
475470
$entryCount = count($chooseArgs) - 1;
476471

0 commit comments

Comments
 (0)