Skip to content

Commit

Permalink
Add T_NAMESPACE in array of forbidden successors
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Jul 30, 2021
1 parent d7c4564 commit e4dd5a6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public function isCandidate(Tokens $tokens)

/**
* {@inheritdoc}
*
* Must run after NoBlankLinesAfterPhpdocFixer.
*/
public function getPriority()
{
Expand Down
15 changes: 8 additions & 7 deletions src/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Bar {}
/**
* {@inheritdoc}
*
* Must run before HeaderCommentFixer, PhpdocAlignFixer, SingleBlankLineBeforeNamespaceFixer.
* Must run before HeaderCommentFixer, PhpdocAlignFixer.
* Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer.
*/
public function getPriority()
Expand All @@ -71,16 +71,17 @@ public function getPriority()
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
{
static $forbiddenSuccessors = [
T_DOC_COMMENT,
T_BREAK,
T_COMMENT,
T_WHITESPACE,
T_RETURN,
T_THROW,
T_GOTO,
T_CONTINUE,
T_BREAK,
T_DECLARE,
T_DOC_COMMENT,
T_GOTO,
T_NAMESPACE,
T_RETURN,
T_THROW,
T_USE,
T_WHITESPACE,
];

foreach ($tokens as $index => $token) {
Expand Down
1 change: 0 additions & 1 deletion tests/AutoReview/FixerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public function provideFixersPriorityCases()
[$fixers['no_alternative_syntax'], $fixers['no_useless_else']],
[$fixers['no_alternative_syntax'], $fixers['switch_continue_to_break']],
[$fixers['no_blank_lines_after_phpdoc'], $fixers['header_comment']],
[$fixers['no_blank_lines_after_phpdoc'], $fixers['single_blank_line_before_namespace']],
[$fixers['no_empty_comment'], $fixers['no_extra_blank_lines']],
[$fixers['no_empty_comment'], $fixers['no_trailing_whitespace']],
[$fixers['no_empty_comment'], $fixers['no_whitespace_in_blank_line']],
Expand Down
16 changes: 16 additions & 0 deletions tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ public function testFixesOthers()
$this->doTest($expected, $input);
}

public function testWhitespaceInDocBlockAboveNamespaceIsNotTouched()
{
$expected = <<<'EOF'
<?php
/**
* This is a file-level docblock.
*/
namespace Foo\Bar\Baz;
EOF;

$this->doTest($expected);
}

public function testFixesWindowsStyle()
{
$expected = "<?php\r\n /** * Constant! */\n \$foo = 123;";
Expand Down

0 comments on commit e4dd5a6

Please sign in to comment.