Skip to content

Commit

Permalink
Priority test for NoBreakComment and NoUselessElse
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum committed Aug 6, 2020
1 parent 43da94c commit 45e6a08
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Fixer/ControlStructure/NoBreakCommentFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public function isCandidate(Tokens $tokens)
return $tokens->isAnyTokenKindsFound([T_CASE, T_DEFAULT]);
}

/**
* {@inheritdoc}
*
* Must run after NoUselessElseFixer.
*/
public function getPriority()
{
return 0;
}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/ControlStructure/NoUselessElseFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getDefinition()
/**
* {@inheritdoc}
*
* Must run before BracesFixer, CombineConsecutiveUnsetsFixer, NoExtraBlankLinesFixer, NoTrailingWhitespaceFixer, NoUselessReturnFixer, NoWhitespaceInBlankLineFixer.
* Must run before BracesFixer, CombineConsecutiveUnsetsFixer, NoBreakCommentFixer, NoExtraBlankLinesFixer, NoTrailingWhitespaceFixer, NoUselessReturnFixer, NoWhitespaceInBlankLineFixer.
* Must run after NoAlternativeSyntaxFixer, NoEmptyStatementFixer, NoUnneededCurlyBracesFixer.
*/
public function getPriority()
Expand Down
1 change: 1 addition & 0 deletions tests/AutoReview/FixerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public function provideFixersPriorityCases()
[$fixers['no_unused_imports'], $fixers['single_line_after_imports']],
[$fixers['no_useless_else'], $fixers['braces']],
[$fixers['no_useless_else'], $fixers['combine_consecutive_unsets']],
[$fixers['no_useless_else'], $fixers['no_break_comment']],
[$fixers['no_useless_else'], $fixers['no_extra_blank_lines']],
[$fixers['no_useless_else'], $fixers['no_trailing_whitespace']],
[$fixers['no_useless_else'], $fixers['no_useless_return']],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
Integration of fixers: no_useless_else,no_break_comment.
--RULESET--
{"no_useless_else": true, "no_break_comment": true}
--EXPECT--
<?php
switch($foo) {
case 1:
if ($bar) {
return 'bar';
} // 1
return 'baz';
// 2
case 2:
echo 1;
}

--INPUT--
<?php
switch($foo) {
case 1:
if ($bar) {
return 'bar';
} else { // 1
return 'baz';
} // 2
case 2:
echo 1;
}

0 comments on commit 45e6a08

Please sign in to comment.