Skip to content

Commit

Permalink
bug: NoMultipleStatementsPerLineFixer must run before CurlyBracesPosi…
Browse files Browse the repository at this point in the history
…tionFixer (#7087)
  • Loading branch information
kubawerlos authored Jun 24, 2023
1 parent 7c6803f commit 4bf8ab9
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions doc/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ List of Available Rules
The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.

*warning deprecated* Use ``single_space_around_construct``, ``control_structure_braces``,
``curly_braces_position``, ``control_structure_continuation_position``,
``declare_parentheses``, ``no_multiple_statements_per_line``,
``control_structure_continuation_position``, ``declare_parentheses``,
``no_multiple_statements_per_line``, ``curly_braces_position``,
``statement_indentation`` and ``no_extra_blank_lines`` instead.

Configuration options:
Expand Down
4 changes: 2 additions & 2 deletions doc/rules/basic/braces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ This rule is deprecated and will be removed on next major version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You should use ``single_space_around_construct``, ``control_structure_braces``,
``curly_braces_position``, ``control_structure_continuation_position``,
``declare_parentheses``, ``no_multiple_statements_per_line``,
``control_structure_continuation_position``, ``declare_parentheses``,
``no_multiple_statements_per_line``, ``curly_braces_position``,
``statement_indentation`` and ``no_extra_blank_lines`` instead.

Configuration
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/Basic/CurlyBracesPositionFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ public function isCandidate(Tokens $tokens): bool
* {@inheritdoc}
*
* Must run before SingleLineEmptyBodyFixer, StatementIndentationFixer.
* Must run after ControlStructureBracesFixer.
* Must run after ControlStructureBracesFixer, NoMultipleStatementsPerLineFixer.
*/
public function getPriority(): int
{
return parent::getPriority();
return -2;
}

protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
Expand Down
1 change: 1 addition & 0 deletions src/Fixer/Basic/NoMultipleStatementsPerLineFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getDefinition(): FixerDefinitionInterface
/**
* {@inheritdoc}
*
* Must run before CurlyBracesPositionFixer.
* Must run after ControlStructureBracesFixer, NoEmptyStatementFixer.
*/
public function getPriority(): int
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Basic/SingleLineEmptyBodyFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getDefinition(): FixerDefinitionInterface
*/
public function getPriority(): int
{
return -1;
return -3;
}

public function isCandidate(Tokens $tokens): bool
Expand Down
3 changes: 3 additions & 0 deletions tests/AutoReview/FixerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@ private static function getFixersPriorityGraph(): array
'binary_operator_spaces',
'method_argument_space',
],
'no_multiple_statements_per_line' => [
'curly_braces_position',
],
'no_php4_constructor' => [
'ordered_class_elements',
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Integration of fixers: no_multiple_statements_per_line,curly_braces_position.
--RULESET--
{"no_multiple_statements_per_line": true, "curly_braces_position": true}
--EXPECT--
<?php
f(function () {
static $x;
if (true) {
}
});

--INPUT--
<?php
f(function () { static $x; if (true) {} });

0 comments on commit 4bf8ab9

Please sign in to comment.