Skip to content

Commit db548df

Browse files
committed
Squiz/MultiLineFunctionDeclaration: add tests for arrow function declarations
The Squiz sniff inherits the change from the `PEAR.Functions.FunctionDeclaration` sniff. This commit adds tests to document the behaviour and safeguard the inherited change.
1 parent eced441 commit db548df

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,24 @@ new ExceptionMessage(),
302302
) {
303303
}
304304
}
305+
306+
$arrowNoArgs = fn () => $retrievedfromscope;
307+
308+
$arrowSingleLineArgs = fn (Type $param1, int $param2, string $param3): \ReturnType => $retrievedfromscope;
309+
310+
$arrowMultiLineArgs = fn (
311+
$longVar1,
312+
$longerVar2,
313+
&...$muchLongerVar3
314+
) => $longVar1;
315+
316+
$arrowNoArgs = fn( )
317+
=> $retrievedfromscope;
318+
319+
$arrowSingleLineArgs = fn( Type $param1 , int $param2, string $param3
320+
) : \ReturnType => $retrievedfromscope;
321+
322+
$arrowMultiLineArgs = fn (
323+
$longVar1, $longerVar2,
324+
325+
& ... $muchLongerVar3) => $longVar1;

src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc.fixed

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,24 @@ new ExceptionMessage(),
314314
) {
315315
}
316316
}
317+
318+
$arrowNoArgs = fn () => $retrievedfromscope;
319+
320+
$arrowSingleLineArgs = fn (Type $param1, int $param2, string $param3): \ReturnType => $retrievedfromscope;
321+
322+
$arrowMultiLineArgs = fn (
323+
$longVar1,
324+
$longerVar2,
325+
&...$muchLongerVar3
326+
) => $longVar1;
327+
328+
$arrowNoArgs = fn ( )
329+
=> $retrievedfromscope;
330+
331+
$arrowSingleLineArgs = fn ( Type $param1 , int $param2, string $param3) : \ReturnType => $retrievedfromscope;
332+
333+
$arrowMultiLineArgs = fn (
334+
$longVar1,
335+
$longerVar2,
336+
& ... $muchLongerVar3
337+
) => $longVar1;

src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public function getErrorList($testFile='MultiLineFunctionDeclarationUnitTest.inc
7070
252 => 1,
7171
253 => 1,
7272
254 => 1,
73+
316 => 1,
74+
319 => 1,
75+
320 => 1,
76+
323 => 1,
77+
324 => 1,
78+
325 => 2,
7379
];
7480
} else {
7581
$errors = [

0 commit comments

Comments
 (0)