Skip to content

Commit

Permalink
Feat: Remove space after fn declaration as defined in PER2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 23, 2024
1 parent 8933c53 commit ef93427
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef93427

Please sign in to comment.