Skip to content

Commit 63c549e

Browse files
committed
Feat: Remove space after fn declaration as defined in PER2.0
1 parent f8d2e2d commit 63c549e

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Diff for: ecs.php

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
use PhpCsFixer\Fixer\FunctionNotation\CombineNestedDirnameFixer;
6969
use PhpCsFixer\Fixer\FunctionNotation\FopenFlagOrderFixer;
7070
use PhpCsFixer\Fixer\FunctionNotation\FopenFlagsFixer;
71+
use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer;
7172
use PhpCsFixer\Fixer\FunctionNotation\ImplodeCallFixer;
7273
use PhpCsFixer\Fixer\FunctionNotation\LambdaNotUsedImportFixer;
7374
use PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer;
@@ -541,6 +542,11 @@
541542
],
542543
],
543544
)
545+
// Spaces should be properly placed in a function declaration.
546+
->withConfiguredRule(
547+
FunctionDeclarationFixer::class,
548+
['closure_fn_spacing' => 'none'], // Defined in PER 2.0
549+
)
544550
->withSkip([
545551
// We allow empty catch statements (but they must have comment - see EmptyCatchCommentSniff)
546552
EmptyStatementSniff::class . '.DetectedCatch' => null,

Diff for: tests/Integration/Fixtures/Basic.correct.php.inc

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,16 @@ class Basic
3838
return false; // BlankLineBeforeStatementFixer
3939
}
4040

41-
public function fooBar(mixed $foo): mixed
41+
public function fooBar(mixed $foo): mixed // FunctionDeclarationFixer
4242
{
43+
$value = 5;
44+
// FunctionDeclarationFixer
45+
$function = function ($foo) use ($value) {
46+
return $foo + $value;
47+
};
48+
// FunctionDeclarationFixer
49+
$fn = fn($foo) => $foo + $value;
50+
4351
// PhpdocToCommentFixer
4452
/*
4553
* Phpdoc used instead of plain comment

Diff for: tests/Integration/Fixtures/Basic.wrong.php.inc

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ class Basic
3131

3232
public const MY_PUBLIC_CONST = 333; // OrderedClassElementsFixer
3333

34-
public function fooBar(mixed $foo): mixed
34+
public function fooBar ( mixed $foo ): mixed // FunctionDeclarationFixer
3535
{
36+
$value = 5;
37+
// FunctionDeclarationFixer
38+
$function = function($foo)use($value) {
39+
return $foo + $value;
40+
};
41+
// FunctionDeclarationFixer
42+
$fn = fn ($foo) => $foo + $value;
43+
3644
// PhpdocToCommentFixer
3745
/**
3846
* Phpdoc used instead of plain comment

0 commit comments

Comments
 (0)