Browse Source

bug #3987 Run HeaderCommentFixer after NoBlankLinesAfterPhpdocFixer (StanAngeloff)

This PR was merged into the 2.12 branch.

Discussion
----------

Run HeaderCommentFixer after NoBlankLinesAfterPhpdocFixer

This ensures the output is stable when `HeaderCommentFixer` is configured with `["separate" => "bottom", "commentType" => "PHPDoc"]` and the target file has no `namespace` or `declare()` construct.

Test case added, test suite passes.

Commits
-------

da3bdea4 Run HeaderCommentFixer after NoBlankLinesAfterPhpdocFixer
Dariusz Ruminski 6 years ago
parent
commit
727caca87e

+ 13 - 0
src/Fixer/Comment/HeaderCommentFixer.php

@@ -110,6 +110,19 @@ echo 1;
         return $tokens[0]->isGivenKind(T_OPEN_TAG) && $tokens->isMonolithicPhp();
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function getPriority()
+    {
+        // should be run after the NoBlankLinesAfterPhpdocFixer.
+        //
+        // When this fixer is configured with ["separate" => "bottom", "commentType" => "PHPDoc"]
+        // and the target file has no namespace or declare() construct,
+        // the fixed header comment gets trimmed by NoBlankLinesAfterPhpdocFixer if we run before it.
+        return -30;
+    }
+
     /**
      * {@inheritdoc}
      */

+ 1 - 0
tests/AutoReview/FixerFactoryTest.php

@@ -100,6 +100,7 @@ final class FixerFactoryTest extends TestCase
             [$fixers['method_separation'], $fixers['braces']],
             [$fixers['method_separation'], $fixers['indentation_type']],
             [$fixers['no_alias_functions'], $fixers['php_unit_dedicate_assert']],
+            [$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']],

+ 15 - 0
tests/Fixtures/Integration/priority/no_blank_lines_after_phpdoc,header_comment.test

@@ -0,0 +1,15 @@
+--TEST--
+Integration of fixers: no_blank_lines_after_phpdoc,header_comment.
+--RULESET--
+{"no_blank_lines_after_phpdoc": true, "header_comment": {"header": "Header", "commentType": "PHPDoc", "separate": "bottom"}}
+--EXPECT--
+<?php
+/**
+ * Header
+ */
+
+function F() {}
+
+--INPUT--
+<?php
+function F() {}