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">
31
31
-- Thanks to Juliette Reinders Folmer for the tests
32
32
- Fixed bug #3296 : PSR2.ControlStructures.SwitchDeclaration takes phpcs:ignore as content of case body
33
33
- 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
34
35
</notes>
35
36
<contents>
36
37
<dir name="/">
Original file line number Diff line number Diff line change @@ -2276,16 +2276,17 @@ protected function processAdditional()
2276
2276
if (isset ($ this ->tokens [$ x ]) === true && $ this ->tokens [$ x ]['code ' ] === T_OPEN_PARENTHESIS ) {
2277
2277
$ ignore = Util \Tokens::$ emptyTokens ;
2278
2278
$ ignore += [
2279
- T_STRING => T_STRING ,
2280
2279
T_ARRAY => T_ARRAY ,
2280
+ T_CALLABLE => T_CALLABLE ,
2281
2281
T_COLON => T_COLON ,
2282
2282
T_NAMESPACE => T_NAMESPACE ,
2283
2283
T_NS_SEPARATOR => T_NS_SEPARATOR ,
2284
+ T_NULL => T_NULL ,
2284
2285
T_NULLABLE => T_NULLABLE ,
2285
- T_CALLABLE => T_CALLABLE ,
2286
2286
T_PARENT => T_PARENT ,
2287
2287
T_SELF => T_SELF ,
2288
2288
T_STATIC => T_STATIC ,
2289
+ T_STRING => T_STRING ,
2289
2290
T_TYPE_UNION => T_TYPE_UNION ,
2290
2291
];
2291
2292
Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ $arrowWithUnionReturn = fn($param) : int|float => $param | 10;
93
93
/* testTernary */
94
94
$ fn = fn ($ a ) => $ a ? /* testTernaryThen */ fn () : string => 'a ' : /* testTernaryElse */ fn () : string => 'b ' ;
95
95
96
+ /* testTernaryWithTypes */
97
+ $ fn = fn (int |null $ a ) : array |null => $ a ? null : [];
98
+
96
99
function matchInArrow ($ x ) {
97
100
/* testWithMatchValue */
98
101
$ fn = fn ($ x ) => match (true ) {
Original file line number Diff line number Diff line change @@ -445,6 +445,24 @@ public function testTernary()
445
445
}//end testTernary()
446
446
447
447
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
+
448
466
/**
449
467
* Test arrow function returning a match control structure.
450
468
*
You can’t perform that action at this time.
0 commit comments