@@ -4180,8 +4180,10 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
41804180 }
41814181 }
41824182 } elseif ($ expectedArgumentCount != '* ' ) {
4183- preg_match ('/(\d*)([-+,])(\d*)/ ' , $ expectedArgumentCount , $ argMatch );
4184- switch ($ argMatch [2 ] ?? '' ) {
4183+ if (1 !== preg_match ('/(\d*)([-+,])(\d*)/ ' , $ expectedArgumentCount , $ argMatch )) {
4184+ $ argMatch = ['' , '' , '' , '' ];
4185+ }
4186+ switch ($ argMatch [2 ]) {
41854187 case '+ ' :
41864188 if ($ argumentCount < $ argMatch [1 ]) {
41874189 $ argumentCountError = true ;
@@ -4254,7 +4256,7 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
42544256 // do we now have a function/variable/number?
42554257 $ expectingOperator = true ;
42564258 $ expectingOperand = false ;
4257- $ val = $ match [1 ];
4259+ $ val = $ match [1 ] ?? '' ;
42584260 $ length = strlen ($ val );
42594261
42604262 if (preg_match ('/^ ' . self ::CALCULATION_REGEXP_FUNCTION . '$/miu ' , $ val , $ matches )) {
@@ -4310,7 +4312,7 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
43104312 $ rangeStartCellRef = $ output [count ($ output ) - 2 ]['value ' ] ?? '' ;
43114313 }
43124314 preg_match ('/^ ' . self ::CALCULATION_REGEXP_CELLREF . '$/miu ' , $ rangeStartCellRef , $ rangeStartMatches );
4313- if ($ rangeStartMatches [2 ] !== $ matches [2 ]) {
4315+ if (isset ( $ rangeStartMatches [ 2 ]) && $ rangeStartMatches [2 ] !== $ matches [2 ]) {
43144316 return $ this ->raiseFormulaError ('3D Range references are not yet supported ' );
43154317 }
43164318 }
@@ -4400,7 +4402,7 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
44004402 $ valx = $ val ;
44014403 $ endRowColRef = ($ refSheet !== null ) ? $ refSheet ->getHighestDataColumn ($ valx ) : AddressRange::MAX_COLUMN ; // Max 16,384 columns for Excel2007
44024404 $ val = "{$ rangeWS2 }{$ endRowColRef }{$ val }" ;
4403- } elseif (ctype_alpha ($ val ) && strlen ($ val ?? '' ) <= 3 ) {
4405+ } elseif (ctype_alpha ($ val ) && is_string ($ val) && strlen ( $ val ) <= 3 ) {
44044406 // Column range
44054407 $ stackItemType = 'Column Reference ' ;
44064408 $ endRowColRef = ($ refSheet !== null ) ? $ refSheet ->getHighestDataRow ($ val ) : AddressRange::MAX_ROW ; // Max 1,048,576 rows for Excel2007
@@ -4565,6 +4567,12 @@ private static function dataTestReference(array &$operandData): mixed
45654567 return $ operand ;
45664568 }
45674569
4570+ private static int $ matchIndex8 = 8 ;
4571+
4572+ private static int $ matchIndex9 = 9 ;
4573+
4574+ private static int $ matchIndex10 = 10 ;
4575+
45684576 /**
45694577 * @return array<int, mixed>|false
45704578 */
@@ -4928,12 +4936,17 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
49284936 } elseif (preg_match ('/^ ' . self ::CALCULATION_REGEXP_CELLREF . '$/i ' , $ token ?? '' , $ matches )) {
49294937 $ cellRef = null ;
49304938
4931- if (isset ($ matches [8 ])) {
4939+ /* Phpstan says matches[8/9/10] is never set,
4940+ and code coverage report seems to confirm.
4941+ Appease PhpStan for now;
4942+ probably delete this block later.
4943+ */
4944+ if (isset ($ matches [self ::$ matchIndex8 ])) {
49324945 if ($ cell === null ) {
49334946 // We can't access the range, so return a REF error
49344947 $ cellValue = ExcelError::REF ();
49354948 } else {
4936- $ cellRef = $ matches [6 ] . $ matches [7 ] . ': ' . $ matches [9 ] . $ matches [10 ];
4949+ $ cellRef = $ matches [6 ] . $ matches [7 ] . ': ' . $ matches [self :: $ matchIndex9 ] . $ matches [self :: $ matchIndex10 ];
49374950 if ($ matches [2 ] > '' ) {
49384951 $ matches [2 ] = trim ($ matches [2 ], "\"' " );
49394952 if ((str_contains ($ matches [2 ], '[ ' )) || (str_contains ($ matches [2 ], '] ' ))) {
0 commit comments