@@ -4160,8 +4160,10 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
41604160 }
41614161 }
41624162 } 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 ]) {
41654167 case '+ ' :
41664168 if ($ argumentCount < $ argMatch [1 ]) {
41674169 $ argumentCountError = true ;
@@ -4234,7 +4236,7 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
42344236 // do we now have a function/variable/number?
42354237 $ expectingOperator = true ;
42364238 $ expectingOperand = false ;
4237- $ val = $ match [1 ];
4239+ $ val = $ match [1 ] ?? '' ;
42384240 $ length = strlen ($ val );
42394241
42404242 if (preg_match ('/^ ' . self ::CALCULATION_REGEXP_FUNCTION . '$/miu ' , $ val , $ matches )) {
@@ -4290,7 +4292,7 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
42904292 $ rangeStartCellRef = $ output [count ($ output ) - 2 ]['value ' ] ?? '' ;
42914293 }
42924294 preg_match ('/^ ' . self ::CALCULATION_REGEXP_CELLREF . '$/miu ' , $ rangeStartCellRef , $ rangeStartMatches );
4293- if ($ rangeStartMatches [2 ] !== $ matches [2 ]) {
4295+ if (isset ( $ rangeStartMatches [ 2 ]) && $ rangeStartMatches [2 ] !== $ matches [2 ]) {
42944296 return $ this ->raiseFormulaError ('3D Range references are not yet supported ' );
42954297 }
42964298 }
@@ -4380,7 +4382,7 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
43804382 $ valx = $ val ;
43814383 $ endRowColRef = ($ refSheet !== null ) ? $ refSheet ->getHighestDataColumn ($ valx ) : AddressRange::MAX_COLUMN ; // Max 16,384 columns for Excel2007
43824384 $ val = "{$ rangeWS2 }{$ endRowColRef }{$ val }" ;
4383- } elseif (ctype_alpha ($ val ) && strlen ($ val ?? '' ) <= 3 ) {
4385+ } elseif (ctype_alpha ($ val ) && is_string ($ val) && strlen ( $ val ) <= 3 ) {
43844386 // Column range
43854387 $ stackItemType = 'Column Reference ' ;
43864388 $ 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
45454547 return $ operand ;
45464548 }
45474549
4550+ private static int $ matchIndex8 = 8 ;
4551+
4552+ private static int $ matchIndex9 = 9 ;
4553+
4554+ private static int $ matchIndex10 = 10 ;
4555+
45484556 /**
45494557 * @return array<int, mixed>|false
45504558 */
@@ -4908,12 +4916,17 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
49084916 } elseif (preg_match ('/^ ' . self ::CALCULATION_REGEXP_CELLREF . '$/i ' , $ token ?? '' , $ matches )) {
49094917 $ cellRef = null ;
49104918
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 ])) {
49124925 if ($ cell === null ) {
49134926 // We can't access the range, so return a REF error
49144927 $ cellValue = ExcelError::REF ();
49154928 } else {
4916- $ cellRef = $ matches [6 ] . $ matches [7 ] . ': ' . $ matches [9 ] . $ matches [10 ];
4929+ $ cellRef = $ matches [6 ] . $ matches [7 ] . ': ' . $ matches [self :: $ matchIndex9 ] . $ matches [self :: $ matchIndex10 ];
49174930 if ($ matches [2 ] > '' ) {
49184931 $ matches [2 ] = trim ($ matches [2 ], "\"' " );
49194932 if ((str_contains ($ matches [2 ], '[ ' )) || (str_contains ($ matches [2 ], '] ' ))) {
0 commit comments