Skip to content

Commit

Permalink
Make @psr12 remove anonymous classes empty braces
Browse files Browse the repository at this point in the history
  • Loading branch information
julienfalque committed Aug 8, 2022
1 parent 198293b commit 663d064
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 52 deletions.
2 changes: 2 additions & 0 deletions doc/ruleSets/PSR12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Rules
- `lowercase_cast <./../rules/cast_notation/lowercase_cast.rst>`_
- `lowercase_static_reference <./../rules/casing/lowercase_static_reference.rst>`_
- `new_with_braces <./../rules/operator/new_with_braces.rst>`_
config:
``['anonymous_class' => false]``
- `no_blank_lines_after_class_opening <./../rules/class_notation/no_blank_lines_after_class_opening.rst>`_
- `no_leading_import_slash <./../rules/import/no_leading_import_slash.rst>`_
- `no_whitespace_in_blank_line <./../rules/whitespace/no_whitespace_in_blank_line.rst>`_
Expand Down
12 changes: 9 additions & 3 deletions doc/rules/operator/new_with_braces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ Rule sets
The rule is part of the following rule sets:

@PSR12
Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``new_with_braces`` rule with the default config.
Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``new_with_braces`` rule with the config below:

``['anonymous_class' => false]``

@PhpCsFixer
Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``new_with_braces`` rule with the default config.
Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``new_with_braces`` rule with the config below:

``['anonymous_class' => false]``

@Symfony
Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``new_with_braces`` rule with the default config.
Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``new_with_braces`` rule with the config below:

``['anonymous_class' => false]``
4 changes: 3 additions & 1 deletion src/RuleSet/Sets/PSR12Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function getRules(): array
'declare_equal_normalize' => true,
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'new_with_braces' => true,
'new_with_braces' => [
'anonymous_class' => false,
],
'no_blank_lines_after_class_opening' => true,
'no_leading_import_slash' => true,
'no_whitespace_in_blank_line' => true,
Expand Down
19 changes: 19 additions & 0 deletions tests/Fixtures/Integration/set/@PSR12.test-in.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?

declare(strict_types = 1 );

namespace Vendor\Package;
use const BAR;
use function foo;
Expand Down Expand Up @@ -39,4 +42,20 @@ class Aaa implements
$b = (boolean) 1;
$c = true ? (INT) '1' : 2;

function bar() : void
{
}

$class = new class () {};

class Baz
{
const FOO = 'foo';

public function bar(): ? int
{
return 0;
}
}

?>
18 changes: 18 additions & 0 deletions tests/Fixtures/Integration/set/@PSR12.test-out.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Vendor\Package;

use FooInterfaceA;
Expand Down Expand Up @@ -48,3 +50,19 @@ class Aaa implements
$a = new Foo();
$b = (bool) 1;
$c = true ? (int) '1' : 2;

function bar(): void
{
}

$class = new class {};

class Baz
{
public const FOO = 'foo';

public function bar(): ?int
{
return 0;
}
}
4 changes: 0 additions & 4 deletions tests/Fixtures/Integration/set/@PSR12_php70.test

This file was deleted.

9 changes: 0 additions & 9 deletions tests/Fixtures/Integration/set/@PSR12_php70.test-in.php

This file was deleted.

9 changes: 0 additions & 9 deletions tests/Fixtures/Integration/set/@PSR12_php70.test-out.php

This file was deleted.

4 changes: 0 additions & 4 deletions tests/Fixtures/Integration/set/@PSR12_php71.test

This file was deleted.

11 changes: 0 additions & 11 deletions tests/Fixtures/Integration/set/@PSR12_php71.test-in.php

This file was deleted.

11 changes: 0 additions & 11 deletions tests/Fixtures/Integration/set/@PSR12_php71.test-out.php

This file was deleted.

0 comments on commit 663d064

Please sign in to comment.