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 @@ -366,6 +366,26 @@ public function provideClassSpecCases()
366366 'Foo \\Bar \\NamespacedClass.withmodifier(["and-arg" => true]) ' ,
367367 ['Foo \\Bar \\NamespacedClass.withmodifier ' , [["and-arg " => true ]]],
368368 ],
369+ 'Number ' => [
370+ 'Foo(1) ' ,
371+ ['Foo ' , [1 ]]
372+ ],
373+ 'Negative integer ' => [
374+ 'Foo(-1) ' ,
375+ ['Foo ' , [-1 ]]
376+ ],
377+ 'Negative integer in array ' => [
378+ 'Foo([-1]) ' ,
379+ ['Foo ' , [[-1 ]]]
380+ ],
381+ 'Multiple integers ' => [
382+ 'Foo(-1, 5, 4, -2) ' ,
383+ ['Foo ' , [-1 , 5 , 4 , -2 ]]
384+ ],
385+ 'Negative double ' => [
386+ 'Foo(-1.5) ' ,
387+ ['Foo ' , [-1.5 ]]
388+ ],
369389 ];
370390 }
371391}
You can’t perform that action at this time.
0 commit comments