11<?php
22
3+ /* testImportUse */
4+ use Vendor \Package \Sub as Alias ;
5+
6+ /* testImportGroupUse */
7+ use Vendor \Package \Sub \{
8+ ClassA ,
9+ ClassB as BAlias ,
10+ };
11+
12+ if ($ foo ) {}
13+
14+ /* testTraitUse */
15+ class TraitUse {
16+ use ImportedTrait;
17+
18+ function methodName () {}
19+ }
20+
21+ /* testNotAFunction */
22+ interface NotAFunction {};
23+
24+ /* testFunctionNoParams */
25+ function noParams () {}
26+
327/* testPassByReference */
428function passByReference (&$ var ) {}
529
@@ -32,6 +56,69 @@ function myFunction($a = 10 & 20) {}
3256/* testArrowFunction */
3357fn (int $ a , ...$ b ) => $ b ;
3458
59+ /* testArrowFunctionReturnByRef */
60+ fn &(?string $ a ) => $ b ;
61+
62+ /* testArrayDefaultValues */
63+ function arrayDefaultValues ($ var1 = [], $ var2 = array (1 , 2 , 3 ) ) {}
64+
65+ /* testConstantDefaultValueSecondParam */
66+ function constantDefaultValueSecondParam ($ var1 , $ var2 = M_PI ) {}
67+
68+ /* testScalarTernaryExpressionInDefault */
69+ function ternayInDefault ( $ a = FOO ? 'bar ' : 10 , ? bool $ b ) {}
70+
71+ /* testVariadicFunction */
72+ function variadicFunction ( int ... $ a ) {}
73+
74+ /* testVariadicByRefFunction */
75+ function variadicByRefFunction ( &...$ a ) {}
76+
77+ /* testWithAllTypes */
78+ class testAllTypes {
79+ function allTypes (
80+ ?ClassName $ a ,
81+ self $ b ,
82+ parent $ c ,
83+ object $ d ,
84+ ?int $ e ,
85+ string &$ f ,
86+ iterable $ g ,
87+ bool $ h = true ,
88+ callable $ i = 'is_null ' ,
89+ float $ j = 1.1 ,
90+ array ...$ k
91+ ) {}
92+ }
93+
94+ /* testArrowFunctionWithAllTypes */
95+ $ fn = fn (
96+ ?ClassName $ a ,
97+ self $ b ,
98+ parent $ c ,
99+ object $ d ,
100+ ?int $ e ,
101+ string &$ f ,
102+ iterable $ g ,
103+ bool $ h = true ,
104+ callable $ i = 'is_null ' ,
105+ float $ j = 1.1 ,
106+ array ...$ k
107+ ) => $ something ;
108+
109+ /* testMessyDeclaration */
110+ function messyDeclaration (
111+ // comment
112+ ?\MyNS /* comment */
113+ \ SubCat // phpcs:ignore Standard.Cat.Sniff -- for reasons.
114+ \ MyClass $ a ,
115+ $ b /* test */ = /* test */ 'default ' /* test*/ ,
116+ // phpcs:ignore Stnd.Cat.Sniff -- For reasons.
117+ ? /*comment*/
118+ bool // phpcs:disable Stnd.Cat.Sniff -- For reasons.
119+ & /*test*/ ... /* phpcs:ignore */ $ c
120+ ) {}
121+
35122/* testPHP8MixedTypeHint */
36123function mixedTypeHint (mixed &...$ var1 ) {}
37124
@@ -52,7 +139,7 @@ function namespacedClassType( \Package\Sub\ClassName $a, ?Sub\AnotherClass $b )
52139function unionTypeSimple (int |float $ number , self |parent &...$ obj ) {}
53140
54141/* testPHP8UnionTypesWithSpreadOperatorAndReference */
55- function globalFunctionWithSpreadAndReference (float |null &$ paramA , string |int ...$ paramB ) {}
142+ function globalFunctionWithSpreadAndReference (float |null &$ paramA , string |int ...$ paramB ) {}
56143
57144/* testPHP8UnionTypesSimpleWithBitwiseOrInDefault */
58145$ fn = fn (int |float $ var = CONSTANT_A | CONSTANT_B ) => $ var ;
@@ -116,7 +203,13 @@ class ConstructorPropertyPromotionAndNormalParams {
116203
117204class ConstructorPropertyPromotionWithReadOnly {
118205 /* testPHP81ConstructorPropertyPromotionWithReadOnly */
119- public function __construct (public readonly ?int $ promotedProp , readonly private string |bool &$ promotedToo ) {}
206+ public function __construct (public readonly ?int $ promotedProp , ReadOnly private string |bool &$ promotedToo ) {}
207+ }
208+
209+ class ConstructorPropertyPromotionWithReadOnlyNoTypeDeclaration {
210+ /* testPHP81ConstructorPropertyPromotionWithReadOnlyNoTypeDeclaration */
211+ // Intentional fatal error. Readonly properties MUST be typed.
212+ public function __construct (public readonly $ promotedProp , ReadOnly private &$ promotedToo ) {}
120213}
121214
122215class ConstructorPropertyPromotionWithOnlyReadOnly {
@@ -180,3 +273,49 @@ function pseudoTypeTrue(?true $var = true) {}
180273/* testPHP82PseudoTypeFalseAndTrue */
181274// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method.
182275function pseudoTypeFalseAndTrue (true |false $ var = true ) {}
276+
277+ /* testPHP81NewInInitializers */
278+ function newInInitializers (
279+ TypeA $ new = new TypeA (self ::CONST_VALUE ),
280+ \Package \TypeB $ newToo = new \Package \TypeB (10 , 'string ' ),
281+ ) {}
282+
283+ /* testFunctionCallFnPHPCS353-354 */
284+ $ value = $ obj ->fn (true );
285+
286+ /* testClosureNoParams */
287+ function () {};
288+
289+ /* testClosure */
290+ function ( $ a = 'test ' ) {};
291+
292+ /* testClosureUseNoParams */
293+ function () use () {};
294+
295+ /* testClosureUse */
296+ function () use ( $ foo , $ bar ) {};
297+
298+ /* testFunctionParamListWithTrailingComma */
299+ function trailingComma (
300+ ?string $ foo /*comment*/ ,
301+ $ bar = 0 ,
302+ ) {}
303+
304+ /* testClosureParamListWithTrailingComma */
305+ function (
306+ $ foo ,
307+ $ bar ,
308+ ) {};
309+
310+ /* testArrowFunctionParamListWithTrailingComma */
311+ $ fn = fn ( ?int $ a , ...$ b , ) => $ b ;
312+
313+ /* testClosureUseWithTrailingComma */
314+ function () use (
315+ $ foo /*comment*/ ,
316+ $ bar ,
317+ ) {};
318+
319+ /* testArrowFunctionLiveCoding */
320+ // Intentional parse error. This has to be the last test in the file.
321+ $ fn = fn
0 commit comments