File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -423,6 +423,7 @@ public static function parse_class_spec($classSpec)
423423 $ bucketStack = [];
424424 $ lastTokenWasNSSeparator = false ;
425425 $ currentKey = null ;
426+ $ factor = 1 ;
426427
427428 foreach ($ tokens as $ token ) {
428429 // $forceResult used to allow null result to be detected
@@ -444,6 +445,8 @@ public static function parse_class_spec($classSpec)
444445 // Treat service name separator as NS separator
445446 $ class .= '. ' ;
446447 $ lastTokenWasNSSeparator = true ;
448+ } elseif ($ token === '- ' ) {
449+ $ factor = -1 ;
447450 } elseif ($ lastTokenWasNSSeparator && is_array ($ token ) && $ token [0 ] === T_STRING ) {
448451 // Found another section of a namespaced class
449452 $ class .= $ token [1 ];
@@ -471,11 +474,11 @@ public static function parse_class_spec($classSpec)
471474 break ;
472475
473476 case T_DNUMBER :
474- $ result = (double )$ token [1 ];
477+ $ result = (( double )$ token [1 ]) * $ factor ;
475478 break ;
476479
477480 case T_LNUMBER :
478- $ result = (int )$ token [1 ];
481+ $ result = (( int )$ token [1 ]) * $ factor ;
479482 break ;
480483
481484 case T_DOUBLE_ARROW :
@@ -550,6 +553,8 @@ public static function parse_class_spec($classSpec)
550553 // Set the active bucket to be our newly-pushed, empty array
551554 $ bucket = &$ bucket [$ key ];
552555 }
556+
557+ $ factor = 1 ;
553558 }
554559 }
555560
Original file line number Diff line number Diff line change @@ -352,6 +352,26 @@ public static function provideClassSpecCases()
352352 'Foo \\Bar \\NamespacedClass.withmodifier(["and-arg" => true]) ' ,
353353 ['Foo \\Bar \\NamespacedClass.withmodifier ' , [["and-arg " => true ]]],
354354 ],
355+ 'Number ' => [
356+ 'Foo(1) ' ,
357+ ['Foo ' , [1 ]]
358+ ],
359+ 'Negative integer ' => [
360+ 'Foo(-1) ' ,
361+ ['Foo ' , [-1 ]]
362+ ],
363+ 'Negative integer in array ' => [
364+ 'Foo([-1]) ' ,
365+ ['Foo ' , [[-1 ]]]
366+ ],
367+ 'Multiple integers ' => [
368+ 'Foo(-1, 5, 4, -2) ' ,
369+ ['Foo ' , [-1 , 5 , 4 , -2 ]]
370+ ],
371+ 'Negative double ' => [
372+ 'Foo(-1.5) ' ,
373+ ['Foo ' , [-1.5 ]]
374+ ],
355375 ];
356376 }
357377}
You can’t perform that action at this time.
0 commit comments