Skip to content

Commit

Permalink
ClassDefinitionFixer - rename constructor arguments option
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed Dec 2, 2021
1 parent 0eab6c6 commit 329e364
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion doc/list.rst
Expand Up @@ -196,7 +196,7 @@ List of Available Rules
| Whether there should be a single space after the parenthesis of anonymous class (PSR12) or not.
| Allowed types: ``bool``
| Default value: ``false``
- | ``fix_constructor_arguments``
- | ``inline_constructor_arguments``
| Whether constructor argument list in anonymous classes should be single line.
| Allowed types: ``bool``
| Default value: ``true``
Expand Down
2 changes: 1 addition & 1 deletion doc/ruleSets/PSR12.rst
Expand Up @@ -14,7 +14,7 @@ Rules
``['allow_single_line_anonymous_class_with_empty_body' => true]``
- `class_definition <./../rules/class_notation/class_definition.rst>`_
config:
``['fix_constructor_arguments' => false, 'space_before_parenthesis' => true]``
``['inline_constructor_arguments' => false, 'space_before_parenthesis' => true]``
- `compact_nullable_typehint <./../rules/whitespace/compact_nullable_typehint.rst>`_
- `declare_equal_normalize <./../rules/language_construct/declare_equal_normalize.rst>`_
- `lowercase_cast <./../rules/cast_notation/lowercase_cast.rst>`_
Expand Down
8 changes: 4 additions & 4 deletions doc/rules/class_notation/class_definition.rst
Expand Up @@ -45,8 +45,8 @@ Allowed types: ``bool``

Default value: ``false``

``fix_constructor_arguments``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``inline_constructor_arguments``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Whether constructor argument list in anonymous classes should be single line.

Expand Down Expand Up @@ -154,7 +154,7 @@ With configuration: ``['space_before_parenthesis' => true]``.
Example #6
~~~~~~~~~~

With configuration: ``['fix_constructor_arguments' => true]``.
With configuration: ``['inline_constructor_arguments' => true]``.

.. code-block:: diff
Expand All @@ -175,7 +175,7 @@ The rule is part of the following rule sets:
@PSR12
Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``class_definition`` rule with the config below:

``['fix_constructor_arguments' => false, 'space_before_parenthesis' => true]``
``['inline_constructor_arguments' => false, 'space_before_parenthesis' => true]``

@PSR2
Using the `@PSR2 <./../../ruleSets/PSR2.rst>`_ rule set will enable the ``class_definition`` rule with the default config.
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/ClassNotation/ClassDefinitionFixer.php
Expand Up @@ -95,7 +95,7 @@ interface Bar extends
),
new CodeSample(
"<?php\n\$foo = new class(\n \$bar,\n \$baz\n) {};\n",
['fix_constructor_arguments' => true]
['inline_constructor_arguments' => true]
),
]
);
Expand Down Expand Up @@ -155,7 +155,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
->setAllowedTypes(['bool'])
->setDefault(false)
->getOption(),
(new FixerOptionBuilder('fix_constructor_arguments', 'Whether constructor argument list in anonymous classes should be single line.'))
(new FixerOptionBuilder('inline_constructor_arguments', 'Whether constructor argument list in anonymous classes should be single line.'))
->setAllowedTypes(['bool'])
->setDefault(true)
->getOption(),
Expand Down Expand Up @@ -335,7 +335,7 @@ private function getClassyInheritanceInfo(Tokens $tokens, int $startIndex, strin
private function makeClassyDefinitionSingleLine(Tokens $tokens, int $startIndex, int $endIndex): void
{
for ($i = $endIndex; $i >= $startIndex; --$i) {
if (!$this->configuration['fix_constructor_arguments'] && $tokens[$i]->equals(')')) {
if (!$this->configuration['inline_constructor_arguments'] && $tokens[$i]->equals(')')) {
$i = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $i);

continue;
Expand Down
2 changes: 1 addition & 1 deletion src/RuleSet/Sets/PSR12Set.php
Expand Up @@ -30,7 +30,7 @@ public function getRules(): array
'allow_single_line_anonymous_class_with_empty_body' => true,
],
'class_definition' => [
'fix_constructor_arguments' => false, // handled by method_argument_space fixer
'inline_constructor_arguments' => false, // handled by method_argument_space fixer
'space_before_parenthesis' => true, // defined in PSR12 ¶8. Anonymous Classes
],
'compact_nullable_typehint' => true,
Expand Down
16 changes: 8 additions & 8 deletions tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php
Expand Up @@ -34,7 +34,7 @@ public function testConfigureDefaultToFalse(): void
'single_item_single_line' => false,
'single_line' => false,
'space_before_parenthesis' => false,
'fix_constructor_arguments' => true,
'inline_constructor_arguments' => true,
];

$fixer = new ClassDefinitionFixer();
Expand Down Expand Up @@ -103,7 +103,7 @@ public function testInvalidConfigurationKey(): void
{
$this->expectException(InvalidFixerConfigurationException::class);
$this->expectExceptionMessageMatches(
'/^\[class_definition\] Invalid configuration: The option "a" does not exist\. Defined options are: "fix_constructor_arguments", "multi_line_extends_each_single_line", "single_item_single_line", "single_line", "space_before_parenthesis"\.$/'
'/^\[class_definition\] Invalid configuration: The option "a" does not exist\. Defined options are: "inline_constructor_arguments", "multi_line_extends_each_single_line", "single_item_single_line", "single_line", "space_before_parenthesis"\.$/'
);

$fixer = new ClassDefinitionFixer();
Expand Down Expand Up @@ -157,12 +157,12 @@ public function provideAnonymousClassesCases(): array
[
'<?php $a = new class( ) {};',
"<?php \$a = new\n class ( ){};",
['fix_constructor_arguments' => false],
['inline_constructor_arguments' => false],
],
[
'<?php $a = new class( $this->foo() , bar ( $a) ) {};',
"<?php \$a = new\n class ( \$this->foo() , bar ( \$a) ){};",
['fix_constructor_arguments' => false],
['inline_constructor_arguments' => false],
],
[
'<?php $a = new class(10, 1, /**/ 2) {};',
Expand All @@ -171,7 +171,7 @@ public function provideAnonymousClassesCases(): array
[
'<?php $a = new class( 10, 1,/**/2 ) {};',
'<?php $a = new class( 10, 1,/**/2 ){};',
['fix_constructor_arguments' => false],
['inline_constructor_arguments' => false],
],
[
'<?php $a = new class(2) {};',
Expand All @@ -184,7 +184,7 @@ public function provideAnonymousClassesCases(): array
[
'<?php $a = new class( $this->prop ) {};',
'<?php $a = new class( $this->prop ){};',
['fix_constructor_arguments' => false],
['inline_constructor_arguments' => false],
],
[
'<?php $a = new class($this->prop, $v[3], 4) {};',
Expand Down Expand Up @@ -295,10 +295,10 @@ class#
'<?php $z = new class () {};',
['space_before_parenthesis' => true],
],
'space_before_parenthesis and fix_constructor_arguments' => [
'space_before_parenthesis and inline_constructor_arguments' => [
'<?php $z = new class ( static::foo($this->bar()) ,baz() ) {};',
'<?php $z = new class ( static::foo($this->bar()) ,baz() ) {};',
['space_before_parenthesis' => true, 'fix_constructor_arguments' => false],
['space_before_parenthesis' => true, 'inline_constructor_arguments' => false],
],
];
}
Expand Down

0 comments on commit 329e364

Please sign in to comment.