Skip to content

Commit

Permalink
feat: Add single_line_empty_body to @PhpCsFixer (#7266)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wirone committed Sep 4, 2023
1 parent effec1f commit fe9788b
Show file tree
Hide file tree
Showing 62 changed files with 82 additions and 206 deletions.
2 changes: 2 additions & 0 deletions doc/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3008,6 +3008,8 @@ List of Available Rules

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.

Part of rule set `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_

`Source PhpCsFixer\\Fixer\\Basic\\SingleLineEmptyBodyFixer <./../src/Fixer/Basic/SingleLineEmptyBodyFixer.php>`_
- `single_line_throw <./rules/function_notation/single_line_throw.rst>`_

Expand Down
1 change: 1 addition & 0 deletions doc/ruleSets/PhpCsFixer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Rules
- `return_assignment <./../rules/return_notation/return_assignment.rst>`_
- `self_static_accessor <./../rules/class_notation/self_static_accessor.rst>`_
- `single_line_comment_style <./../rules/comment/single_line_comment_style.rst>`_
- `single_line_empty_body <./../rules/basic/single_line_empty_body.rst>`_
- `whitespace_after_comma_in_array <./../rules/array_notation/whitespace_after_comma_in_array.rst>`_ with config:

``['ensure_single_space' => true]``
Expand Down
8 changes: 8 additions & 0 deletions doc/rules/basic/single_line_empty_body.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ Example #1
-{
-}
+) {}
Rule sets
---------

The rule is part of the following rule set:

- `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_

4 changes: 1 addition & 3 deletions src/Cache/NullCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ public function needFixing(string $file, string $fileContent): bool
return true;
}

public function setFile(string $file, string $fileContent): void
{
}
public function setFile(string $file, string $fileContent): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @internal
*/
final class InvalidForEnvFixerConfigurationException extends InvalidFixerConfigurationException
{
}
final class InvalidForEnvFixerConfigurationException extends InvalidFixerConfigurationException {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @internal
*/
final class RequiredFixerConfigurationException extends InvalidFixerConfigurationException
{
}
final class RequiredFixerConfigurationException extends InvalidFixerConfigurationException {}
8 changes: 2 additions & 6 deletions src/Console/Output/Progress/NullOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
*/
final class NullOutput implements ProgressOutputInterface
{
public function printLegend(): void
{
}
public function printLegend(): void {}

public function onFixerFileProcessed(FixerFileProcessedEvent $event): void
{
}
public function onFixerFileProcessed(FixerFileProcessedEvent $event): void {}
}
4 changes: 1 addition & 3 deletions src/Fixer/PhpUnit/PhpUnitTargetVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ final class PhpUnitTargetVersion
public const VERSION_8_4 = '8.4';
public const VERSION_NEWEST = 'newest';

private function __construct()
{
}
private function __construct() {}

public static function fulfills(string $candidate, string $target): bool
{
Expand Down
4 changes: 1 addition & 3 deletions src/FixerConfiguration/InvalidOptionsForEnvException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@
*
* @internal
*/
final class InvalidOptionsForEnvException extends InvalidOptionsException
{
}
final class InvalidOptionsForEnvException extends InvalidOptionsException {}
4 changes: 1 addition & 3 deletions src/Linter/LintingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@
*
* @TODO 4.0 make class "final"
*/
class LintingException extends \RuntimeException
{
}
class LintingException extends \RuntimeException {}
4 changes: 1 addition & 3 deletions src/Linter/UnavailableLinterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@
*
* @TODO 4.0 make class "final"
*/
class UnavailableLinterException extends \RuntimeException
{
}
class UnavailableLinterException extends \RuntimeException {}
4 changes: 1 addition & 3 deletions src/PregException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@
*
* @internal
*/
final class PregException extends \RuntimeException
{
}
final class PregException extends \RuntimeException {}
4 changes: 1 addition & 3 deletions src/RuleSet/AbstractRuleSetDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
*/
abstract class AbstractRuleSetDescription implements RuleSetDescriptionInterface
{
public function __construct()
{
}
public function __construct() {}

public function getName(): string
{
Expand Down
1 change: 1 addition & 0 deletions src/RuleSet/Sets/PhpCsFixerSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function getRules(): array
'return_assignment' => true,
'self_static_accessor' => true,
'single_line_comment_style' => true,
'single_line_empty_body' => true,
'single_line_throw' => false,
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
'yield_from_array_to_yields' => true,
Expand Down
8 changes: 2 additions & 6 deletions src/StdinFileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ public function openFile($openMode = 'r', $useIncludePath = false, $context = nu
throw new \BadMethodCallException(sprintf('Method "%s" is not implemented.', __METHOD__));
}

public function setFileClass($className = null): void
{
}
public function setFileClass($className = null): void {}

public function setInfoClass($className = null): void
{
}
public function setInfoClass($className = null): void {}
}
4 changes: 1 addition & 3 deletions src/Tokenizer/CT.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ final class CT
public const T_DYNAMIC_CLASS_CONSTANT_FETCH_CURLY_BRACE_OPEN = 10038;
public const T_DYNAMIC_CLASS_CONSTANT_FETCH_CURLY_BRACE_CLOSE = 10039;

private function __construct()
{
}
private function __construct() {}

/**
* Get name for custom token.
Expand Down
27 changes: 7 additions & 20 deletions tests/Fixtures/Integration/misc/PHP8_0.test
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,12 @@ $country = $session?->user?->getAddress()?->country;
class PostsController
{
#[Route('/api/posts/{id}', methods: ['GET'])]
public function get($id): void
{
}
public function get($id): void {}
}

$object = new #[ExampleAttribute] class() {
#[ExampleAttribute]
public function foo(#[ExampleAttribute] $bar): void
{
}
public function foo(#[ExampleAttribute] $bar): void {}
};

// https://wiki.php.net/rfc/union_types_v2
Expand All @@ -75,22 +71,16 @@ class Number
// https://wiki.php.net/rfc/static_return_type
class T
{
public function Foo(object $A): ?static
{
}
public function Foo(object $A): ?static {}

public function something(): static
{
}
public function something(): static {}
}

// https://wiki.php.net/rfc/variable_syntax_tweaks
// nothing we can do

// https://wiki.php.net/rfc/trailing_comma_in_parameter_list
function foo(string $param = null): void
{
}
function foo(string $param = null): void {}
call_user_func('foo', 1);

// https://wiki.php.net/rfc/trailing_comma_in_closure_use_list
Expand All @@ -101,9 +91,7 @@ $foo2 = static function () use ($bar, $baz): void { echo $bar.$baz; };
// https://wiki.php.net/rfc/mixed_type_v2
class T_Mixed
{
public function Foo(mixed $a): mixed
{
}
public function Foo(mixed $a): mixed {}
}

// https://wiki.php.net/rfc/throw_expression
Expand All @@ -130,8 +118,7 @@ class Point
protected float $y = 0.0,
private float $z = 0.0,
private ?string $desc = null,
) {
}
) {}
}

// https://wiki.php.net/rfc/match_expression_v2
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/Integration/misc/PHP8_1.test
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class TestNewWithInitialiers
{
public function __construct(
private Logger $logger = new NullLogger(),
) {
}
) {}
}

--INPUT--
Expand Down
14 changes: 4 additions & 10 deletions tests/Fixtures/Integration/misc/PHP8_2.test
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ enum A: string
}

#[Attr(A::B->name)]
class E
{
}
class E {}

// https://wiki.php.net/rfc/null-false-standalone-types
class FalseNull
Expand All @@ -38,8 +36,7 @@ class FalseNull
public function __construct(
private false $falsy = false,
private null $nully = null
) {
}
) {}

public function falsy(): false
{
Expand All @@ -58,9 +55,7 @@ class FalseNull
}
}

function falsyNull(null $n, false $f): null|false
{
}
function falsyNull(null $n, false $f): null|false {}

array_filter([], fn (null $n) => null === $n);
array_filter([], fn (false $n) => false === $n);
Expand All @@ -72,8 +67,7 @@ class TrueType

public function __construct(
private true $havingABud = true
) {
}
) {}

public function havingABud(): true
{
Expand Down
8 changes: 2 additions & 6 deletions tests/Fixtures/Integration/misc/issue_3879.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ Integration of fixers: align_multiline_comment and PHPDoc rules.
*
* @return int the number of runs needed to fix this is 2 :(
*/
function fixMe($str)
{
}
function fixMe($str) {}

--INPUT--
<?php
Expand All @@ -26,6 +24,4 @@ function fixMe($str)

* @return int The number of runs needed to fix this is 2 :( .
*/
function fixMe($str)
{
}
function fixMe($str) {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/DoctrineAnnotationSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\DoctrineAnnotationSet
*/
final class DoctrineAnnotationSetTest extends AbstractSetTestCase
{
}
final class DoctrineAnnotationSetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PERCS1x0RiskySetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PERCS1x0RiskySet
*/
final class PERCS1x0RiskySetTest extends AbstractSetTestCase
{
}
final class PERCS1x0RiskySetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PERCS1x0SetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PERCS1x0Set
*/
final class PERCS1x0SetTest extends AbstractSetTestCase
{
}
final class PERCS1x0SetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PERRiskySetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PERRiskySet
*/
final class PERRiskySetTest extends AbstractSetTestCase
{
}
final class PERRiskySetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PERSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PERSet
*/
final class PERSetTest extends AbstractSetTestCase
{
}
final class PERSetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PHP54MigrationSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PHP54MigrationSet
*/
final class PHP54MigrationSetTest extends AbstractSetTestCase
{
}
final class PHP54MigrationSetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PHP56MigrationRiskySetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PHP56MigrationRiskySet
*/
final class PHP56MigrationRiskySetTest extends AbstractSetTestCase
{
}
final class PHP56MigrationRiskySetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PHP70MigrationRiskySetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PHP70MigrationRiskySet
*/
final class PHP70MigrationRiskySetTest extends AbstractSetTestCase
{
}
final class PHP70MigrationRiskySetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PHP70MigrationSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PHP70MigrationSet
*/
final class PHP70MigrationSetTest extends AbstractSetTestCase
{
}
final class PHP70MigrationSetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PHP71MigrationRiskySetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PHP71MigrationRiskySet
*/
final class PHP71MigrationRiskySetTest extends AbstractSetTestCase
{
}
final class PHP71MigrationRiskySetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PHP71MigrationSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PHP71MigrationSet
*/
final class PHP71MigrationSetTest extends AbstractSetTestCase
{
}
final class PHP71MigrationSetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PHP73MigrationSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PHP73MigrationSet
*/
final class PHP73MigrationSetTest extends AbstractSetTestCase
{
}
final class PHP73MigrationSetTest extends AbstractSetTestCase {}
4 changes: 1 addition & 3 deletions tests/RuleSet/Sets/PHP74MigrationRiskySetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
*
* @covers \PhpCsFixer\RuleSet\Sets\PHP74MigrationRiskySet
*/
final class PHP74MigrationRiskySetTest extends AbstractSetTestCase
{
}
final class PHP74MigrationRiskySetTest extends AbstractSetTestCase {}
Loading

0 comments on commit fe9788b

Please sign in to comment.