@@ -4160,8 +4160,10 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
4160
4160
}
4161
4161
}
4162
4162
} elseif ($ expectedArgumentCount != '* ' ) {
4163
- preg_match ('/(\d*)([-+,])(\d*)/ ' , $ expectedArgumentCount , $ argMatch );
4164
- switch ($ argMatch [2 ] ?? '' ) {
4163
+ if (1 !== preg_match ('/(\d*)([-+,])(\d*)/ ' , $ expectedArgumentCount , $ argMatch )) {
4164
+ $ argMatch = ['' , '' , '' , '' ];
4165
+ }
4166
+ switch ($ argMatch [2 ]) {
4165
4167
case '+ ' :
4166
4168
if ($ argumentCount < $ argMatch [1 ]) {
4167
4169
$ argumentCountError = true ;
@@ -4234,7 +4236,7 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
4234
4236
// do we now have a function/variable/number?
4235
4237
$ expectingOperator = true ;
4236
4238
$ expectingOperand = false ;
4237
- $ val = $ match [1 ];
4239
+ $ val = $ match [1 ] ?? '' ;
4238
4240
$ length = strlen ($ val );
4239
4241
4240
4242
if (preg_match ('/^ ' . self ::CALCULATION_REGEXP_FUNCTION . '$/miu ' , $ val , $ matches )) {
@@ -4290,7 +4292,7 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
4290
4292
$ rangeStartCellRef = $ output [count ($ output ) - 2 ]['value ' ] ?? '' ;
4291
4293
}
4292
4294
preg_match ('/^ ' . self ::CALCULATION_REGEXP_CELLREF . '$/miu ' , $ rangeStartCellRef , $ rangeStartMatches );
4293
- if ($ rangeStartMatches [2 ] !== $ matches [2 ]) {
4295
+ if (isset ( $ rangeStartMatches [ 2 ]) && $ rangeStartMatches [2 ] !== $ matches [2 ]) {
4294
4296
return $ this ->raiseFormulaError ('3D Range references are not yet supported ' );
4295
4297
}
4296
4298
}
@@ -4380,7 +4382,7 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
4380
4382
$ valx = $ val ;
4381
4383
$ endRowColRef = ($ refSheet !== null ) ? $ refSheet ->getHighestDataColumn ($ valx ) : AddressRange::MAX_COLUMN ; // Max 16,384 columns for Excel2007
4382
4384
$ val = "{$ rangeWS2 }{$ endRowColRef }{$ val }" ;
4383
- } elseif (ctype_alpha ($ val ) && strlen ($ val ?? '' ) <= 3 ) {
4385
+ } elseif (ctype_alpha ($ val ) && is_string ($ val) && strlen ( $ val ) <= 3 ) {
4384
4386
// Column range
4385
4387
$ stackItemType = 'Column Reference ' ;
4386
4388
$ endRowColRef = ($ refSheet !== null ) ? $ refSheet ->getHighestDataRow ($ val ) : AddressRange::MAX_ROW ; // Max 1,048,576 rows for Excel2007
@@ -4545,6 +4547,12 @@ private static function dataTestReference(array &$operandData): mixed
4545
4547
return $ operand ;
4546
4548
}
4547
4549
4550
+ private static int $ matchIndex8 = 8 ;
4551
+
4552
+ private static int $ matchIndex9 = 9 ;
4553
+
4554
+ private static int $ matchIndex10 = 10 ;
4555
+
4548
4556
/**
4549
4557
* @return array<int, mixed>|false
4550
4558
*/
@@ -4908,12 +4916,17 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
4908
4916
} elseif (preg_match ('/^ ' . self ::CALCULATION_REGEXP_CELLREF . '$/i ' , $ token ?? '' , $ matches )) {
4909
4917
$ cellRef = null ;
4910
4918
4911
- if (isset ($ matches [8 ])) {
4919
+ /* Phpstan says matches[8/9/10] is never set,
4920
+ and code coverage report seems to confirm.
4921
+ Appease PhpStan for now;
4922
+ probably delete this block later.
4923
+ */
4924
+ if (isset ($ matches [self ::$ matchIndex8 ])) {
4912
4925
if ($ cell === null ) {
4913
4926
// We can't access the range, so return a REF error
4914
4927
$ cellValue = ExcelError::REF ();
4915
4928
} else {
4916
- $ cellRef = $ matches [6 ] . $ matches [7 ] . ': ' . $ matches [9 ] . $ matches [10 ];
4929
+ $ cellRef = $ matches [6 ] . $ matches [7 ] . ': ' . $ matches [self :: $ matchIndex9 ] . $ matches [self :: $ matchIndex10 ];
4917
4930
if ($ matches [2 ] > '' ) {
4918
4931
$ matches [2 ] = trim ($ matches [2 ], "\"' " );
4919
4932
if ((str_contains ($ matches [2 ], '[ ' )) || (str_contains ($ matches [2 ], '] ' ))) {
0 commit comments