@@ -1187,6 +1187,136 @@ public function testPHP82PseudoTypeFalseAndTrue()
1187
1187
}//end testPHP82PseudoTypeFalseAndTrue()
1188
1188
1189
1189
1190
+ /**
1191
+ * Verify recognition of PHP 8.2 DNF return type declaration.
1192
+ *
1193
+ * @return void
1194
+ */
1195
+ public function testPHP82DNFType ()
1196
+ {
1197
+ // Offsets are relative to the T_FUNCTION token.
1198
+ $ expected = [
1199
+ 'scope ' => 'public ' ,
1200
+ 'scope_specified ' => false ,
1201
+ 'return_type ' => 'bool|(Foo&Bar)|string ' ,
1202
+ 'return_type_token ' => 8 ,
1203
+ 'return_type_end_token ' => 16 ,
1204
+ 'nullable_return_type ' => false ,
1205
+ 'is_abstract ' => false ,
1206
+ 'is_final ' => false ,
1207
+ 'is_static ' => false ,
1208
+ 'has_body ' => true ,
1209
+ ];
1210
+
1211
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
1212
+
1213
+ }//end testPHP82DNFType()
1214
+
1215
+
1216
+ /**
1217
+ * Verify recognition of PHP 8.2 DNF return type declaration on an abstract method.
1218
+ *
1219
+ * @return void
1220
+ */
1221
+ public function testPHP82DNFTypeAbstractMethod ()
1222
+ {
1223
+ // Offsets are relative to the T_FUNCTION token.
1224
+ $ expected = [
1225
+ 'scope ' => 'protected ' ,
1226
+ 'scope_specified ' => true ,
1227
+ 'return_type ' => 'float|(Foo&Bar) ' ,
1228
+ 'return_type_token ' => 8 ,
1229
+ 'return_type_end_token ' => 14 ,
1230
+ 'nullable_return_type ' => false ,
1231
+ 'is_abstract ' => true ,
1232
+ 'is_final ' => false ,
1233
+ 'is_static ' => false ,
1234
+ 'has_body ' => false ,
1235
+ ];
1236
+
1237
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
1238
+
1239
+ }//end testPHP82DNFTypeAbstractMethod()
1240
+
1241
+
1242
+ /**
1243
+ * Verify recognition of PHP 8.2 DNF return type declaration with illegal nullability.
1244
+ *
1245
+ * @return void
1246
+ */
1247
+ public function testPHP82DNFTypeIllegalNullable ()
1248
+ {
1249
+ // Offsets are relative to the T_FUNCTION token.
1250
+ $ expected = [
1251
+ 'scope ' => 'public ' ,
1252
+ 'scope_specified ' => false ,
1253
+ 'return_type ' => '?(A&\Pck\B)|bool ' ,
1254
+ 'return_type_token ' => 8 ,
1255
+ 'return_type_end_token ' => 17 ,
1256
+ 'nullable_return_type ' => true ,
1257
+ 'is_abstract ' => false ,
1258
+ 'is_final ' => false ,
1259
+ 'is_static ' => false ,
1260
+ 'has_body ' => true ,
1261
+ ];
1262
+
1263
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
1264
+
1265
+ }//end testPHP82DNFTypeIllegalNullable()
1266
+
1267
+
1268
+ /**
1269
+ * Verify recognition of PHP 8.2 DNF return type declaration on a closure.
1270
+ *
1271
+ * @return void
1272
+ */
1273
+ public function testPHP82DNFTypeClosure ()
1274
+ {
1275
+ // Offsets are relative to the T_CLOSURE token.
1276
+ $ expected = [
1277
+ 'scope ' => 'public ' ,
1278
+ 'scope_specified ' => false ,
1279
+ 'return_type ' => 'object|(namespace\Foo&Countable) ' ,
1280
+ 'return_type_token ' => 6 ,
1281
+ 'return_type_end_token ' => 14 ,
1282
+ 'nullable_return_type ' => false ,
1283
+ 'is_abstract ' => false ,
1284
+ 'is_final ' => false ,
1285
+ 'is_static ' => false ,
1286
+ 'has_body ' => true ,
1287
+ ];
1288
+
1289
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
1290
+
1291
+ }//end testPHP82DNFTypeClosure()
1292
+
1293
+
1294
+ /**
1295
+ * Verify recognition of PHP 8.2 DNF return type declaration on an arrow function.
1296
+ *
1297
+ * @return void
1298
+ */
1299
+ public function testPHP82DNFTypeFn ()
1300
+ {
1301
+ // Offsets are relative to the T_FN token.
1302
+ $ expected = [
1303
+ 'scope ' => 'public ' ,
1304
+ 'scope_specified ' => false ,
1305
+ 'return_type ' => 'null|(Partially\Qualified&Traversable)|void ' ,
1306
+ 'return_type_token ' => 6 ,
1307
+ 'return_type_end_token ' => 16 ,
1308
+ 'nullable_return_type ' => false ,
1309
+ 'is_abstract ' => false ,
1310
+ 'is_final ' => false ,
1311
+ 'is_static ' => false ,
1312
+ 'has_body ' => true ,
1313
+ ];
1314
+
1315
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
1316
+
1317
+ }//end testPHP82DNFTypeFn()
1318
+
1319
+
1190
1320
/**
1191
1321
* Test for incorrect tokenization of array return type declarations in PHPCS < 2.8.0.
1192
1322
*
0 commit comments