1
1
<?php
2
2
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
+
3
27
/* testPassByReference */
4
28
function passByReference (&$ var ) {}
5
29
@@ -32,6 +56,75 @@ function myFunction($a = 10 & 20) {}
32
56
/* testArrowFunction */
33
57
fn (int $ a , ...$ b ) => $ b ;
34
58
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
+ /* testVariadicFunctionClassType */
78
+ function variableLengthArgument ($ unit , DateInterval ...$ intervals ) {}
79
+
80
+ /* testNameSpacedTypeDeclaration */
81
+ function namespacedClassType ( \Package \Sub \ClassName $ a , ?Sub \AnotherClass $ b ) {}
82
+
83
+ /* testWithAllTypes */
84
+ class testAllTypes {
85
+ function allTypes (
86
+ ?ClassName $ a ,
87
+ self $ b ,
88
+ parent $ c ,
89
+ object $ d ,
90
+ ?int $ e ,
91
+ string &$ f ,
92
+ iterable $ g ,
93
+ bool $ h = true ,
94
+ callable $ i = 'is_null ' ,
95
+ float $ j = 1.1 ,
96
+ array ...$ k
97
+ ) {}
98
+ }
99
+
100
+ /* testArrowFunctionWithAllTypes */
101
+ $ fn = fn (
102
+ ?ClassName $ a ,
103
+ self $ b ,
104
+ parent $ c ,
105
+ object $ d ,
106
+ ?int $ e ,
107
+ string &$ f ,
108
+ iterable $ g ,
109
+ bool $ h = true ,
110
+ callable $ i = 'is_null ' ,
111
+ float $ j = 1.1 ,
112
+ array ...$ k
113
+ ) => $ something ;
114
+
115
+ /* testMessyDeclaration */
116
+ function messyDeclaration (
117
+ // comment
118
+ ?\MyNS /* comment */
119
+ \ SubCat // phpcs:ignore Standard.Cat.Sniff -- for reasons.
120
+ \ MyClass $ a ,
121
+ $ b /* test */ = /* test */ 'default ' /* test*/ ,
122
+ // phpcs:ignore Stnd.Cat.Sniff -- For reasons.
123
+ ? /*comment*/
124
+ bool // phpcs:disable Stnd.Cat.Sniff -- For reasons.
125
+ & /*test*/ ... /* phpcs:ignore */ $ c
126
+ ) {}
127
+
35
128
/* testPHP8MixedTypeHint */
36
129
function mixedTypeHint (mixed &...$ var1 ) {}
37
130
@@ -46,7 +139,7 @@ function namespaceOperatorTypeHint(?namespace\Name $var1) {}
46
139
function unionTypeSimple (int |float $ number , self |parent &...$ obj ) {}
47
140
48
141
/* testPHP8UnionTypesWithSpreadOperatorAndReference */
49
- function globalFunctionWithSpreadAndReference (float |null &$ paramA , string |int ...$ paramB ) {}
142
+ function globalFunctionWithSpreadAndReference (float |null &$ paramA , string |int ...$ paramB ) {}
50
143
51
144
/* testPHP8UnionTypesSimpleWithBitwiseOrInDefault */
52
145
$ fn = fn (int |float $ var = CONSTANT_A | CONSTANT_B ) => $ var ;
@@ -110,7 +203,13 @@ class ConstructorPropertyPromotionAndNormalParams {
110
203
111
204
class ConstructorPropertyPromotionWithReadOnly {
112
205
/* testPHP81ConstructorPropertyPromotionWithReadOnly */
113
- 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 ) {}
114
213
}
115
214
116
215
class ConstructorPropertyPromotionWithOnlyReadOnly {
@@ -174,3 +273,49 @@ function pseudoTypeTrue(?true $var = true) {}
174
273
/* testPHP82PseudoTypeFalseAndTrue */
175
274
// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method.
176
275
function 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