Skip to content

Commit

Permalink
Feat: Empty body of function should be abberviated {} as defined in…
Browse files Browse the repository at this point in the history
… PER2.0 (part of #94)
  • Loading branch information
OndraM committed May 6, 2024
1 parent 63c549e commit 652527e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use PhpCsFixer\Fixer\Basic\BracesFixer;
use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer;
use PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer;
use PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer;
use PhpCsFixer\Fixer\Casing\ClassReferenceNameCasingFixer;
use PhpCsFixer\Fixer\Casing\MagicMethodCasingFixer;
use PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer;
Expand Down Expand Up @@ -228,6 +229,8 @@
SetTypeToCastFixer::class,
// Array index should always be written by using square braces
NormalizeIndexBraceFixer::class,
// Empty body of class, interface, trait, enum or function must be abbreviated as {} and placed on the same line as the previous symbol, separated by a single space.
SingleLineEmptyBodyFixer::class, // Defined in PER 2.0
// Values separated by a comma on a single line should not have a trailing comma.
NoTrailingCommaInSinglelineFixer::class,
// Multi-line arrays, arguments list and parameters list must have a trailing comma
Expand Down
4 changes: 1 addition & 3 deletions src/Helper/SniffClassWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@

final class SniffClassWrapper
{
public function __construct(private File $file, private int $position, private Naming $naming)
{
}
public function __construct(private File $file, private int $position, private Naming $naming) {}

public function getClassName(): ?string
{
Expand Down
6 changes: 6 additions & 0 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ class Basic
{
return $first . $third;
}

public function emptyFunction1(): void {} // SingleLineEmptyBodyFixer

public function emptyFunction2(
$arg,
): void {} // SingleLineEmptyBodyFixer
}
8 changes: 8 additions & 0 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@ class Basic
{
return $first . $third;
}

public function emptyFunction1(): void {
} // SingleLineEmptyBodyFixer

public function emptyFunction2(
$arg
): void {
} // SingleLineEmptyBodyFixer
}
3 changes: 1 addition & 2 deletions tests/Integration/Fixtures/NewPhpFeatures.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ namespace Lmc\CodingStandard\Integration\Fixtures;
class NewPhpFeatures
{
public function __construct(private string $someString) // RequireConstructorPropertyPromotionSniff
{
}
{}

public function php80features(
string|bool $foo, // TypesSpacesFixer
Expand Down

0 comments on commit 652527e

Please sign in to comment.