Skip to content

Commit

Permalink
bug #5567 Fix order of BracesFixer and ClassDefinitionFixer (Daeroni)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.18 branch.

Discussion
----------

Fix order of BracesFixer and ClassDefinitionFixer

If BracesFixer is configured with "position_after_functions_and_oop_constructs": "same", it would be overwritten by ClassDefinitionFixer putting the brace on the next line unless the ClassDefinitionFixer is run before BracesFixer.

It seems ClassDefinitionFixer was previously run implicitly before BracesFixer, but 701708e changed the priority of BracesFixer from negative to positive and the order of the two fixers were reversed.

Commits
-------

01d34da Fix order of BracesFixer and ClassDefinitionFixer
  • Loading branch information
keradus committed Mar 22, 2021
2 parents d617223 + 01d34da commit 61b9090
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/Basic/BracesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function bar($baz)
* {@inheritdoc}
*
* Must run before ArrayIndentationFixer, MethodArgumentSpaceFixer, MethodChainingIndentationFixer.
* Must run after ClassAttributesSeparationFixer, ElseifFixer, LineEndingFixer, MethodSeparationFixer, NoAlternativeSyntaxFixer, NoEmptyStatementFixer, NoUselessElseFixer, SingleSpaceAfterConstructFixer, SingleTraitInsertPerStatementFixer.
* Must run after ClassAttributesSeparationFixer, ClassDefinitionFixer, ElseifFixer, LineEndingFixer, MethodSeparationFixer, NoAlternativeSyntaxFixer, NoEmptyStatementFixer, NoUselessElseFixer, SingleSpaceAfterConstructFixer, SingleTraitInsertPerStatementFixer.
*/
public function getPriority()
{
Expand Down
10 changes: 10 additions & 0 deletions src/Fixer/ClassNotation/ClassDefinitionFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ interface Bar extends
);
}

/**
* {@inheritdoc}
*
* Must run before BracesFixer.
*/
public function getPriority()
{
return 36;
}

/**
* {@inheritdoc}
*/
Expand Down
1 change: 1 addition & 0 deletions tests/AutoReview/FixerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function provideFixersPriorityCases()
[$fixers['braces'], $fixers['method_chaining_indentation']],
[$fixers['class_attributes_separation'], $fixers['braces']],
[$fixers['class_attributes_separation'], $fixers['indentation_type']],
[$fixers['class_definition'], $fixers['braces']],
[$fixers['class_keyword_remove'], $fixers['no_unused_imports']],
[$fixers['combine_consecutive_issets'], $fixers['multiline_whitespace_before_semicolons']],
[$fixers['combine_consecutive_issets'], $fixers['no_singleline_whitespace_before_semicolons']],
Expand Down
15 changes: 15 additions & 0 deletions tests/Fixtures/Integration/priority/class_definition,braces.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Integration of fixers: class_definition,braces.
--RULESET--
{"class_definition": true, "braces": {"position_after_functions_and_oop_constructs": "same"}}
--EXPECT--
<?php

class Foo {
}

--INPUT--
<?php

class Foo{
}

0 comments on commit 61b9090

Please sign in to comment.