Browse Source

PhpdocNoUselessInheritdocFixer - support multiline docblock

Dariusz Ruminski 8 years ago
parent
commit
97a82c5bbd

+ 3 - 2
src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php

@@ -57,7 +57,8 @@ final class PhpdocNoUselessInheritdocFixer extends AbstractFixer
      */
      */
     public function getPriority()
     public function getPriority()
     {
     {
-        // should run before NoEmptyPhpdocFixer and PhpdocInlineTagFixer and after PhpdocToCommentFixer.
+        // Should run before NoEmptyPhpdocFixer, PhpdocInlineTagFixer and NoTrailingWhitespaceInCommentFixer
+        // and after PhpdocToCommentFixer.
         return 6;
         return 6;
     }
     }
 
 
@@ -138,7 +139,7 @@ final class PhpdocNoUselessInheritdocFixer extends AbstractFixer
     {
     {
         $count = 0;
         $count = 0;
         $content = preg_replace_callback(
         $content = preg_replace_callback(
-            '#([\s]*(?:@{*|{*[ \t]*@)[ \t]*inheritdoc[\s]*)([^}]*)((?:}*)[\s]*)#i',
+            '#(\h*(?:@{*|{*\h*@)\h*inheritdoc\h*)([^}]*)((?:}*)\h*)#i',
             function ($matches) {
             function ($matches) {
                 return ' '.$matches[2];
                 return ' '.$matches[2];
             },
             },

+ 26 - 0
tests/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixerTest.php

@@ -49,6 +49,19 @@ final class PhpdocNoUselessInheritdocFixerTest extends AbstractFixerTestCase
                 {
                 {
                     /** */
                     /** */
                     public function A(){}
                     public function A(){}
+
+                    /**
+                     * '.'
+                     */
+                    public function B(){}
+
+                    /**
+                     * Descr.
+                     *
+                     * @param int $c
+                     * '.'
+                     */
+                    public function C($c){}
                 }
                 }
                 ',
                 ',
                 '<?php
                 '<?php
@@ -56,6 +69,19 @@ final class PhpdocNoUselessInheritdocFixerTest extends AbstractFixerTestCase
                 {
                 {
                     /** @inheritdoc */
                     /** @inheritdoc */
                     public function A(){}
                     public function A(){}
+
+                    /**
+                     * @inheritdoc
+                     */
+                    public function B(){}
+
+                    /**
+                     * Descr.
+                     *
+                     * @param int $c
+                     * @inheritdoc
+                     */
+                    public function C($c){}
                 }
                 }
                 ',
                 ',
             ),
             ),

+ 1 - 0
tests/FixerFactoryTest.php

@@ -301,6 +301,7 @@ final class FixerFactoryTest extends \PHPUnit_Framework_TestCase
             array($fixers['phpdoc_add_missing_param_annotation'], $fixers['phpdoc_align']), // tested also in: phpdoc_add_missing_param_annotation,phpdoc_align.test
             array($fixers['phpdoc_add_missing_param_annotation'], $fixers['phpdoc_align']), // tested also in: phpdoc_add_missing_param_annotation,phpdoc_align.test
             array($fixers['phpdoc_no_alias_tag'], $fixers['phpdoc_add_missing_param_annotation']), // tested also in: phpdoc_no_alias_tag,phpdoc_add_missing_param_annotation.test
             array($fixers['phpdoc_no_alias_tag'], $fixers['phpdoc_add_missing_param_annotation']), // tested also in: phpdoc_no_alias_tag,phpdoc_add_missing_param_annotation.test
             array($fixers['phpdoc_no_useless_inheritdoc'], $fixers['no_empty_phpdoc']), // tested also in: phpdoc_no_useless_inheritdoc,no_empty_phpdoc.test
             array($fixers['phpdoc_no_useless_inheritdoc'], $fixers['no_empty_phpdoc']), // tested also in: phpdoc_no_useless_inheritdoc,no_empty_phpdoc.test
+            array($fixers['phpdoc_no_useless_inheritdoc'], $fixers['no_trailing_whitespace_in_comment']), // tested also in: phpdoc_no_useless_inheritdoc,no_trailing_whitespace_in_comment.test
             array($fixers['phpdoc_no_useless_inheritdoc'], $fixers['phpdoc_inline_tag']), // tested also in: phpdoc_no_useless_inheritdoc,phpdoc_inline_tag.test
             array($fixers['phpdoc_no_useless_inheritdoc'], $fixers['phpdoc_inline_tag']), // tested also in: phpdoc_no_useless_inheritdoc,phpdoc_inline_tag.test
             array($fixers['phpdoc_to_comment'], $fixers['phpdoc_no_useless_inheritdoc']), // tested also in: phpdoc_to_comment,phpdoc_no_useless_inheritdoc.test
             array($fixers['phpdoc_to_comment'], $fixers['phpdoc_no_useless_inheritdoc']), // tested also in: phpdoc_to_comment,phpdoc_no_useless_inheritdoc.test
         );
         );

+ 25 - 0
tests/Fixtures/Integration/priority/phpdoc_no_useless_inheritdoc,no_trailing_whitespace_in_comment.test

@@ -0,0 +1,25 @@
+--TEST--
+Integration of fixers: phpdoc_no_useless_inheritdoc,no_trailing_whitespace_in_comment.
+--RULESET--
+{"phpdoc_no_useless_inheritdoc": true, "no_trailing_whitespace_in_comment": true}
+--EXPECT--
+<?php
+
+class A
+{
+    /**
+     *
+     */
+    public function B(){}
+}
+
+--INPUT--
+<?php
+
+class A
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function B(){}
+}