From ef93427e2933dc901643db924db3c65185422e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Tue, 7 May 2024 00:39:20 +0200 Subject: [PATCH] Feat: Remove space after `fn` declaration as defined in PER2.0 --- ecs.php | 6 ++++++ tests/Integration/Fixtures/Basic.correct.php.inc | 10 +++++++++- tests/Integration/Fixtures/Basic.wrong.php.inc | 10 +++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ecs.php b/ecs.php index 067392b..ab97c09 100644 --- a/ecs.php +++ b/ecs.php @@ -68,6 +68,7 @@ use PhpCsFixer\Fixer\FunctionNotation\CombineNestedDirnameFixer; use PhpCsFixer\Fixer\FunctionNotation\FopenFlagOrderFixer; use PhpCsFixer\Fixer\FunctionNotation\FopenFlagsFixer; +use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer; use PhpCsFixer\Fixer\FunctionNotation\ImplodeCallFixer; use PhpCsFixer\Fixer\FunctionNotation\LambdaNotUsedImportFixer; use PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer; @@ -543,6 +544,11 @@ ], ], ) + // Spaces should be properly placed in a function declaration. + ->withConfiguredRule( + FunctionDeclarationFixer::class, + ['closure_fn_spacing' => 'none'], // Defined in PER 2.0 + ) ->withSkip([ // We allow empty catch statements (but they must have comment - see EmptyCatchCommentSniff) EmptyStatementSniff::class . '.DetectedCatch' => null, diff --git a/tests/Integration/Fixtures/Basic.correct.php.inc b/tests/Integration/Fixtures/Basic.correct.php.inc index 0d21c71..db6f21f 100644 --- a/tests/Integration/Fixtures/Basic.correct.php.inc +++ b/tests/Integration/Fixtures/Basic.correct.php.inc @@ -40,8 +40,16 @@ class Basic return false; // BlankLineBeforeStatementFixer } - public function fooBar(mixed $foo): mixed + public function fooBar(mixed $foo): mixed // FunctionDeclarationFixer { + $value = 5; + // FunctionDeclarationFixer + $function = function ($foo) use ($value) { + return $foo + $value; + }; + // FunctionDeclarationFixer + $fn = fn($foo) => $foo + $value; + // PhpdocToCommentFixer /* * Phpdoc used instead of plain comment diff --git a/tests/Integration/Fixtures/Basic.wrong.php.inc b/tests/Integration/Fixtures/Basic.wrong.php.inc index 24ba5fb..6d15347 100644 --- a/tests/Integration/Fixtures/Basic.wrong.php.inc +++ b/tests/Integration/Fixtures/Basic.wrong.php.inc @@ -33,8 +33,16 @@ class Basic public const MY_PUBLIC_CONST = 333; // OrderedClassElementsFixer - public function fooBar(mixed $foo): mixed + public function fooBar ( mixed $foo ): mixed // FunctionDeclarationFixer { + $value = 5; + // FunctionDeclarationFixer + $function = function($foo)use($value) { + return $foo + $value; + }; + // FunctionDeclarationFixer + $fn = fn ($foo) => $foo + $value; + // PhpdocToCommentFixer /** * Phpdoc used instead of plain comment