Просмотр исходного кода

BlankLineBeforeStatementFixer - add "phpdoc"

Gerrit Addiks 5 лет назад
Родитель
Сommit
ef752ba608

+ 1 - 0
.gitattributes

@@ -17,4 +17,5 @@
 *.php   text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4 diff=php
 *.php   text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4 diff=php
 *.rst   text whitespace=blank-at-eol,blank-at-eof
 *.rst   text whitespace=blank-at-eol,blank-at-eof
 *.yml   text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
 *.yml   text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
+*.png   binary eol=unset
 /tests/Fixtures/**/* -text -filter
 /tests/Fixtures/**/* -text -filter

+ 1 - 1
doc/list.rst

@@ -106,7 +106,7 @@ List of Available Rules
 
 
    - | ``statements``
    - | ``statements``
      | List of statements which must be preceded by an empty line.
      | List of statements which must be preceded by an empty line.
-     | Allowed values: a subset of ``['break', 'case', 'continue', 'declare', 'default', 'do', 'exit', 'for', 'foreach', 'goto', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', 'yield_from']``
+     | Allowed values: a subset of ``['break', 'case', 'continue', 'declare', 'default', 'phpdoc', 'do', 'exit', 'for', 'foreach', 'goto', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', 'yield_from']``
      | Default value: ``['break', 'continue', 'declare', 'return', 'throw', 'try']``
      | Default value: ``['break', 'continue', 'declare', 'return', 'throw', 'try']``
 
 
 
 

+ 1 - 1
doc/rules/whitespace/blank_line_before_statement.rst

@@ -12,7 +12,7 @@ Configuration
 
 
 List of statements which must be preceded by an empty line.
 List of statements which must be preceded by an empty line.
 
 
-Allowed values: a subset of ``['break', 'case', 'continue', 'declare', 'default', 'do', 'exit', 'for', 'foreach', 'goto', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', 'yield_from']``
+Allowed values: a subset of ``['break', 'case', 'continue', 'declare', 'default', 'phpdoc', 'do', 'exit', 'for', 'foreach', 'goto', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', 'yield_from']``
 
 
 Default value: ``['break', 'continue', 'declare', 'return', 'throw', 'try']``
 Default value: ``['break', 'continue', 'declare', 'return', 'throw', 'try']``
 
 

+ 1 - 0
src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php

@@ -43,6 +43,7 @@ final class BlankLineBeforeStatementFixer extends AbstractFixer implements Confi
         'continue' => T_CONTINUE,
         'continue' => T_CONTINUE,
         'declare' => T_DECLARE,
         'declare' => T_DECLARE,
         'default' => T_DEFAULT,
         'default' => T_DEFAULT,
+        'phpdoc' => T_DOC_COMMENT,
         'do' => T_DO,
         'do' => T_DO,
         'exit' => T_EXIT,
         'exit' => T_EXIT,
         'for' => T_FOR,
         'for' => T_FOR,

+ 50 - 0
tests/Fixer/Whitespace/BlankLineBeforeStatementFixerTest.php

@@ -1491,6 +1491,56 @@ enum UserStatus: string {
         return "label";
         return "label";
     }
     }
 }
 }
+',
+        ];
+    }
+
+    /**
+     * @dataProvider provideFixWithDocCommentCases
+     */
+    public function testFixWithDocCommentCases(string $expected, string $input = null): void
+    {
+        $this->fixer->configure([
+            'statements' => ['phpdoc'],
+        ]);
+
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFixWithDocCommentCases(): iterable
+    {
+        yield [
+            '<?php
+/** @var int $foo */
+$foo = 123;
+
+/** @var float $bar */
+$bar = 45.6;
+
+/** @var string */
+$baz = "789";
+',
+            '<?php
+/** @var int $foo */
+$foo = 123;
+/** @var float $bar */
+$bar = 45.6;
+/** @var string */
+$baz = "789";
+',
+        ];
+
+        yield [
+            '<?php
+/* header */
+
+/**
+ * Class description
+ */
+class Foo {
+    /** test */
+    public function bar() {}
+}
 ',
 ',
         ];
         ];
     }
     }