File tree Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3131 -- Thanks to Juliette Reinders Folmer for the tests
3232 - Fixed bug #3296 : PSR2.ControlStructures.SwitchDeclaration takes phpcs:ignore as content of case body
3333 - Fixed bug #3303 : findStartOfStatement() doesn't work with T_OPEN_TAG_WITH_ECHO
34+ - Fixed bug #3316 : Arrow function not tokenized correctly when using null in union type
3435 </notes>
3536 <contents>
3637 <dir name="/">
Original file line number Diff line number Diff line change @@ -2276,16 +2276,17 @@ protected function processAdditional()
22762276 if (isset ($ this ->tokens [$ x ]) === true && $ this ->tokens [$ x ]['code ' ] === T_OPEN_PARENTHESIS ) {
22772277 $ ignore = Util \Tokens::$ emptyTokens ;
22782278 $ ignore += [
2279- T_STRING => T_STRING ,
22802279 T_ARRAY => T_ARRAY ,
2280+ T_CALLABLE => T_CALLABLE ,
22812281 T_COLON => T_COLON ,
22822282 T_NAMESPACE => T_NAMESPACE ,
22832283 T_NS_SEPARATOR => T_NS_SEPARATOR ,
2284+ T_NULL => T_NULL ,
22842285 T_NULLABLE => T_NULLABLE ,
2285- T_CALLABLE => T_CALLABLE ,
22862286 T_PARENT => T_PARENT ,
22872287 T_SELF => T_SELF ,
22882288 T_STATIC => T_STATIC ,
2289+ T_STRING => T_STRING ,
22892290 T_TYPE_UNION => T_TYPE_UNION ,
22902291 ];
22912292
Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ $arrowWithUnionReturn = fn($param) : int|float => $param | 10;
9393/* testTernary */
9494$ fn = fn ($ a ) => $ a ? /* testTernaryThen */ fn () : string => 'a ' : /* testTernaryElse */ fn () : string => 'b ' ;
9595
96+ /* testTernaryWithTypes */
97+ $ fn = fn (int |null $ a ) : array |null => $ a ? null : [];
98+
9699function matchInArrow ($ x ) {
97100 /* testWithMatchValue */
98101 $ fn = fn ($ x ) => match (true ) {
Original file line number Diff line number Diff line change @@ -445,6 +445,24 @@ public function testTernary()
445445 }//end testTernary()
446446
447447
448+ /**
449+ * Test typed arrow functions used in ternary operators.
450+ *
451+ * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
452+ *
453+ * @return void
454+ */
455+ public function testTernaryWithTypes ()
456+ {
457+ $ tokens = self ::$ phpcsFile ->getTokens ();
458+
459+ $ token = $ this ->getTargetToken ('/* testTernaryWithTypes */ ' , T_FN );
460+ $ this ->backfillHelper ($ token );
461+ $ this ->scopePositionTestHelper ($ token , 15 , 27 );
462+
463+ }//end testTernaryWithTypes()
464+
465+
448466 /**
449467 * Test arrow function returning a match control structure.
450468 *
You can’t perform that action at this time.
0 commit comments