Browse Source

Add T_NAMESPACE in array of forbidden successors

John Paul E. Balandan, CPA 3 years ago
parent
commit
e4dd5a61eb

+ 0 - 2
src/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixer.php

@@ -46,8 +46,6 @@ final class SingleBlankLineBeforeNamespaceFixer extends AbstractLinesBeforeNames
 
 
     /**
     /**
      * {@inheritdoc}
      * {@inheritdoc}
-     *
-     * Must run after NoBlankLinesAfterPhpdocFixer.
      */
      */
     public function getPriority()
     public function getPriority()
     {
     {

+ 8 - 7
src/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixer.php

@@ -57,7 +57,7 @@ class Bar {}
     /**
     /**
      * {@inheritdoc}
      * {@inheritdoc}
      *
      *
-     * Must run before HeaderCommentFixer, PhpdocAlignFixer, SingleBlankLineBeforeNamespaceFixer.
+     * Must run before HeaderCommentFixer, PhpdocAlignFixer.
      * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer.
      * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer.
      */
      */
     public function getPriority()
     public function getPriority()
@@ -71,16 +71,17 @@ class Bar {}
     protected function applyFix(\SplFileInfo $file, Tokens $tokens)
     protected function applyFix(\SplFileInfo $file, Tokens $tokens)
     {
     {
         static $forbiddenSuccessors = [
         static $forbiddenSuccessors = [
-            T_DOC_COMMENT,
+            T_BREAK,
             T_COMMENT,
             T_COMMENT,
-            T_WHITESPACE,
-            T_RETURN,
-            T_THROW,
-            T_GOTO,
             T_CONTINUE,
             T_CONTINUE,
-            T_BREAK,
             T_DECLARE,
             T_DECLARE,
+            T_DOC_COMMENT,
+            T_GOTO,
+            T_NAMESPACE,
+            T_RETURN,
+            T_THROW,
             T_USE,
             T_USE,
+            T_WHITESPACE,
         ];
         ];
 
 
         foreach ($tokens as $index => $token) {
         foreach ($tokens as $index => $token) {

+ 0 - 1
tests/AutoReview/FixerFactoryTest.php

@@ -141,7 +141,6 @@ final class FixerFactoryTest extends TestCase
             [$fixers['no_alternative_syntax'], $fixers['no_useless_else']],
             [$fixers['no_alternative_syntax'], $fixers['no_useless_else']],
             [$fixers['no_alternative_syntax'], $fixers['switch_continue_to_break']],
             [$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['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_extra_blank_lines']],
             [$fixers['no_empty_comment'], $fixers['no_trailing_whitespace']],
             [$fixers['no_empty_comment'], $fixers['no_trailing_whitespace']],
             [$fixers['no_empty_comment'], $fixers['no_whitespace_in_blank_line']],
             [$fixers['no_empty_comment'], $fixers['no_whitespace_in_blank_line']],

+ 16 - 0
tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php

@@ -287,6 +287,22 @@ EOF;
         $this->doTest($expected, $input);
         $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()
     public function testFixesWindowsStyle()
     {
     {
         $expected = "<?php\r\n    /**     * Constant!     */\n    \$foo = 123;";
         $expected = "<?php\r\n    /**     * Constant!     */\n    \$foo = 123;";

+ 0 - 0
tests/Fixtures/Integration/priority/no_blank_lines_after_phpdoc,single_blank_line_before_namespace.test → tests/Fixtures/Integration/misc/no_blank_lines_after_phpdoc,single_blank_line_before_namespace.test